LPs: Fix get LP items using Assets + fix learnpath.class.php

pull/3741/head
Julio Montoya 5 years ago
parent fe97dd14a3
commit 55e34c5901
  1. 6
      public/main/inc/lib/UnserializeApi.php
  2. 486
      public/main/lp/learnpath.class.php
  3. 39
      public/main/lp/lp_controller.php
  4. 2
      public/main/lp/lp_view.php
  5. 56
      public/main/lp/scorm_api.php
  6. 14
      src/CoreBundle/Component/Utils/AssetDirectoryNamer.php
  7. 5
      src/CourseBundle/Entity/CLp.php

@ -98,11 +98,7 @@ class UnserializeApi
scormOrganization::class, scormOrganization::class,
scormResource::class, scormResource::class,
Link::class, Link::class,
LpItem::class, LpItem::class
\Chamilo\CourseBundle\Entity\CLp::class,
\Chamilo\CoreBundle\Entity\Course::class,
\Chamilo\CoreBundle\Entity\ResourceNode::class,
\Chamilo\CoreBundle\Entity\ResourceType::class,
] ]
); );
break; break;

@ -104,296 +104,275 @@ class learnpath
public $modified_on = ''; public $modified_on = '';
public $publicated_on = ''; public $publicated_on = '';
public $expired_on = ''; public $expired_on = '';
public $ref = null; public $ref;
public $course_int_id; public $course_int_id;
public $course_info = []; public $course_info = [];
public $categoryId; public $categoryId;
public $entity; public $scormUrl;
/** /**
* Constructor. * Constructor.
* Needs a database handler, a course code and a learnpath id from the database. * Needs a database handler, a course code and a learnpath id from the database.
* Also builds the list of items into $this->items. * Also builds the list of items into $this->items.
* *
* @param string $course Course code
* @param int $lp_id c_lp.iid
* @param int $user_id
*/ */
public function __construct($course, $lp_id, $user_id) public function __construct(CLp $entity, $course_info, $user_id)
{ {
$debug = $this->debug; $debug = $this->debug;
$this->encoding = api_get_system_encoding(); $this->encoding = api_get_system_encoding();
if (empty($course)) { $lp_id = (int) $entity->getIid();
$course = api_get_course_id(); $course_id = (int) $course_info['real_id'];
}
$course_info = api_get_course_info($course);
if (!empty($course_info)) {
$this->cc = $course_info['code'];
$this->course_info = $course_info;
$course_id = $course_info['real_id'];
} else {
$this->error = 'Course code does not exist in database.';
}
$lp_id = (int) $lp_id;
$course_id = (int) $course_id;
$this->set_course_int_id($course_id); $this->set_course_int_id($course_id);
// Check learnpath ID.
if (empty($lp_id) || empty($course_id)) { if (empty($lp_id) || empty($course_id)) {
$this->error = "Parameter is empty: LpId:'$lp_id', courseId: '$lp_id'"; $this->error = "Parameter is empty: LpId:'$lp_id', courseId: '$lp_id'";
} else { } else {
$repo = Container::getLpRepository(); $this->lp_id = $lp_id;
/** @var CLp $entity */ $this->type = $entity->getLpType();
$entity = $repo->find($lp_id); $this->name = stripslashes($entity->getName());
if ($entity) { $this->proximity = $entity->getContentLocal();
$this->entity = $entity; $this->theme = $entity->getTheme();
$this->lp_id = $lp_id; $this->maker = $entity->getContentLocal();
$this->type = $entity->getLpType(); $this->prevent_reinit = $entity->getPreventReinit();
$this->name = stripslashes($entity->getName()); $this->seriousgame_mode = $entity->getSeriousgameMode();
$this->proximity = $entity->getContentLocal(); $this->license = $entity->getContentLicense();
$this->theme = $entity->getTheme(); $this->scorm_debug = $entity->getDebug();
$this->maker = $entity->getContentLocal(); $this->js_lib = $entity->getJsLib();
$this->prevent_reinit = $entity->getPreventReinit(); $this->path = $entity->getPath();
$this->seriousgame_mode = $entity->getSeriousgameMode(); $this->author = $entity->getAuthor();
$this->license = $entity->getContentLicense(); $this->hide_toc_frame = $entity->getHideTocFrame();
$this->scorm_debug = $entity->getDebug(); $this->lp_session_id = $entity->getSessionId();
$this->js_lib = $entity->getJsLib(); $this->use_max_score = $entity->getUseMaxScore();
$this->path = $entity->getPath(); $this->subscribeUsers = $entity->getSubscribeUsers();
$this->author = $entity->getAuthor(); $this->created_on = $entity->getCreatedOn()->format('Y-m-d H:i:s');
$this->hide_toc_frame = $entity->getHideTocFrame(); $this->modified_on = $entity->getModifiedOn()->format('Y-m-d H:i:s');
$this->lp_session_id = $entity->getSessionId(); $this->ref = $entity->getRef();
$this->use_max_score = $entity->getUseMaxScore(); $this->categoryId = 0;
$this->subscribeUsers = $entity->getSubscribeUsers(); if ($entity->getCategory()) {
$this->created_on = $entity->getCreatedOn()->format('Y-m-d H:i:s'); $this->categoryId = $entity->getCategory()->getIid();
$this->modified_on = $entity->getModifiedOn()->format('Y-m-d H:i:s'); }
$this->ref = $entity->getRef();
$this->categoryId = 0; if ($entity->hasAsset()) {
if ($entity->getCategory()) { $asset = $entity->getAsset();
$this->categoryId = $entity->getCategory()->getIid(); $this->scormUrl = Container::getAssetRepository()->getAssetUrl($asset).'/';
} }
$this->accumulateScormTime = $entity->getAccumulateWorkTime(); $this->accumulateScormTime = $entity->getAccumulateWorkTime();
if (!empty($entity->getPublicatedOn())) { if (!empty($entity->getPublicatedOn())) {
$this->publicated_on = $entity->getPublicatedOn()->format('Y-m-d H:i:s'); $this->publicated_on = $entity->getPublicatedOn()->format('Y-m-d H:i:s');
} }
if (!empty($entity->getExpiredOn())) { if (!empty($entity->getExpiredOn())) {
$this->expired_on = $entity->getExpiredOn()->format('Y-m-d H:i:s'); $this->expired_on = $entity->getExpiredOn()->format('Y-m-d H:i:s');
} }
if (2 == $this->type) { if (2 == $this->type) {
if (1 == $entity->getForceCommit()) { if (1 == $entity->getForceCommit()) {
$this->force_commit = true; $this->force_commit = true;
}
} }
$this->mode = $entity->getDefaultViewMod(); }
$this->mode = $entity->getDefaultViewMod();
// Check user ID. // Check user ID.
if (empty($user_id)) { if (empty($user_id)) {
$this->error = 'User ID is empty'; $this->error = 'User ID is empty';
} else {
$userInfo = api_get_user_info($user_id);
if (!empty($userInfo)) {
$this->user_id = $userInfo['user_id'];
} else { } else {
$userInfo = api_get_user_info($user_id); $this->error = 'User ID does not exist in database #'.$user_id;
if (!empty($userInfo)) {
$this->user_id = $userInfo['user_id'];
} else {
$this->error = 'User ID does not exist in database #'.$user_id;
}
} }
}
// End of variables checking. // End of variables checking.
$session_id = api_get_session_id(); $session_id = api_get_session_id();
// Get the session condition for learning paths of the base + session. // Get the session condition for learning paths of the base + session.
$session = api_get_session_condition($session_id); $session = api_get_session_condition($session_id);
// Now get the latest attempt from this user on this LP, if available, otherwise create a new one. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
$lp_table = Database::get_course_table(TABLE_LP_VIEW); $lp_table = Database::get_course_table(TABLE_LP_VIEW);
// Selecting by view_count descending allows to get the highest view_count first. // Selecting by view_count descending allows to get the highest view_count first.
$sql = "SELECT * FROM $lp_table $sql = "SELECT * FROM $lp_table
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
lp_id = $lp_id AND lp_id = $lp_id AND
user_id = $user_id user_id = $user_id
$session $session
ORDER BY view_count DESC"; ORDER BY view_count DESC";
$res = Database::query($sql); $res = Database::query($sql);
if (Database::num_rows($res) > 0) { if (Database::num_rows($res) > 0) {
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
$this->attempt = $row['view_count']; $this->attempt = $row['view_count'];
$this->lp_view_id = $row['iid']; $this->lp_view_id = $row['iid'];
$this->last_item_seen = $row['last_item']; $this->last_item_seen = $row['last_item'];
$this->progress_db = $row['progress']; $this->progress_db = $row['progress'];
$this->lp_view_session_id = $row['session_id']; $this->lp_view_session_id = $row['session_id'];
} elseif (!api_is_invitee()) { } elseif (!api_is_invitee()) {
$this->attempt = 1; $this->attempt = 1;
$params = [ $params = [
'c_id' => $course_id, 'c_id' => $course_id,
'lp_id' => $lp_id, 'lp_id' => $lp_id,
'user_id' => $user_id, 'user_id' => $user_id,
'view_count' => 1, 'view_count' => 1,
'session_id' => $session_id, 'session_id' => $session_id,
'last_item' => 0, 'last_item' => 0,
]; ];
$this->last_item_seen = 0; $this->last_item_seen = 0;
$this->lp_view_session_id = $session_id; $this->lp_view_session_id = $session_id;
$this->lp_view_id = Database::insert($lp_table, $params); $this->lp_view_id = Database::insert($lp_table, $params);
} }
// Initialise items. // Initialise items.
$lp_item_table = Database::get_course_table(TABLE_LP_ITEM); $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
$sql = "SELECT * FROM $lp_item_table $sql = "SELECT * FROM $lp_item_table
WHERE c_id = $course_id AND lp_id = '".$this->lp_id."' WHERE c_id = $course_id AND lp_id = '".$this->lp_id."'
ORDER BY parent_item_id, display_order"; ORDER BY parent_item_id, display_order";
$res = Database::query($sql); $res = Database::query($sql);
$lp_item_id_list = []; $lp_item_id_list = [];
while ($row = Database::fetch_array($res)) { while ($row = Database::fetch_array($res)) {
$lp_item_id_list[] = $row['iid']; $lp_item_id_list[] = $row['iid'];
switch ($this->type) { switch ($this->type) {
case 3: //aicc case 3: //aicc
$oItem = new aiccItem('db', $row['iid'], $course_id); $oItem = new aiccItem('db', $row['iid'], $course_id);
if (is_object($oItem)) { if (is_object($oItem)) {
$my_item_id = $oItem->get_id(); $my_item_id = $oItem->get_id();
$oItem->set_lp_view($this->lp_view_id, $course_id); $oItem->set_lp_view($this->lp_view_id, $course_id);
$oItem->set_prevent_reinit($this->prevent_reinit); $oItem->set_prevent_reinit($this->prevent_reinit);
// Don't use reference here as the next loop will make the pointed object change. // Don't use reference here as the next loop will make the pointed object change.
$this->items[$my_item_id] = $oItem; $this->items[$my_item_id] = $oItem;
$this->refs_list[$oItem->ref] = $my_item_id; $this->refs_list[$oItem->ref] = $my_item_id;
} }
break; break;
case 2: case 2:
$oItem = new scormItem('db', $row['iid'], $course_id); $oItem = new scormItem('db', $row['iid'], $course_id);
if (is_object($oItem)) { if (is_object($oItem)) {
$my_item_id = $oItem->get_id(); $my_item_id = $oItem->get_id();
$oItem->set_lp_view($this->lp_view_id, $course_id); $oItem->set_lp_view($this->lp_view_id, $course_id);
$oItem->set_prevent_reinit($this->prevent_reinit); $oItem->set_prevent_reinit($this->prevent_reinit);
// Don't use reference here as the next loop will make the pointed object change. // Don't use reference here as the next loop will make the pointed object change.
$this->items[$my_item_id] = $oItem; $this->items[$my_item_id] = $oItem;
$this->refs_list[$oItem->ref] = $my_item_id; $this->refs_list[$oItem->ref] = $my_item_id;
} }
break; break;
case 1: case 1:
default: default:
$oItem = new learnpathItem($row['iid'], $user_id, $course_id, $row); $oItem = new learnpathItem($row['iid'], $user_id, $course_id, $row);
if (is_object($oItem)) { if (is_object($oItem)) {
$my_item_id = $oItem->get_id(); $my_item_id = $oItem->get_id();
// Moved down to when we are sure the item_view exists. // Moved down to when we are sure the item_view exists.
//$oItem->set_lp_view($this->lp_view_id); //$oItem->set_lp_view($this->lp_view_id);
$oItem->set_prevent_reinit($this->prevent_reinit); $oItem->set_prevent_reinit($this->prevent_reinit);
// Don't use reference here as the next loop will make the pointed object change. // Don't use reference here as the next loop will make the pointed object change.
$this->items[$my_item_id] = $oItem; $this->items[$my_item_id] = $oItem;
$this->refs_list[$my_item_id] = $my_item_id; $this->refs_list[$my_item_id] = $my_item_id;
} }
break; break;
} }
// Setting the object level with variable $this->items[$i][parent] // Setting the object level with variable $this->items[$i][parent]
foreach ($this->items as $itemLPObject) { foreach ($this->items as $itemLPObject) {
$level = self::get_level_for_item( $level = self::get_level_for_item(
$this->items, $this->items,
$itemLPObject->db_id $itemLPObject->db_id
); );
$itemLPObject->level = $level; $itemLPObject->level = $level;
} }
// Setting the view in the item object. // Setting the view in the item object.
if (is_object($this->items[$row['iid']])) { if (is_object($this->items[$row['iid']])) {
$this->items[$row['iid']]->set_lp_view($this->lp_view_id, $course_id); $this->items[$row['iid']]->set_lp_view($this->lp_view_id, $course_id);
if (TOOL_HOTPOTATOES == $this->items[$row['iid']]->get_type()) { if (TOOL_HOTPOTATOES == $this->items[$row['iid']]->get_type()) {
$this->items[$row['iid']]->current_start_time = 0; $this->items[$row['iid']]->current_start_time = 0;
$this->items[$row['iid']]->current_stop_time = 0; $this->items[$row['iid']]->current_stop_time = 0;
}
} }
} }
}
if (!empty($lp_item_id_list)) { if (!empty($lp_item_id_list)) {
$lp_item_id_list_to_string = implode("','", $lp_item_id_list); $lp_item_id_list_to_string = implode("','", $lp_item_id_list);
if (!empty($lp_item_id_list_to_string)) { if (!empty($lp_item_id_list_to_string)) {
// Get last viewing vars. // Get last viewing vars.
$itemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW); $itemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW);
// This query should only return one or zero result. // This query should only return one or zero result.
$sql = "SELECT lp_item_id, status $sql = "SELECT lp_item_id, status
FROM $itemViewTable FROM $itemViewTable
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
lp_view_id = ".$this->get_view_id()." AND lp_view_id = ".$this->get_view_id()." AND
lp_item_id IN ('".$lp_item_id_list_to_string."') lp_item_id IN ('".$lp_item_id_list_to_string."')
ORDER BY view_count DESC "; ORDER BY view_count DESC ";
$status_list = []; $status_list = [];
$res = Database::query($sql); $res = Database::query($sql);
while ($row = Database:: fetch_array($res)) { while ($row = Database:: fetch_array($res)) {
$status_list[$row['lp_item_id']] = $row['status']; $status_list[$row['lp_item_id']] = $row['status'];
} }
foreach ($lp_item_id_list as $item_id) { foreach ($lp_item_id_list as $item_id) {
if (isset($status_list[$item_id])) { if (isset($status_list[$item_id])) {
$status = $status_list[$item_id]; $status = $status_list[$item_id];
if (is_object($this->items[$item_id])) {
$this->items[$item_id]->set_status($status);
if (empty($status)) {
$this->items[$item_id]->set_status(
$this->default_status
);
}
}
} else {
if (!api_is_invitee()) {
if (is_object($this->items[$item_id])) { if (is_object($this->items[$item_id])) {
$this->items[$item_id]->set_status($status); $this->items[$item_id]->set_status(
if (empty($status)) { $this->default_status
$this->items[$item_id]->set_status( );
$this->default_status
);
}
} }
} else {
if (!api_is_invitee()) {
if (is_object($this->items[$item_id])) {
$this->items[$item_id]->set_status(
$this->default_status
);
}
if (!empty($this->lp_view_id)) { if (!empty($this->lp_view_id)) {
// Add that row to the lp_item_view table so that // Add that row to the lp_item_view table so that
// we have something to show in the stats page. // we have something to show in the stats page.
$params = [ $params = [
'c_id' => $course_id, 'c_id' => $course_id,
'lp_item_id' => $item_id, 'lp_item_id' => $item_id,
'lp_view_id' => $this->lp_view_id, 'lp_view_id' => $this->lp_view_id,
'view_count' => 1, 'view_count' => 1,
'status' => 'not attempted', 'status' => 'not attempted',
'start_time' => time(), 'start_time' => time(),
'total_time' => 0, 'total_time' => 0,
'score' => 0, 'score' => 0,
]; ];
Database::insert($itemViewTable, $params); Database::insert($itemViewTable, $params);
$this->items[$item_id]->set_lp_view( $this->items[$item_id]->set_lp_view(
$this->lp_view_id, $this->lp_view_id,
$course_id $course_id
); );
}
} }
} }
} }
} }
} }
}
$this->ordered_items = self::get_flat_ordered_items_list( $this->ordered_items = self::get_flat_ordered_items_list(
$this->get_id(), $this->get_id(),
0, 0,
$course_id $course_id
); );
$this->max_ordered_items = 0; $this->max_ordered_items = 0;
foreach ($this->ordered_items as $index => $dummy) { foreach ($this->ordered_items as $index => $dummy) {
if ($index > $this->max_ordered_items && !empty($dummy)) { if ($index > $this->max_ordered_items && !empty($dummy)) {
$this->max_ordered_items = $index; $this->max_ordered_items = $index;
}
}
// TODO: Define the current item better.
$this->first();
if ($debug) {
error_log('lp_view_session_id '.$this->lp_view_session_id);
error_log('End of learnpath constructor for learnpath '.$this->get_id());
} }
} }
// TODO: Define the current item better.
$this->first();
if ($debug) {
error_log('lp_view_session_id '.$this->lp_view_session_id);
error_log('End of learnpath constructor for learnpath '.$this->get_id());
}
} }
}
public function getEntity(): CLp
{
return $this->entity;
} }
/** /**
@ -3508,7 +3487,8 @@ class learnpath
$linkProtocol = substr($file, 0, 5); $linkProtocol = substr($file, 0, 5);
if ('http:' === $linkProtocol) { if ('http:' === $linkProtocol) {
//this is the special intervention case //this is the special intervention case
$file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=nonhttps&source='.urlencode($file); $file = api_get_path(WEB_CODE_PATH).
'lp/embed.php?type=nonhttps&source='.urlencode($file);
} }
} }
} }
@ -3531,7 +3511,7 @@ class learnpath
$type_quiz = false; $type_quiz = false;
foreach ($list as $toc) { foreach ($list as $toc) {
if ($toc['id'] == $lp_item_id && 'quiz' == $toc['type']) { if ($toc['id'] == $lp_item_id && 'quiz' === $toc['type']) {
$type_quiz = true; $type_quiz = true;
} }
} }
@ -3586,15 +3566,14 @@ class learnpath
$lp_item_path = preg_replace('/%2F/', '/', $lp_item_path); $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
$lp_item_path = preg_replace('/%3A/', ':', $lp_item_path); $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
$asset = $this->getEntity()->getAsset(); /*$asset = $this->getEntity()->getAsset();
$folder = Container::getAssetRepository()->getFolder($asset); $folder = Container::getAssetRepository()->getFolder($asset);
$hasFile = Container::getAssetRepository()->getFileSystem()->has($folder.$lp_item_path); $hasFile = Container::getAssetRepository()->getFileSystem()->has($folder.$lp_item_path);
$file = null; $file = null;
if ($hasFile) { if ($hasFile) {
$file = Container::getAssetRepository()->getAssetUrl($asset).'/'.$lp_item_path; $file = Container::getAssetRepository()->getAssetUrl($asset).'/'.$lp_item_path;
} }*/
$file = $this->scormUrl.$lp_item_path;
error_log($file);
// Prepare the path. // Prepare the path.
/*$file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path; /*$file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
@ -3604,7 +3583,7 @@ class learnpath
if ('/' === substr($lp_path, -1)) { if ('/' === substr($lp_path, -1)) {
$lp_path = substr($lp_path, 0, -1); $lp_path = substr($lp_path, 0, -1);
}*/ }*/
if (!$hasFile) { /*if (!$hasFile) {
// if file not found. // if file not found.
$decoded = html_entity_decode($lp_item_path); $decoded = html_entity_decode($lp_item_path);
[$decoded] = explode('?', $decoded); [$decoded] = explode('?', $decoded);
@ -3629,7 +3608,7 @@ class learnpath
} else { } else {
$file = $course_path.'/scorm/'.$lp_path.'/'.$decoded; $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
} }
} }*/
} }
// We want to use parameters if they were defined in the imsmanifest // We want to use parameters if they were defined in the imsmanifest
@ -3643,7 +3622,8 @@ class learnpath
break; break;
case CLp::AICC_TYPE: case CLp::AICC_TYPE:
// Formatting AICC HACP append URL. // Formatting AICC HACP append URL.
$aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'lp/aicc_hacp.php').'&'; $aicc_append = '?aicc_sid='.
urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'lp/aicc_hacp.php').'&';
if (!empty($lp_item_params)) { if (!empty($lp_item_params)) {
$aicc_append .= $lp_item_params.'&'; $aicc_append .= $lp_item_params.'&';
} }

@ -25,9 +25,9 @@ require_once __DIR__.'/../inc/global.inc.php';
api_protect_course_script(true); api_protect_course_script(true);
$current_course_tool = TOOL_LEARNPATH; $current_course_tool = TOOL_LEARNPATH;
$_course = api_get_course_info();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$lpRepo = Container::getLpRepository(); $lpRepo = Container::getLpRepository();
$courseInfo = api_get_course_info();
$glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools'); $glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
$showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']); $showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']);
@ -284,7 +284,7 @@ if (1 == $refresh) {
$lp_controller_touched = 1; $lp_controller_touched = 1;
$lp_found = false; $lp_found = false;
/*$lpObject = Session::read('lpobject'); $lpObject = Session::read('lpobject');
if (!empty($lpObject)) { if (!empty($lpObject)) {
$oLP = UnserializeApi::unserialize('lp', $lpObject); $oLP = UnserializeApi::unserialize('lp', $lpObject);
if (isset($oLP) && is_object($oLP)) { if (isset($oLP) && is_object($oLP)) {
@ -304,7 +304,7 @@ if (!empty($lpObject)) {
error_log('api_get_course_id(): '.api_get_course_id()); error_log('api_get_course_id(): '.api_get_course_id());
} }
if (1 == $myrefresh) { if (1 === $myrefresh) {
$myrefresh_id = $oLP->get_id(); $myrefresh_id = $oLP->get_id();
} }
$oLP = null; $oLP = null;
@ -315,7 +315,7 @@ if (!empty($lpObject)) {
$lp_found = true; $lp_found = true;
} }
} }
}*/ }
$lpItemId = $_REQUEST['id'] ?? 0; $lpItemId = $_REQUEST['id'] ?? 0;
$lpId = $_REQUEST['lp_id'] ?? 0; $lpId = $_REQUEST['lp_id'] ?? 0;
@ -345,30 +345,32 @@ if ($lpId) {
switch ($type) { switch ($type) {
case CLp::LP_TYPE: case CLp::LP_TYPE:
$oLP = new learnpath(api_get_course_id(), $lpId, api_get_user_id()); $oLP = new learnpath($lp, $courseInfo, api_get_user_id());
if (false !== $oLP) { if (false !== $oLP) {
$lp_found = true; $lp_found = true;
} }
break; break;
case CLp::SCORM_TYPE: case CLp::SCORM_TYPE:
$oLP = new scorm(api_get_course_id(), $lpId, api_get_user_id()); $oLP = new scorm($lp, $courseInfo, api_get_user_id());
if (false !== $oLP) { if (false !== $oLP) {
$lp_found = true; $lp_found = true;
} }
break; break;
case CLp::AICC_TYPE: case CLp::AICC_TYPE:
$oLP = new aicc(api_get_course_id(), $lpId, api_get_user_id()); $oLP = new aicc($lp, $courseInfo, api_get_user_id());
if (false !== $oLP) { if (false !== $oLP) {
$lp_found = true; $lp_found = true;
} }
break; break;
default: default:
$oLP = new learnpath(api_get_course_id(), $lpId, api_get_user_id()); $oLP = new learnpath($lp, $lpId, api_get_user_id());
if (false !== $oLP) { if (false !== $oLP) {
$lp_found = true; $lp_found = true;
} }
break; break;
} }
Session::write('oLP', $oLP);
} }
} }
@ -457,7 +459,6 @@ switch ($action) {
} }
} }
} }
Session::write('oLP', $_SESSION['oLP']);
if (!$is_allowed_to_edit) { if (!$is_allowed_to_edit) {
api_not_allowed(true); api_not_allowed(true);
} }
@ -524,17 +525,12 @@ switch ($action) {
if (isset($_POST['submit_button']) && !empty($post_title)) { if (isset($_POST['submit_button']) && !empty($post_title)) {
// If a title was submitted: // If a title was submitted:
// Updating the lp.modified_on
$_SESSION['oLP']->set_modified_on();
if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) { if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
// Check post_time to ensure ??? (counter-hacking measure?) // Check post_time to ensure ??? (counter-hacking measure?)
require 'lp_add_item.php'; require 'lp_add_item.php';
} else { } else {
Session::write('post_time', $_POST['post_time']); Session::write('post_time', $_POST['post_time']);
$directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0; $directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0;
$courseInfo = api_get_course_info();
if (empty($directoryParentId)) { if (empty($directoryParentId)) {
$_SESSION['oLP']->generate_lp_folder($courseInfo); $_SESSION['oLP']->generate_lp_folder($courseInfo);
} }
@ -553,7 +549,7 @@ switch ($action) {
} else { } else {
if ($_POST['content_lp']) { if ($_POST['content_lp']) {
$document_id = $_SESSION['oLP']->create_document( $document_id = $_SESSION['oLP']->create_document(
$_course, $courseInfo,
$_POST['content_lp'], $_POST['content_lp'],
$_POST['title'], $_POST['title'],
'html', 'html',
@ -577,7 +573,7 @@ switch ($action) {
} else { } else {
if ($_POST['content_lp']) { if ($_POST['content_lp']) {
$document_id = $_SESSION['oLP']->createReadOutText( $document_id = $_SESSION['oLP']->createReadOutText(
$_course, $courseInfo,
$_POST['content_lp'], $_POST['content_lp'],
$_POST['title'], $_POST['title'],
$directoryParentId $directoryParentId
@ -758,9 +754,6 @@ switch ($action) {
} else { } else {
Session::write('refresh', 1); Session::write('refresh', 1);
if (isset($_POST['submit_button']) && !empty($post_title)) { if (isset($_POST['submit_button']) && !empty($post_title)) {
// Updating the lp.modified_on
$_SESSION['oLP']->set_modified_on();
// TODO: mp3 edit // TODO: mp3 edit
$audio = []; $audio = [];
if (isset($_FILES['mp3'])) { if (isset($_FILES['mp3'])) {
@ -785,7 +778,7 @@ switch ($action) {
); );
if (isset($_POST['content_lp'])) { if (isset($_POST['content_lp'])) {
$_SESSION['oLP']->edit_document($_course); $_SESSION['oLP']->edit_document($courseInfo);
} }
$is_success = true; $is_success = true;
@ -931,7 +924,7 @@ switch ($action) {
// Teachers can export to PDF // Teachers can export to PDF
if (!$is_allowed_to_edit) { if (!$is_allowed_to_edit) {
if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->getEntity(), api_get_user_id(), $_course)) { if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->getEntity(), api_get_user_id(), $courseInfo)) {
api_not_allowed(); api_not_allowed();
} }
} }
@ -1247,7 +1240,7 @@ switch ($action) {
} else { } else {
$_SESSION['oLP']->save_current(); $_SESSION['oLP']->save_current();
$_SESSION['oLP']->save_last(); $_SESSION['oLP']->save_last();
$url = $_course['course_public_url'].'?sid='.api_get_session_id(); $url = $courseInfo['course_public_url'].'?sid='.api_get_session_id();
$redirectTo = isset($_GET['redirectTo']) ? $_GET['redirectTo'] : ''; $redirectTo = isset($_GET['redirectTo']) ? $_GET['redirectTo'] : '';
switch ($redirectTo) { switch ($redirectTo) {
case 'lp_list': case 'lp_list':
@ -1430,7 +1423,7 @@ switch ($action) {
} }
if (!empty($_SESSION['oLP'])) { if (!empty($_SESSION['oLP'])) {
//$_SESSION['lpobject'] = serialize($_SESSION['oLP']); Session::write('lpobject', serialize($oLP));
if ($debug > 0) { if ($debug > 0) {
error_log('lpobject is serialized in session', 0); error_log('lpobject is serialized in session', 0);
} }

@ -215,7 +215,7 @@ if (!isset($src)) {
switch ($lpType) { switch ($lpType) {
case CLp::LP_TYPE: case CLp::LP_TYPE:
$oLP->stop_previous_item(); $oLP->stop_previous_item();
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript"></script>';
$preReqCheck = $oLP->prerequisites_match($lp_item_id); $preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) { if (true === $preReqCheck) {

@ -22,18 +22,13 @@ use ChamiloSession as Session;
// of Maritime Navigation when trying to execute this row // of Maritime Navigation when trying to execute this row
// var result = api.LMSInitialize(""); // var result = api.LMSInitialize("");
// get the error response : you are not authorized to call this function // get the error response : you are not authorized to call this function
// Flag to allow for anonymous user - needs to be set before global.inc.php. // Flag to allow for anonymous user - needs to be set before global.inc.php.
$use_anonymous = true; $use_anonymous = true;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$file = Session::read('file');
/** @var learnpath $oLP */ /** @var learnpath $oLP */
$oLP = UnserializeApi::unserialize( //$oLP = UnserializeApi::unserialize('lp', Session::read('lpobject'));
'lp', $oLP = Session::read('oLP');
Session::read('lpobject')
);
if (!is_object($oLP)) { if (!is_object($oLP)) {
error_log('New LP - scorm_api - Could not load oLP object', 0); error_log('New LP - scorm_api - Could not load oLP object', 0);
exit; exit;
@ -45,9 +40,10 @@ if (!is_object($oItem)) {
error_log('New LP - scorm_api - Could not load oItem item', 0); error_log('New LP - scorm_api - Could not load oItem item', 0);
exit; exit;
} }
$autocomplete_when_80pct = 0;
$user = api_get_user_info(); $user = api_get_user_info();
$userId = api_get_user_id(); $userId = api_get_user_id();
$itemId = $oItem->get_id();
$lpId = $oLP->get_id();
header('Content-type: text/javascript'); header('Content-type: text/javascript');
@ -83,9 +79,6 @@ function APIobject() {
// SCORM // SCORM
var API = new APIobject(); //for scorm 1.2 var API = new APIobject(); //for scorm 1.2
var api = API; var api = API;
//var API_1484_11 = new APIobject(); //for scorm 1.3
//var api_1484_11 = API_1484_11;
// SCORM-specific Error codes // SCORM-specific Error codes
var G_NoError = 0; var G_NoError = 0;
var G_GeneralException = 101; var G_GeneralException = 101;
@ -113,7 +106,6 @@ var G_InvalidSetValueMessage = 'Invalid set value, element is a keywo
var G_ElementIsReadOnlyMessage = 'Element is read only'; var G_ElementIsReadOnlyMessage = 'Element is read only';
var G_ElementIsWriteOnlyMessage = 'Element is write only'; var G_ElementIsWriteOnlyMessage = 'Element is write only';
var G_IncorrectDataTypeMessage = 'Incorrect Data Type'; var G_IncorrectDataTypeMessage = 'Incorrect Data Type';
var olms = new Object(); var olms = new Object();
//the last recorded error message was: //the last recorded error message was:
@ -146,14 +138,12 @@ olms.scorm_variables = new Array(
// manage variables to save or not // manage variables to save or not
olms.variable_to_send = new Array(); olms.variable_to_send = new Array();
// temporary list of variables (gets set to true when set through LMSSetValue) // temporary list of variables (gets set to true when set through LMSSetValue)
olms.updatable_vars_list = new Array(); olms.updatable_vars_list = new Array();
// marker of whether the LMSFinish() function was called, which is important for SCORM behaviour // marker of whether the LMSFinish() function was called, which is important for SCORM behaviour
olms.finishSignalReceived = 0; olms.finishSignalReceived = 0;
// marker to remember if the SCO has calles a "set" on lesson_status // marker to remember if the SCO has calles a "set" on lesson_status
olms.statusSignalReceived = 0; olms.statusSignalReceived = 0;
// Strictly scorm variables // Strictly scorm variables
olms.score=<?php echo $oItem->get_score(); ?>; olms.score=<?php echo $oItem->get_score(); ?>;
olms.max='<?php echo $oItem->get_max(); ?>'; olms.max='<?php echo $oItem->get_max(); ?>';
@ -172,20 +162,14 @@ olms.info_lms_item = new Array();
// Chamilo internal variables (not SCORM) // Chamilo internal variables (not SCORM)
// olms.saved_lesson_status = 'not attempted'; // olms.saved_lesson_status = 'not attempted';
olms.lms_lp_id = <?php echo $oLP->get_id(); ?>; olms.lms_lp_id = <?php echo $lpId; ?>;
olms.lms_item_id = <?php echo $oItem->get_id(); ?>; olms.lms_item_id = <?php echo $itemId; ?>;
olms.lms_initialized = 0; olms.lms_initialized = 0;
// switch_finished indicates if the switch process is finished (if it has gone // switch_finished indicates if the switch process is finished (if it has gone
// through LMSInitialize() for the new item. Until then, all LMSSetValue() // through LMSInitialize() for the new item. Until then, all LMSSetValue()
// commands received are executed on the *previous/current* item // commands received are executed on the *previous/current* item
// This flag is updated in LMSInitialize() and in switch_item() // This flag is updated in LMSInitialize() and in switch_item()
olms.switch_finished = 0; olms.switch_finished = 0;
//olms.lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
//olms.lms_complete_lessons = <?php echo $oLP->get_complete_items_count(); ?>;
//olms.lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode; ?>';
//if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
olms.lms_view_id = '<?php echo $oLP->get_view(null, $userId); ?>'; olms.lms_view_id = '<?php echo $oLP->get_view(null, $userId); ?>';
if(olms.lms_view_id == ''){ olms.lms_view_id = 1;} if(olms.lms_view_id == ''){ olms.lms_view_id = 1;}
olms.lms_user_id = '<?php echo $userId; ?>'; olms.lms_user_id = '<?php echo $userId; ?>';
@ -239,8 +223,8 @@ $(function() {
logit_scorm('Other SCORM calls are shown in orange.', 1); logit_scorm('Other SCORM calls are shown in orange.', 1);
logit_lms('To add new messages to these logs, use logit_lms() or logit_scorm().'); logit_lms('To add new messages to these logs, use logit_lms() or logit_scorm().');
olms.info_lms_item[0] = '<?php echo $oItem->get_id(); ?>'; olms.info_lms_item[0] = '<?php echo $itemId; ?>';
olms.info_lms_item[1] = '<?php echo $oItem->get_id(); ?>'; olms.info_lms_item[1] = '<?php echo $itemId; ?>';
$("#content_id").on('load', function() { $("#content_id").on('load', function() {
logit_lms('#content_id load event starts'); logit_lms('#content_id load event starts');
@ -358,7 +342,7 @@ function LMSInitialize() {
$fixLinkSetting = api_get_configuration_value('lp_fix_embed_content'); $fixLinkSetting = api_get_configuration_value('lp_fix_embed_content');
$showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']); $showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']);
if ($showGlossary) { if ($showGlossary) {
if ('ismanual' == api_get_setting('show_glossary_in_documents')) { if ('ismanual' === api_get_setting('show_glossary_in_documents')) {
?> ?>
if (olms.lms_item_type == 'sco') { if (olms.lms_item_type == 'sco') {
attach_glossary_into_scorm('automatic'); attach_glossary_into_scorm('automatic');
@ -366,15 +350,13 @@ function LMSInitialize() {
attach_glossary_into_scorm('manual'); attach_glossary_into_scorm('manual');
} }
<?php <?php
} elseif ('isautomatic' == api_get_setting('show_glossary_in_documents')) { } elseif ('isautomatic' === api_get_setting('show_glossary_in_documents')) {
?> ?>
attach_glossary_into_scorm('automatic'); attach_glossary_into_scorm('automatic');
<?php <?php
} ?> }
<?php }
} ?> if ($fixLinkSetting) {
<?php if ($fixLinkSetting) {
?> ?>
attach_glossary_into_scorm('fix_links'); attach_glossary_into_scorm('fix_links');
<?php <?php
@ -407,7 +389,9 @@ function LMSGetValue(param) {
} }
olms.G_LastError = G_NotInitialized; olms.G_LastError = G_NotInitialized;
olms.G_LastErrorMessage = G_NotInitializedMessage; olms.G_LastErrorMessage = G_NotInitializedMessage;
logit_scorm('LMSGetValue('+param+') on item id '+olms.lms_item_id+':<br />=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0); logit_scorm(
'LMSGetValue('+param+') on item id '+olms.lms_item_id+':<br />=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage
);
return ''; return '';
} }
@ -518,9 +502,7 @@ function LMSGetValue(param) {
} else if(param == 'cmi.objectives._children'){ } else if(param == 'cmi.objectives._children'){
// ---- cmi.objectives._children // ---- cmi.objectives._children
result = 'id,score,status'; result = 'id,score,status';
} else if(param == 'cmi.objectives._count'){ } else if(param == 'cmi.objectives._count') {
// ---- cmi.objectives._count
//result='<?php echo $oItem->get_view_count(); ?>';
result = olms.item_objectives.length; result = olms.item_objectives.length;
} else if(param.substring(0,15)== 'cmi.objectives.'){ } else if(param.substring(0,15)== 'cmi.objectives.'){
var myres = ''; var myres = '';
@ -1684,8 +1666,7 @@ function switch_item(current_item, next_item)
var mysrc = '<?php echo api_get_path(WEB_CODE_PATH); ?>lp/lp_controller.php?action=content&lp_id=' + olms.lms_lp_id + var mysrc = '<?php echo api_get_path(WEB_CODE_PATH); ?>lp/lp_controller.php?action=content&lp_id=' + olms.lms_lp_id +
'&item_id=' + next_item + '&cid=' + olms.lms_course_id + '&sid=' + olms.lms_session_id; '&item_id=' + next_item + '&cid=' + olms.lms_course_id + '&sid=' + olms.lms_session_id;
var cont_f = $("#content_id"); var cont_f = $("#content_id");
<?php if ('fullscreen' === $oLP->mode) {
<?php if ('fullscreen' == $oLP->mode) {
?> ?>
cont_f = window.open('' + mysrc, 'content_id', 'toolbar=0,location=0,status=0,scrollbars=1,resizable=1'); cont_f = window.open('' + mysrc, 'content_id', 'toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
cont_f.onload=function(){ cont_f.onload=function(){
@ -1694,7 +1675,6 @@ function switch_item(current_item, next_item)
cont_f.onunload=function(){ cont_f.onunload=function(){
olms.info_lms_item[0]=olms.info_lms_item[1]; olms.info_lms_item[0]=olms.info_lms_item[1];
} }
<?php <?php
} else { } else {
?> ?>

@ -9,7 +9,6 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Vich\UploaderBundle\Mapping\PropertyMapping; use Vich\UploaderBundle\Mapping\PropertyMapping;
use Vich\UploaderBundle\Naming\ConfigurableInterface; use Vich\UploaderBundle\Naming\ConfigurableInterface;
use Vich\UploaderBundle\Naming\DirectoryNamerInterface; use Vich\UploaderBundle\Naming\DirectoryNamerInterface;
use Vich\UploaderBundle\Util\Transliterator;
class AssetDirectoryNamer implements DirectoryNamerInterface, ConfigurableInterface class AssetDirectoryNamer implements DirectoryNamerInterface, ConfigurableInterface
{ {
@ -20,25 +19,14 @@ class AssetDirectoryNamer implements DirectoryNamerInterface, ConfigurableInterf
private $charsPerDir = 2; private $charsPerDir = 2;
private $dirs = 1; private $dirs = 1;
/**
* @var bool
*/
private $transliterate = false;
/** /**
* @var PropertyAccessorInterface * @var PropertyAccessorInterface
*/ */
protected $propertyAccessor; protected $propertyAccessor;
/** public function __construct(?PropertyAccessorInterface $propertyAccessor)
* @var Transliterator
*/
private $transliterator;
public function __construct(?PropertyAccessorInterface $propertyAccessor, Transliterator $transliterator)
{ {
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
$this->transliterator = $transliterator;
} }
/** /**

@ -1093,6 +1093,11 @@ class CLp extends AbstractResource implements ResourceInterface
return $this->asset; return $this->asset;
} }
public function hasAsset(): bool
{
return null !== $this->asset;
}
public function setAsset(?Asset $asset): self public function setAsset(?Asset $asset): self
{ {
$this->asset = $asset; $this->asset = $asset;

Loading…
Cancel
Save