parent
45b49087b4
commit
4ce93eaf76
@ -0,0 +1,19 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
class HookPortfolioItemViewed extends HookEvent implements HookPortfolioItemViewedEventInterface |
||||||
|
{ |
||||||
|
protected function __construct() |
||||||
|
{ |
||||||
|
parent::__construct('HookPortfolioItemViewed'); |
||||||
|
} |
||||||
|
|
||||||
|
public function notifyItemViewed(): void |
||||||
|
{ |
||||||
|
/** @var HookPortfolioItemViewedObserverInterface $observer */ |
||||||
|
foreach ($this->observers as $observer) { |
||||||
|
$observer->hookItemViewed($this); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
interface HookPortfolioItemViewedEventInterface extends HookEventInterface |
||||||
|
{ |
||||||
|
public function notifyItemViewed(): void; |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
interface HookPortfolioItemViewedObserverInterface extends HookObserverInterface |
||||||
|
{ |
||||||
|
public function hookItemViewed(HookPortfolioItemViewedEventInterface $hookEvent); |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
use Chamilo\CoreBundle\Entity\Portfolio; |
||||||
|
use Chamilo\PluginBundle\XApi\ToolExperience\Statement\PortfolioItemViewed; |
||||||
|
use Doctrine\ORM\OptimisticLockException; |
||||||
|
use Doctrine\ORM\ORMException; |
||||||
|
|
||||||
|
class XApiPortfolioItemViewedHookObserver extends XApiActivityHookObserver implements HookPortfolioItemViewedObserverInterface |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @throws OptimisticLockException |
||||||
|
* @throws ORMException |
||||||
|
*/ |
||||||
|
public function hookItemViewed(HookPortfolioItemViewedEventInterface $hookEvent) |
||||||
|
{ |
||||||
|
/** @var Portfolio $item */ |
||||||
|
$item = $hookEvent->getEventData()['portfolio']; |
||||||
|
|
||||||
|
$statement = (new PortfolioItemViewed($item))->generate(); |
||||||
|
|
||||||
|
$this->saveSharedStatement($statement); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||||
|
|
||||||
|
use Chamilo\CoreBundle\Entity\Portfolio; |
||||||
|
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioCategory; |
||||||
|
use Xabbuh\XApi\Model\Context; |
||||||
|
|
||||||
|
abstract class PortfolioItem extends BaseStatement |
||||||
|
{ |
||||||
|
protected $item; |
||||||
|
|
||||||
|
public function __construct(Portfolio $item) |
||||||
|
{ |
||||||
|
$this->item = $item; |
||||||
|
} |
||||||
|
|
||||||
|
protected function generateContext(): Context |
||||||
|
{ |
||||||
|
$context = parent::generateContext(); |
||||||
|
|
||||||
|
$category = $this->item->getCategory(); |
||||||
|
|
||||||
|
if ($category) { |
||||||
|
$categoryActivity = new PortfolioCategory($category); |
||||||
|
|
||||||
|
$contextActivities = $context |
||||||
|
->getContextActivities() |
||||||
|
->withAddedCategoryActivity( |
||||||
|
$categoryActivity->generate() |
||||||
|
) |
||||||
|
; |
||||||
|
|
||||||
|
$context = $context->withContextActivities($contextActivities); |
||||||
|
} |
||||||
|
|
||||||
|
return $context; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||||
|
|
||||||
|
use Chamilo\CoreBundle\Entity\PortfolioAttachment; |
||||||
|
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioItem; |
||||||
|
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User; |
||||||
|
use Chamilo\PluginBundle\XApi\ToolExperience\Statement\PortfolioItem as PortfolioItemStatement; |
||||||
|
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Viewed; |
||||||
|
use Database; |
||||||
|
use Xabbuh\XApi\Model\Statement; |
||||||
|
|
||||||
|
class PortfolioItemViewed extends PortfolioItemStatement |
||||||
|
{ |
||||||
|
public function generate(): Statement |
||||||
|
{ |
||||||
|
$itemAuthor = $this->item->getUser(); |
||||||
|
|
||||||
|
$itemAttachments = Database::getManager() |
||||||
|
->getRepository(PortfolioAttachment::class) |
||||||
|
->findFromItem($this->item) |
||||||
|
; |
||||||
|
|
||||||
|
$actor = new User($itemAuthor); |
||||||
|
$verb = new Viewed(); |
||||||
|
$object = new PortfolioItem($this->item); |
||||||
|
$context = $this->generateContext(); |
||||||
|
$attachments = $this->generateAttachments($itemAttachments, $itemAuthor); |
||||||
|
|
||||||
|
return new Statement( |
||||||
|
$this->generateStatementId('portfolio-item'), |
||||||
|
$actor->generate(), |
||||||
|
$verb->generate(), |
||||||
|
$object->generate(), |
||||||
|
null, |
||||||
|
null, |
||||||
|
$this->item->getCreationDate(), |
||||||
|
null, |
||||||
|
$context, |
||||||
|
$attachments |
||||||
|
); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue