LP: Add hook when viewing item - refs BT#16742

pull/3680/head
Angel Fernando Quiroz Campos 5 years ago
parent c0df68672f
commit 218dbd3c89
  1. 29
      main/inc/lib/hook/HookLearningPathItemViewed.php
  2. 13
      main/inc/lib/hook/interfaces/HookLearningPathItemViewedEventInterface.php
  3. 15
      main/inc/lib/hook/interfaces/HookLearningPathItemViewedObserverInterface.php
  4. 4
      main/lp/lp_ajax_save_item.php

@ -0,0 +1,29 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class HookLearningPathItemViewed.
*/
class HookLearningPathItemViewed extends HookEvent implements HookLearningPathItemViewedEventInterface
{
/**
* HookLearningPathItemViewed constructor.
*
* @throws \Exception
*/
protected function __construct()
{
parent::__construct('HookLearningPathItemViewed');
}
/**
* @inheritDoc
*/
public function notifyLearningPathItemViewed()
{
/** @var \HookLearningPathItemViewedObserverInterface $observer */
foreach ($this->observers as $observer) {
$observer->hookLearningPathItemViewed($this);
}
}
}

@ -0,0 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface HookLearningPathItemViewedEventInterface.
*/
interface HookLearningPathItemViewedEventInterface extends HookEventInterface
{
/**
* @return mixed
*/
public function notifyLearningPathItemViewed();
}

@ -0,0 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface HookLearningPathItemViewedObserverInterface.
*/
interface HookLearningPathItemViewedObserverInterface extends HookObserverInterface
{
/**
* @param \HookLearningPathItemViewedEventInterface $event
*
* @return mixed
*/
public function hookLearningPathItemViewed(HookLearningPathItemViewedEventInterface $event);
}

@ -541,6 +541,10 @@ function save_item(
// To be sure progress is updated.
$myLP->save_last($score);
HookLearningPathItemViewed::create()
->setEventData(['item_view_id' => $myLPI->db_item_view_id])
->notifyLearningPathItemViewed();
Session::write('lpobject', serialize($myLP));
Session::write('oLP', $myLP);
if ($debug > 0) {

Loading…
Cancel
Save