Plugin: XAPI: Add statement when portfolio items/comments are edited - refs BT#18201

pull/4501/head
Angel Fernando Quiroz Campos 3 years ago
parent b10d0904b2
commit f4454b0494
  1. 10
      main/inc/lib/PortfolioController.php
  2. 19
      main/inc/lib/hook/HookPortfolioCommentEdited.php
  3. 19
      main/inc/lib/hook/HookPortfolioItemEdited.php
  4. 8
      main/inc/lib/hook/interfaces/HookPortfolioCommentEditedEventInterface.php
  5. 8
      main/inc/lib/hook/interfaces/HookPortfolioCommentEditedObserverInterface.php
  6. 8
      main/inc/lib/hook/interfaces/HookPortfolioItemEditedEventInterface.php
  7. 8
      main/inc/lib/hook/interfaces/HookPortfolioItemEditedObserverInterface.php
  8. 19
      plugin/xapi/src/Hook/XApiPortfolioCommentEditedHookObserver.php
  9. 19
      plugin/xapi/src/Hook/XApiPortfolioItemEditedHookObserver.php
  10. 39
      plugin/xapi/src/ToolExperience/Statement/PortfolioCommentEdited.php
  11. 39
      plugin/xapi/src/ToolExperience/Statement/PortfolioItemEdited.php
  12. 16
      plugin/xapi/src/ToolExperience/Verb/Edited.php
  13. 12
      plugin/xapi/src/XApiPlugin.php

@ -830,6 +830,11 @@ class PortfolioController
$this->em->persist($item);
$this->em->flush();
HookPortfolioItemEdited::create()
->setEventData(['item' => $item])
->notifyItemEdited()
;
$this->processAttachments(
$form,
$item->getUser(),
@ -2949,6 +2954,11 @@ class PortfolioController
PortfolioAttachment::TYPE_COMMENT
);
HookPortfolioCommentEdited::create()
->setEventData(['comment' => $comment])
->notifyCommentEdited()
;
Display::addFlash(
Display::return_message(get_lang('ItemUpdated'), 'success')
);

@ -0,0 +1,19 @@
<?php
/* For licensing terms, see /license.txt */
class HookPortfolioCommentEdited extends HookEvent implements HookPortfolioCommentEditedEventInterface
{
protected function __construct()
{
parent::__construct('HookPortfolioCommentEdited');
}
public function notifyCommentEdited()
{
/** @var HookPortfolioCommentEditedObserverInterface $observer */
foreach ($this->observers as $observer) {
$observer->hookCommentEdited($this);
}
}
}

@ -0,0 +1,19 @@
<?php
/* For licensing terms, see /license.txt */
class HookPortfolioItemEdited extends HookEvent implements HookPortfolioItemEditedEventInterface
{
protected function __construct()
{
parent::__construct('HookPortfolioItemEdited');
}
public function notifyItemEdited()
{
/** @var HookPortfolioItemEditedObserverInterface $observer */
foreach ($this->observers as $observer) {
$observer->hookItemEdited($this);
}
}
}

@ -0,0 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
interface HookPortfolioCommentEditedEventInterface extends HookEventInterface
{
public function notifyCommentEdited();
}

@ -0,0 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
interface HookPortfolioCommentEditedObserverInterface extends HookObserverInterface
{
public function hookCommentEdited(HookPortfolioCommentEditedEventInterface $hookEvent);
}

@ -0,0 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
interface HookPortfolioItemEditedEventInterface extends HookEventInterface
{
public function notifyItemEdited();
}

@ -0,0 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
interface HookPortfolioItemEditedObserverInterface extends HookObserverInterface
{
public function hookItemEdited(HookPortfolioItemEditedEventInterface $hookEvent);
}

@ -0,0 +1,19 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\PortfolioComment;
use Chamilo\PluginBundle\XApi\ToolExperience\Statement\PortfolioCommentEdited;
class XApiPortfolioCommentEditedHookObserver extends XApiActivityHookObserver implements HookPortfolioCommentEditedObserverInterface
{
public function hookCommentEdited(HookPortfolioCommentEditedEventInterface $hookEvent)
{
/** @var PortfolioComment $comment */
$comment = $hookEvent->getEventData()['comment'];
$statement = (new PortfolioCommentEdited($comment))->generate();
$this->saveSharedStatement($statement);
}
}

@ -0,0 +1,19 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Portfolio;
use Chamilo\PluginBundle\XApi\ToolExperience\Statement\PortfolioItemEdited;
class XApiPortfolioItemEditedHookObserver extends XApiActivityHookObserver implements HookPortfolioItemEditedObserverInterface
{
public function hookItemEdited(HookPortfolioItemEditedEventInterface $hookEvent)
{
/** @var Portfolio $item */
$item = $hookEvent->getEventData()['item'];
$statement = (new PortfolioItemEdited($item))->generate();
$this->saveSharedStatement($statement);
}
}

@ -0,0 +1,39 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement;
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioComment as PortfolioCommentActivity;
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User;
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Edited;
use Xabbuh\XApi\Model\Statement;
class PortfolioCommentEdited extends PortfolioComment
{
use PortfolioAttachmentsTrait;
public function generate(): Statement
{
$user = api_get_user_entity(api_get_user_id());
$actor = new User($user);
$verb = new Edited();
$object = new PortfolioCommentActivity($this->comment);
$context = $this->generateContext();
$attachements = $this->generateAttachmentsForComment($this->comment);
return new Statement(
$this->generateStatementId('portfolio-comment'),
$actor->generate(),
$verb->generate(),
$object->generate(),
null,
null,
api_get_utc_datetime(null, false, true),
null,
$context,
$attachements
);
}
}

@ -0,0 +1,39 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement;
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioItem as PortfolioItemActivity;
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User;
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Edited;
use Xabbuh\XApi\Model\Statement;
class PortfolioItemEdited extends PortfolioItem
{
use PortfolioAttachmentsTrait;
public function generate(): Statement
{
$user = api_get_user_entity(api_get_user_id());
$actor = new User($user);
$verb = new Edited();
$object = new PortfolioItemActivity($this->item);
$context = $this->generateContext();
$attachements = $this->generateAttachmentsForItem($this->item);
return new Statement(
$this->generateStatementId('portfolio-item'),
$actor->generate(),
$verb->generate(),
$object->generate(),
null,
null,
api_get_utc_datetime(null, false, true),
null,
$context,
$attachements
);
}
}

@ -0,0 +1,16 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb;
class Edited extends BaseVerb
{
public function __construct()
{
parent::__construct(
'http://curatr3.com/define/verb/edited',
'Edited'
);
}
}

@ -152,6 +152,8 @@ class XApiPlugin extends Plugin implements HookPluginInterface
$portfolioDownloaded = XApiPortfolioDownloadedHookObserver::create();
$portfolioItemScoredHook = XApiPortfolioItemScoredHookObserver::create();
$portfolioCommentedScoredHook = XApiPortfolioCommentScoredHookObserver::create();
$portfolioItemEditedHook = XApiPortfolioItemEditedHookObserver::create();
$portfolioCommentEditedHook = XApiPortfolioCommentEditedHookObserver::create();
HookLearningPathItemViewed::create()->detach($learningPathItemViewedHook);
HookLearningPathEnd::create()->detach($learningPathEndHook);
@ -164,6 +166,8 @@ class XApiPlugin extends Plugin implements HookPluginInterface
HookPortfolioDownloaded::create()->detach($portfolioDownloaded);
HookPortfolioItemScored::create()->detach($portfolioItemScoredHook);
HookPortfolioCommentScored::create()->detach($portfolioCommentedScoredHook);
HookPortfolioItemEdited::create()->detach($portfolioItemEditedHook);
HookPortfolioCommentEdited::create()->detach($portfolioCommentEditedHook);
return 1;
}
@ -253,6 +257,8 @@ class XApiPlugin extends Plugin implements HookPluginInterface
$portfolioDownloadedHook = XApiPortfolioDownloadedHookObserver::create();
$portfolioItemScoredHook = XApiPortfolioItemScoredHookObserver::create();
$portfolioCommentScoredHook = XApiPortfolioCommentScoredHookObserver::create();
$portfolioItemEditedHook = XApiPortfolioItemEditedHookObserver::create();
$portfolioCommentEditedHook = XApiPortfolioCommentEditedHookObserver::create();
$learningPathItemViewedEvent = HookLearningPathItemViewed::create();
$learningPathEndEvent = HookLearningPathEnd::create();
@ -265,6 +271,8 @@ class XApiPlugin extends Plugin implements HookPluginInterface
$portfolioDownloadedEvent = HookPortfolioDownloaded::create();
$portfolioItemScoredEvent = HookPortfolioItemScored::create();
$portfolioCommentScoredEvent = HookPortfolioCommentScored::create();
$portfolioItemEditedEvent = HookPortfolioItemEdited::create();
$portfolioCommentEditedEvent = HookPortfolioCommentEdited::create();
if ('true' === $this->get(self::SETTING_LRS_LP_ITEM_ACTIVE)) {
$learningPathItemViewedEvent->attach($learningPathItemViewedHook);
@ -298,6 +306,8 @@ class XApiPlugin extends Plugin implements HookPluginInterface
$portfolioDownloadedEvent->attach($portfolioDownloadedHook);
$portfolioItemScoredEvent->attach($portfolioItemScoredHook);
$portfolioCommentScoredEvent->attach($portfolioCommentScoredHook);
$portfolioItemEditedEvent->attach($portfolioItemEditedHook);
$portfolioCommentEditedEvent->attach($portfolioCommentEditedHook);
} else {
$portfolioItemAddedEvent->detach($portfolioItemAddedHook);
$portfolioItemCommentedEvent->detach($portfolioItemCommentedHook);
@ -306,6 +316,8 @@ class XApiPlugin extends Plugin implements HookPluginInterface
$portfolioDownloadedEvent->detach($portfolioDownloadedHook);
$portfolioItemScoredEvent->detach($portfolioItemScoredHook);
$portfolioCommentScoredEvent->detach($portfolioCommentScoredHook);
$portfolioItemEditedEvent->detach($portfolioItemEditedHook);
$portfolioCommentEditedEvent->detach($portfolioCommentEditedHook);
}
return $this;

Loading…
Cancel
Save