LP: Move call to HookLearningPathCreated to learnpath::add_lp method and use entity as data - refs BT#20443

pull/4530/head
Angel Fernando Quiroz Campos 3 years ago
parent bdc5dd906e
commit fb90175564
  1. 128
      main/lp/learnpath.class.php
  2. 7
      main/lp/lp_controller.php
  3. 9
      plugin/externalnotificationconnect/src/Hook/ExternalNotificationConnectLearningPathCreatedHookObserver.php

@ -759,6 +759,7 @@ class learnpath
$courseInfo = api_get_course_info();
}
$em = Database::getManager();
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
// Check course code exists.
// Check lp_name doesn't exist, otherwise append something.
@ -777,7 +778,13 @@ class learnpath
if (empty($expired_on)) {
$expired_on = null;
} else {
$expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
$expired_on = api_get_utc_datetime($expired_on, false, true);
}
if (empty($publicated_on)) {
$publicated_on = null;
} else {
$publicated_on = api_get_utc_datetime($publicated_on, false, true);
}
$check_name = "SELECT * FROM $tbl_lp
@ -824,64 +831,69 @@ class learnpath
$dsp = $row[0] + 1;
}
$params = [
'c_id' => $course_id,
'lp_type' => $type,
'name' => $name,
'description' => $description,
'path' => '',
'default_view_mod' => 'embedded',
'default_encoding' => 'UTF-8',
'display_order' => $dsp,
'content_maker' => 'Chamilo',
'content_local' => 'local',
'js_lib' => '',
'session_id' => $session_id,
'created_on' => api_get_utc_datetime(),
'modified_on' => api_get_utc_datetime(),
'publicated_on' => $publicated_on,
'expired_on' => $expired_on,
'category_id' => $categoryId,
'force_commit' => 0,
'content_license' => '',
'debug' => 0,
'theme' => '',
'preview_image' => '',
'author' => '',
'prerequisite' => 0,
'hide_toc_frame' => 0,
'seriousgame_mode' => 0,
'autolaunch' => 0,
'max_attempts' => 0,
'subscribe_users' => 0,
'accumulate_scorm_time' => 1,
];
$id = Database::insert($tbl_lp, $params);
if ($id > 0) {
$sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id";
Database::query($sql);
// Insert into item_property.
api_item_property_update(
$courseInfo,
TOOL_LEARNPATH,
$id,
'LearnpathAdded',
$userId
);
api_set_default_visibility(
$id,
TOOL_LEARNPATH,
0,
$courseInfo,
$session_id,
$userId
);
$newLp = (new CLp())
->setCId($course_id)
->setLpType($type)
->setName($name)
->setDescription($description)
->setPath('')
->setDefaultViewMod('embedded')
->setDefaultEncoding('UTF-8')
->setDisplayOrder($dsp)
->setContentMaker('Chamilo')
->setContentLocal('local')
->setJsLib('')
->setSessionId($session_id)
->setCreatedOn(api_get_utc_datetime(null, false, true))
->setModifiedOn(api_get_utc_datetime(null, false, true))
->setPublicatedOn($publicated_on)
->setExpiredOn($expired_on)
->setCategoryId($categoryId)
->setForceCommit(false)
->setContentLicense('')
->setDebug(false)
->setTheme('')
->setPreviewImage('')
->setAuthor('')
->setPrerequisite(0)
->setHideTocFrame(false)
->setSeriousgameMode(false)
->setAutolaunch(0)
->setMaxAttempts(0)
->setSubscribeUsers(0)
->setAccumulateScormTime(1)
;
$em->persist($newLp);
$em->flush();
HookLearningPathCreated::create()
->setEventData(['lp' => $newLp])
->notifyCreated()
;
$newLp->setId($newLp->getIid());
$em->flush();
// Insert into item_property.
api_item_property_update(
$courseInfo,
TOOL_LEARNPATH,
$newLp->getIid(),
'LearnpathAdded',
$userId
);
api_set_default_visibility(
$newLp->getIid(),
TOOL_LEARNPATH,
0,
$courseInfo,
$session_id,
$userId
);
return $id;
}
break;
return $newLp->getIid();
}
}

@ -827,14 +827,9 @@ switch ($action) {
$subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
$_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
$accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
$accumulateScormTime = $_REQUEST['accumulate_scorm_time'] ?? 'true';
$_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
HookLearningPathCreated::create()
->setEventData(['lp' => $_SESSION['oLP']])
->notifyCreated()
;
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
header("Location: $url&isStudentView=false");
exit;

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\PluginBundle\ExternalNotificationConnect\Traits\RequestTrait\RequestTrait;
class ExternalNotificationConnectLearningPathCreatedHookObserver extends ExternalNotificationConnectHookObserver implements HookLearningPathCreatedObserverInterface
@ -10,7 +11,7 @@ class ExternalNotificationConnectLearningPathCreatedHookObserver extends Externa
public function hookCreated(HookLearningPathCreatedEventInterface $hookEvent)
{
/** @var learnpath $lp */
/** @var CLp $lp */
$lp = $hookEvent->getEventData()['lp'];
$userId = api_get_user_id();
$courseCode = api_get_course_id();
@ -22,7 +23,7 @@ class ExternalNotificationConnectLearningPathCreatedHookObserver extends Externa
$url .= http_build_query(
[
'action' => 'view',
'lp_id' => $lp->lp_id,
'lp_id' => $lp->getIid(),
'isStudentView' => 'true',
]
);
@ -32,10 +33,10 @@ class ExternalNotificationConnectLearningPathCreatedHookObserver extends Externa
[
'user_id' => $userId,
'course_code' => $courseCode,
'content_id' => $lp->get_id(),
'content_id' => $lp->getIid(),
'content_type' => 'lp',
'content_url' => $url,
'post_title' => $lp->get_name(),
'post_title' => $lp->getName(),
]
);
} catch (Exception $e) {

Loading…
Cancel
Save