LPs: Refactor LP view backend , add scorm zip and add it in var/asset

pull/3741/head
Julio Montoya 4 years ago
parent 7a7af2b00e
commit 95aea43f7c
  1. 43
      public/main/lp/learnpath.class.php
  2. 9
      public/main/lp/learnpathItem.class.php
  3. 119
      public/main/lp/lp_controller.php
  4. 11
      public/main/lp/lp_list.php
  5. 34
      public/main/lp/lp_upload.php
  6. 145
      public/main/lp/lp_view.php
  7. 266
      public/main/lp/scorm.class.php
  8. 2
      src/CoreBundle/Controller/AssetController.php
  9. 30
      src/CoreBundle/Repository/AssetRepository.php
  10. 1
      src/CourseBundle/Entity/CLp.php

@ -990,7 +990,7 @@ class learnpath
self::toggleVisibility($this->lp_id, 0);
if (2 == $this->type || 3 == $this->type) {
/*if (2 == $this->type || 3 == $this->type) {
// This is a scorm learning path, delete the files as well.
$sql = "SELECT path FROM $lp
WHERE iid = ".$this->lp_id;
@ -998,7 +998,7 @@ class learnpath
if (Database::num_rows($res) > 0) {
$row = Database::fetch_array($res);
$path = $row['path'];
$sql = "SELECT id FROM $lp
$sql = "SELECT iid FROM $lp
WHERE
c_id = $course_id AND
path = '$path' AND
@ -1027,7 +1027,7 @@ class learnpath
}
}
}
}
}*/
if (api_get_configuration_value('allow_lp_subscription_to_usergroups')) {
$table = Database::get_course_table(TABLE_LP_REL_USERGROUP);
@ -1894,7 +1894,8 @@ class learnpath
* @param string $file_path the path to the file
* @param string $file_name the original name of the file
*
* @return string 'scorm','aicc','scorm2004','dokeos', 'error-empty-package' if the package is empty, or '' if the package cannot be recognized
* @return string 'scorm','aicc','scorm2004','dokeos', 'error-empty-package'
* if the package is empty, or '' if the package cannot be recognized
*/
public static function getPackageType($file_path, $file_name)
{
@ -3428,7 +3429,6 @@ class learnpath
$lp_item_type = $row['litype'];
$lp_item_path = $row['lipath'];
$lp_item_params = $row['liparams'];
if (empty($lp_item_params) && false !== strpos($lp_item_path, '?')) {
[$lp_item_path, $lp_item_params] = explode('?', $lp_item_path);
}
@ -3447,13 +3447,13 @@ class learnpath
['quiz', 'document', 'final_item', 'link', 'forum', 'thread', 'student_publication']
)
) {
$lp_type = 1;
$lp_type = CLp::LP_TYPE;
}
// Now go through the specific cases to get the end of the path
// @todo Use constants instead of int values.
switch ($lp_type) {
case 1:
case CLp::LP_TYPE:
$file = self::rl_get_resource_link_for_learnpath(
$course_id,
$this->get_id(),
@ -3563,7 +3563,7 @@ class learnpath
$file = 'blank.php?error=document_deleted';
}
break;
case 2:
case CLp::SCORM_TYPE:
if ('dir' !== $lp_item_type) {
// Quite complex here:
// We want to make sure 'http://' (and similar) links can
@ -3580,21 +3580,31 @@ class learnpath
$file = $lp_item_path;
} else {
if ($this->debug > 2) {
error_log('In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path, 0);
error_log('In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path);
}
// Prevent getting untranslatable urls.
$lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
$lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
$asset = $this->getEntity()->getAsset();
$folder = Container::getAssetRepository()->getFolder($asset);
$hasFile = Container::getAssetRepository()->getFileSystem()->has($folder.$lp_item_path);
$file = null;
if ($hasFile) {
$file = Container::getAssetRepository()->getAssetUrl($asset).'/'.$lp_item_path;
}
error_log($file);
// Prepare the path.
$file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
/*$file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
// TODO: Fix this for urls with protocol header.
$file = str_replace('//', '/', $file);
$file = str_replace(':/', '://', $file);
if ('/' == substr($lp_path, -1)) {
if ('/' === substr($lp_path, -1)) {
$lp_path = substr($lp_path, 0, -1);
}
if (!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path))) {
}*/
if (!$hasFile) {
// if file not found.
$decoded = html_entity_decode($lp_item_path);
[$decoded] = explode('?', $decoded);
@ -3631,7 +3641,7 @@ class learnpath
$file = 'lp_content.php?type=dir';
}
break;
case 3:
case CLp::AICC_TYPE:
// 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').'&';
if (!empty($lp_item_params)) {
@ -3682,7 +3692,6 @@ class learnpath
}
break;
case 4:
break;
default:
break;
}
@ -10581,7 +10590,6 @@ EOD;
$lpViewId
) {
$session_id = api_get_session_id();
$course_info = api_get_course_info_by_id($course_id);
$learningPathId = (int) $learningPathId;
$id_in_path = (int) $id_in_path;
@ -10614,7 +10622,6 @@ EOD;
$type = $rowItem->getItemType();
$id = empty($rowItem->getPath()) ? '0' : $rowItem->getPath();
$main_dir_path = api_get_path(WEB_CODE_PATH);
//$main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
$link = '';
$extraParams = api_get_cidreq(true, true, 'learnpath').'&session_id='.$session_id;

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
@ -580,16 +581,14 @@ class learnpathItem
if (Database::num_rows($res) > 0) {
$row = Database::fetch_array($res);
$lp_iv_id = $row[0];
$iva_table = Database::get_course_table(
TABLE_LP_IV_INTERACTION
);
$sql = "SELECT count(id) as mycount
$iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
$sql = "SELECT count(iid) as count
FROM $iva_table
WHERE c_id = $courseId AND lp_iv_id = $lp_iv_id ";
$res_sql = Database::query($sql);
if (Database::num_rows($res_sql) > 0) {
$row = Database::fetch_array($res_sql);
$return = $row['mycount'];
$return = (int) $row['count'];
}
}
} else {

@ -26,6 +26,8 @@ api_protect_course_script(true);
$current_course_tool = TOOL_LEARNPATH;
$_course = api_get_course_info();
$course_id = api_get_course_int_id();
$lpRepo = Container::getLpRepository();
$glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
$showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']);
@ -282,9 +284,8 @@ if (1 == $refresh) {
$lp_controller_touched = 1;
$lp_found = false;
$lpObject = Session::read('lpobject');
/*$lpObject = Session::read('lpobject');
if (!empty($lpObject)) {
/** @var learnpath $oLP */
$oLP = UnserializeApi::unserialize('lp', $lpObject);
if (isset($oLP) && is_object($oLP)) {
if ($debug) {
@ -314,89 +315,67 @@ if (!empty($lpObject)) {
$lp_found = true;
}
}
}
$course_id = api_get_course_int_id();
}*/
$lpItemId = $_REQUEST['id'] ?? 0;
$lpId = $_REQUEST['lp_id'] ?? 0;
$lpItem = null;
$lp = null;
if (!empty($lpItemId)) {
$lpItemRepo = Database::getManager()->getRepository(CLpItem::class);
$lpItem = $lpItemRepo->find($lpItemId);
}
if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])) {
if ($lpId) {
/** @var CLp $lp */
$lp = $lpRepo->find($lpId);
if ($debug > 0) {
error_log(' oLP is not object, has changed or refresh been asked, getting new');
}
// Regenerate a new lp object? Not always as some pages don't need the object (like upload?)
if (!empty($_REQUEST['lp_id']) || !empty($myrefresh_id)) {
// Select the lp in the database and check which type it is (scorm/chamilo/aicc) to generate the
// right object.
if (!empty($_REQUEST['lp_id'])) {
$lp_id = $_REQUEST['lp_id'];
} else {
$lp_id = $myrefresh_id;
}
$lp_id = (int) $lp_id;
if ($lp) {
$logInfo = [
'tool' => TOOL_LEARNPATH,
'action' => 'lp_load',
];
Event::registerLog($logInfo);
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
if (!empty($lp_id)) {
$sel = "SELECT iid, lp_type FROM $lp_table WHERE iid = $lp_id";
$res = Database::query($sel);
if (Database::num_rows($res)) {
$row = Database::fetch_array($res);
$lpIid = $row['iid'];
$type = $row['lp_type'];
$logInfo = [
'tool' => TOOL_LEARNPATH,
'action' => 'lp_load',
];
Event::registerLog($logInfo);
switch ($type) {
case 1:
$oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
break;
case 2:
$oLP = new scorm(api_get_course_id(), $lpIid, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
break;
case 3:
$oLP = new aicc(api_get_course_id(), $lpIid, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
break;
default:
$oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
break;
$type = $lp->getLpType();
switch ($type) {
case CLp::LP_TYPE:
$oLP = new learnpath(api_get_course_id(), $lpId, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
}
break;
case CLp::SCORM_TYPE:
$oLP = new scorm(api_get_course_id(), $lpId, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
break;
case CLp::AICC_TYPE:
$oLP = new aicc(api_get_course_id(), $lpId, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
break;
default:
$oLP = new learnpath(api_get_course_id(), $lpId, api_get_user_id());
if (false !== $oLP) {
$lp_found = true;
}
break;
}
}
if ($lp_found) {
Session::write('oLP', $oLP);
}
}
$lpRepo = Container::getLpRepository();
$lp = null;
if ($lp_found) {
/** @var CLp $lp */
$lp = $lpRepo->find($oLP->get_id());
}
$is_allowed_to_edit = api_is_allowed_to_edit(false, true, false, false);
if (isset($_SESSION['oLP'])) {
if (isset($oLP)) {
// Reinitialises array used by javascript to update items in the TOC.
$_SESSION['oLP']->update_queue = [];
$oLP->update_queue = [];
}
$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
@ -405,10 +384,10 @@ if ($debug) {
error_log('Entered lp_controller.php -+- (action: '.$action.')');
}
$eventLpId = $lp_id = !empty($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0;
if (empty($lp_id)) {
if (isset($_SESSION['oLP'])) {
$eventLpId = $_SESSION['oLP']->get_id();
$eventLpId = $lpId;
if (empty($lpId)) {
if (isset($oLP)) {
$eventLpId = $oLP->get_id();
}
}
@ -1451,7 +1430,7 @@ switch ($action) {
}
if (!empty($_SESSION['oLP'])) {
$_SESSION['lpobject'] = serialize($_SESSION['oLP']);
//$_SESSION['lpobject'] = serialize($_SESSION['oLP']);
if ($debug > 0) {
error_log('lpobject is serialized in session', 0);
}

@ -996,6 +996,17 @@ if ($ending && $allLpTimeValid && api_get_configuration_value('download_files_af
}
}
/*$em = Database::getManager();
$asset = $em->getRepository(\Chamilo\CoreBundle\Entity\Asset::class)->find(1);
$fs = Container::getAssetFileSystem();
var_dump($fs->listContents());
$data = $fs->get('/scorm/'.$asset->getTitle().'/'.$asset->getTitle());
$data =
var_dump($data->getType());
exit;*/
//$zipAdapter->getArchive()->extractTo();
//$asset->getFile()
$template = new Template($nameTools);
$template->assign('first_session_category', $firstSessionCategoryId);
$template->assign('session_star_icon', Display::return_icon('star.png', get_lang('Session')));

@ -41,7 +41,7 @@ if (isset($_POST) && $is_error) {
return false;
unset($_FILES['user_file']);
} elseif ('POST' == $_SERVER['REQUEST_METHOD'] && count($_FILES) > 0 && !empty($_FILES['user_file']['name'])) {
} elseif ('POST' === $_SERVER['REQUEST_METHOD'] && count($_FILES) > 0 && !empty($_FILES['user_file']['name'])) {
// A file upload has been detected, now deal with the file...
// Directory creation.
$stopping_error = false;
@ -58,7 +58,7 @@ if (isset($_POST) && $is_error) {
$proximity = 'local';
if (!empty($_REQUEST['content_proximity'])) {
$proximity = Database::escape_string($_REQUEST['content_proximity']);
$proximity = $_REQUEST['content_proximity'];
}
$maker = 'Scorm';
@ -79,9 +79,8 @@ if (isset($_POST) && $is_error) {
}
break;
case 'scorm':
$oScorm = new scorm();
$entity = $oScorm->getEntity();
$manifest = $oScorm->import_package(
$scorm = new scorm();
$scorm->import_package(
$_FILES['user_file'],
$current_dir,
[],
@ -89,20 +88,19 @@ if (isset($_POST) && $is_error) {
null,
$allowHtaccess
);
if (!empty($manifest)) {
$oScorm->parse_manifest($manifest);
$oScorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']);
Display::addFlash(Display::return_message(get_lang('File upload succeeded!')));
if (!empty($scorm->manifestToString)) {
$scorm->parse_manifest();
$lp = $scorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']);
if ($lp) {
$lp
->setContentLocal($proximity)
->setContentMaker($maker)
;
$em->persist($lp);
$em->flush();
Display::addFlash(Display::return_message(get_lang('File upload succeeded!')));
}
}
$entity
->setContentLocal($proximity)
->setContentMaker($maker)
->setJsLib('scorm_api.php')
;
$em->persist($entity);
$em->flush();
break;
case 'aicc':
$oAICC = new aicc();

@ -22,10 +22,7 @@ $use_anonymous = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_course_script();
if (isset($_REQUEST['origin']) && 'learnpath' === $_REQUEST['origin']) {
$_REQUEST['origin'] = '';
}
$origin = api_get_origin();
// To prevent the template class
$lp_id = !empty($_GET['lp_id']) ? (int) $_GET['lp_id'] : 0;
@ -40,26 +37,21 @@ $courseEntity = api_get_course_entity($course_id);
$sessionEntity = api_get_session_entity($sessionId);
/** @var learnpath $lp */
$lp = Session::read('oLP');
$repo = Container::getLpRepository();
/** @var CLp $entity */
$entity = $repo->find($lp_id);
$lpRepo = Container::getLpRepository();
if (empty($lp)) {
api_not_allowed(true);
}
//$oLP = Session::read('oLP');
/** @var CLp $lp */
$lp = $lp;
// Check if the learning path is visible for student - (LP requisites)
if (!api_is_platform_admin()) {
if (!api_is_allowed_to_edit(null, true, false, false) &&
!learnpath::is_lp_visible_for_student($lp->getEntity(), api_get_user_id())
!learnpath::is_lp_visible_for_student($lp, api_get_user_id())
) {
api_not_allowed(true);
}
}
// Checking visibility (eye icon)
$visibility = $entity->isVisible($courseEntity, $sessionEntity);
$visibility = $lp->isVisible($courseEntity, $sessionEntity);
if (false === $visibility &&
!api_is_allowed_to_edit(false, true, false, false)
@ -67,15 +59,13 @@ if (false === $visibility &&
api_not_allowed(true);
}
$lp_item_id = $lp->get_current_item_id();
$lpType = $lp->get_type();
$lp_item_id = $oLP->get_current_item_id();
$lpType = $lp->getLpType();
if (!$is_allowed_to_edit) {
$categoryId = $lp->getCategoryId();
$category= $lp->getCategory();
$em = Database::getManager();
if (!empty($categoryId)) {
/** @var CLpCategory $category */
$category = $em->getRepository('ChamiloCourseBundle:CLpCategory')->find($categoryId);
if ($category) {
$block = false;
if ($category) {
$user = UserManager::getRepository()->find($user_id);
@ -185,15 +175,15 @@ if ($allowLpItemTip) {
}
// Impress js
if ('impress' === $lp->mode) {
$lp_id = $lp->get_id();
if ('impress' === $lp->getDefaultViewMod()) {
$lp_id = $lp->getIid();
$url = api_get_path(WEB_CODE_PATH)."lp/lp_impress.php?lp_id=$lp_id&".api_get_cidreq();
header("Location: $url");
exit;
}
// Prepare variables for the test tool (just in case) - honestly, this should disappear later on.
Session::write('scorm_view_id', $lp->get_view_id());
Session::write('scorm_view_id', $oLP->get_view_id());
Session::write('scorm_item_id', $lp_item_id);
// Reinit exercises variables to avoid spacename clashes (see exercise tool)
@ -210,8 +200,8 @@ $htmlHeadXtra[] = '<script>
chamilo_courseCode = "'.$course_code.'";
</script>';
$get_toc_list = $lp->get_toc();
$get_teacher_buttons = $lp->get_teacher_toc_buttons();
$get_toc_list = $oLP->get_toc();
$get_teacher_buttons = $oLP->get_teacher_toc_buttons();
$type_quiz = false;
foreach ($get_toc_list as $toc) {
@ -223,13 +213,13 @@ foreach ($get_toc_list as $toc) {
if (!isset($src)) {
$src = null;
switch ($lpType) {
case 1:
$lp->stop_previous_item();
case CLp::LP_TYPE:
$oLP->stop_previous_item();
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
$preReqCheck = $lp->prerequisites_match($lp_item_id);
$preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) {
$src = $lp->get_link(
$src = $oLP->get_link(
'http',
$lp_item_id,
$get_toc_list
@ -242,52 +232,51 @@ if (!isset($src)) {
}
if (isset($file_info['extension']) &&
'pdf' == api_strtolower(substr($file_info['extension'], 0, 3))
'pdf' === api_strtolower(substr($file_info['extension'], 0, 3))
) {
$src = api_get_path(WEB_CODE_PATH).'lp/lp_view_item.php?lp_item_id='.$lp_item_id.'&'.api_get_cidreq();
}
$src = $lp->fixBlockedLinks($src);
$src = $oLP->fixBlockedLinks($src);
if (WhispeakAuthPlugin::isLpItemMarked($lp_item_id)) {
ChamiloSession::write(
WhispeakAuthPlugin::SESSION_LP_ITEM,
['lp' => $lp->lp_id, 'lp_item' => $lp_item_id, 'src' => $src]
['lp' => $lp->getIid(), 'lp_item' => $lp_item_id, 'src' => $src]
);
$src = api_get_path(WEB_PLUGIN_PATH).'whispeakauth/authentify.php';
break;
}
$lp->start_current_item(); // starts time counter manually if asset
$oLP->start_current_item(); // starts time counter manually if asset
} else {
$src = 'blank.php?error=prerequisites';
}
break;
case 2:
case CLp::SCORM_TYPE:
// save old if asset
$lp->stop_previous_item(); // save status manually if asset
$oLP->stop_previous_item(); // save status manually if asset
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
$preReqCheck = $lp->prerequisites_match($lp_item_id);
$preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) {
$src = $lp->get_link('http', $lp_item_id, $get_toc_list);
$lp->start_current_item(); // starts time counter manually if asset
$src = $oLP->get_link('http', $lp_item_id, $get_toc_list);
$oLP->start_current_item(); // starts time counter manually if asset
} else {
$src = 'blank.php?error=prerequisites';
}
break;
case 3:
// aicc
$lp->stop_previous_item(); // save status manually if asset
$htmlHeadXtra[] = '<script src="'.$lp->get_js_lib().'" type="text/javascript" language="javascript"></script>';
$preReqCheck = $lp->prerequisites_match($lp_item_id);
case CLp::AICC_TYPE:
$oLP->stop_previous_item(); // save status manually if asset
$htmlHeadXtra[] = '<script src="'.$oLP->get_js_lib().'" type="text/javascript" language="javascript"></script>';
$preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) {
$src = $lp->get_link(
$src = $oLP->get_link(
'http',
$lp_item_id,
$get_toc_list
);
$lp->start_current_item(); // starts time counter manually if asset
$oLP->start_current_item(); // starts time counter manually if asset
} else {
$src = 'blank.php';
}
@ -311,9 +300,7 @@ if (!empty($_REQUEST['exeId']) &&
isset($lp_id) &&
isset($_REQUEST['lp_item_id'])
) {
global $src;
$lp->items[$lp->current]->write_to_db();
$oLP->items[$oLP->current]->write_to_db();
$TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
@ -335,16 +322,16 @@ if (!empty($_REQUEST['exeId']) &&
$autostart = 'false';
}
$lp->set_previous_item($lp_item_id);
$nameTools = Security::remove_XSS($lp->get_name());
$oLP->set_previous_item($lp_item_id);
$nameTools = Security::remove_XSS($oLP->get_name());
$save_setting = api_get_setting('show_navigation_menu');
global $_setting;
$_setting['show_navigation_menu'] = 'false';
$scorm_css_header = true;
$lp_theme_css = $lp->get_theme();
$lp_theme_css = $oLP->get_theme();
// Sets the css theme of the LP this call is also use at the frames (toc, nav, message).
if ('fullscreen' == $lp->mode) {
if ('fullscreen' === $oLP->mode) {
$htmlHeadXtra[] = "<script>
window.open('$src','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
</script>";
@ -355,9 +342,9 @@ $display_none = '';
$margin_left = '340px';
// Media player code
$display_mode = $lp->mode;
$display_mode = $lp->getDefaultViewMod();
$scorm_css_header = true;
$lp_theme_css = $lp->get_theme();
$lp_theme_css = $lp->getTheme();
// Setting up the CSS theme if exists.
if (!empty($lp_theme_css) && !empty($mycourselptheme) && -1 != $mycourselptheme && 1 == $mycourselptheme) {
@ -368,16 +355,16 @@ if (!empty($lp_theme_css) && !empty($mycourselptheme) && -1 != $mycourselptheme
$progress_bar = '';
if (!api_is_invitee()) {
$progress_bar = $lp->getProgressBar();
$progress_bar = $oLP->getProgressBar();
}
$navigation_bar = $lp->get_navigation_bar();
$navigation_bar_bottom = $lp->get_navigation_bar('control-bottom');
$mediaplayer = $lp->get_mediaplayer($lp->current, $autostart);
$navigation_bar = $oLP->get_navigation_bar();
$navigation_bar_bottom = $oLP->get_navigation_bar('control-bottom');
$mediaplayer = $oLP->get_mediaplayer($oLP->current, $autostart);
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
// Getting all the information about the item.
$sql = "SELECT audio FROM $tbl_lp_item
WHERE c_id = $course_id AND lp_id = ".$lp->lp_id;
WHERE c_id = $course_id AND lp_id = ".$lp->getIid();
$res_media = Database::query($sql);
$show_audioplayer = false;
@ -399,8 +386,9 @@ if ($is_allowed_to_edit) {
'name' => get_lang('Learning paths'),
];
$interbreadcrumb[] = [
'url' => api_get_self()."?action=add_item&type=step&lp_id={$lp->lp_id}&isStudentView=false&".api_get_cidreq(true, true, 'course'),
'name' => $lp->getNameNoTags(),
'url' => api_get_self().
"?action=add_item&type=step&lp_id={$lp->getIid()}&isStudentView=false&".api_get_cidreq(true, true, 'course'),
'name' => $oLP->getNameNoTags(),
];
$interbreadcrumb[] = [
@ -435,11 +423,11 @@ switch ($returnLink) {
}
$lpPreviewImagePath = Display::returnIconPath('unknown.png', ICON_SIZE_BIG);
if ($entity->getResourceNode()->hasResourceFile()) {
$lpPreviewImagePath = $lpRepo->getResourceFileUrl($entity);
if ($lp->getResourceNode()->hasResourceFile()) {
$lpPreviewImagePath = $lpRepo->getResourceFileUrl($lp);
}
if ($lp->current == $lp->get_last()) {
if ($oLP->current == $oLP->get_last()) {
$categories = Category::load(
null,
null,
@ -456,7 +444,7 @@ if ($lp->current == $lp->get_last()) {
if (0 === count($gradebookEvaluations) &&
1 === count($gradebookLinks) &&
LINK_LEARNPATH == $gradebookLinks[0]->get_type() &&
$gradebookLinks[0]->get_ref_id() == $lp->lp_id
$gradebookLinks[0]->get_ref_id() == $oLP->lp_id
) {
$gradebookMinScore = $categories[0]->getCertificateMinScore();
$userScore = $gradebookLinks[0]->calc_score($user_id, 'best');
@ -481,7 +469,7 @@ $template->assign('glossary_tool_available_list', ['true', 'lp', 'exercise_and_l
// If the global gamification mode is enabled...
$gamificationMode = api_get_setting('gamification_mode');
// ...AND this learning path is set in gamification mode, then change the display
$gamificationMode = $gamificationMode && $lp->seriousgame_mode;
$gamificationMode = $gamificationMode && $lp->getSeriousgameMode();
$template->assign('gamification_mode', $gamificationMode);
$template->assign('glossary_extra_tools', api_get_setting('show_glossary_in_extra_tools'));
@ -500,7 +488,7 @@ $template->assign('toc_list', $get_toc_list);
$template->assign('teacher_toc_buttons', $get_teacher_buttons);
$template->assign('iframe_src', $src);
$template->assign('navigation_bar_bottom', $navigation_bar_bottom);
$template->assign('show_left_column', 0 == $lp->getHideTableOfContents());
$template->assign('show_left_column', 0 == $lp->getHideTocFrame());
$showMenu = 0;
$settings = api_get_configuration_value('lp_view_settings');
@ -515,11 +503,11 @@ $template->assign('show_toolbar_by_default', $showMenu);
$template->assign('navigation_in_the_middle', $navigationInTheMiddle);
if (1 == $gamificationMode) {
$template->assign('gamification_stars', $lp->getCalculateStars($sessionId));
$template->assign('gamification_points', $lp->getCalculateScore($sessionId));
$template->assign('gamification_stars', $oLP->getCalculateStars($sessionId));
$template->assign('gamification_points', $oLP->getCalculateScore($sessionId));
}
$template->assign('lp_author', $lp->get_author());
$template->assign('lp_author', $oLP->get_author());
$lpMinTime = '';
if (Tracking::minimumTimeAvailable(api_get_session_id(), api_get_course_int_id())) {
@ -565,17 +553,17 @@ if (Tracking::minimumTimeAvailable(api_get_session_id(), api_get_course_int_id()
}
$template->assign('lp_accumulate_work_time', $lpMinTime);
$template->assign('lp_mode', $lp->mode);
$template->assign('lp_title_scorm', $lp->get_name());
$template->assign('lp_mode', $lp->getDefaultViewMod());
$template->assign('lp_title_scorm', $lp->getName());
if (true === api_get_configuration_value('lp_view_accordion') && 1 == $lpType) {
$template->assign('data_panel', $lp->getTOCTree());
$template->assign('data_panel', $oLP->getTOCTree());
$template->assign('data_list', null);
} else {
$template->assign('data_panel', null);
$template->assign('data_list', $lp->getListArrayToc($get_toc_list));
$template->assign('data_list', $oLP->getListArrayToc($get_toc_list));
}
$template->assign('lp_id', $lp->lp_id);
$template->assign('lp_current_item_id', $lp->get_current_item_id());
$template->assign('lp_id', $lp->getIid());
$template->assign('lp_current_item_id', $oLP->get_current_item_id());
$menuLocation = 'left';
if (!empty(api_get_configuration_value('lp_menu_location'))) {
@ -587,21 +575,20 @@ $template->assign(
'lp_preview_image',
Display::img(
$lpPreviewImagePath,
$lp->getNameNoTags(),
$oLP->getNameNoTags(),
[],
ICON_SIZE_BIG
)
);
$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank');
$template->assign('frame_ready', $frameReady);
$template->displayTemplate('@ChamiloCore/LearnPath/view.html.twig');
// Restore a global setting.
$_setting['show_navigation_menu'] = $save_setting;
Session::write('oLP', $lp);
//Session::write('oLP', $lp);
if ($debug) {
error_log(' ------- end lp_view.php ------');

@ -2,9 +2,12 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpItem;
use Symfony\Component\DomCrawler\Crawler;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
/**
* Defines the scorm class, which is meant to contain the scorm items (nuclear elements).
@ -26,14 +29,16 @@ class scorm extends learnpath
/* Path between the scorm/ directory and the imsmanifest.xml e.g.
maritime_nav/maritime_nav. This is the path that will be used in the
lp_path when importing a package. */
public $subdir = '';
public $items = [];
public $subdir;
public $manifestToString;
public $items;
// Keeps the zipfile safe for the object's life so that we can use it if no title avail.
public $zipname = '';
// Keeps an index of the number of uses of the zipname so far.
public $lastzipnameindex = 0;
public $manifest_encoding = 'UTF-8';
public $debug = false;
public $asset = true;
public $debug = true;
/**
* Class constructor. Based on the parent constructor.
@ -42,9 +47,12 @@ class scorm extends learnpath
* @param int Learnpath ID in DB
* @param int User ID
*/
public function __construct($course_code = null, $resource_id = null, $user_id = null)
public function __construct($courseCode = null, $resource_id = null, $user_id = null)
{
parent::__construct($course_code, $resource_id, $user_id);
$this->items = [];
$this->subdir = '';
$this->manifestToString = '';
parent::__construct($courseCode, $resource_id, $user_id);
}
/**
@ -55,7 +63,7 @@ class scorm extends learnpath
public function open($id)
{
if ($this->debug > 0) {
error_log('New LP - scorm::open() - In scorm::open method', 0);
error_log('scorm::open() - In scorm::open method', 0);
}
}
@ -70,20 +78,10 @@ class scorm extends learnpath
*
* @return array Structured array representing the imsmanifest's contents
*/
public function parse_manifest($file = '')
public function parse_manifest()
{
if ($this->debug > 0) {
error_log('In scorm::parse_manifest('.$file.')', 0);
}
if (empty($file)) {
// Get the path of the imsmanifest file.
}
if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) {
// Parsing using PHP5 DOMXML methods.
if ($this->debug > 0) {
error_log('In scorm::parse_manifest() - Parsing using PHP5 method');
}
if ($this->manifestToString) {
$xml = $this->manifestToString;
// $this->manifest_encoding = api_detect_encoding_xml($xml);
// This is the usual way for reading the encoding.
// This method reads the encoding, it tries to be correct even in cases
@ -92,26 +90,23 @@ class scorm extends learnpath
// UTF-8 is supported by DOMDocument class, this is for sure.
$xml = api_utf8_encode_xml($xml, $this->manifest_encoding);
$crawler = new Crawler();
$crawler->addXmlContent($xml);
$xmlErrors = libxml_get_errors();
if (!empty($xmlErrors)) {
if ($this->debug > 0) {
error_log('New LP - In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument');
error_log('In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument');
}
// Throw exception?
return null;
}
if ($this->debug > 1) {
error_log('New LP - Called (encoding:'.$this->manifest_encoding.' - saved: '.$this->manifest_encoding.')', 0);
error_log('Called (encoding:'.$this->manifest_encoding.' - saved: '.$this->manifest_encoding.')', 0);
}
$root = $crawler->getNode(0);
if ($root->hasAttributes()) {
$attributes = $root->attributes;
if (0 !== $attributes->length) {
@ -226,16 +221,18 @@ class scorm extends learnpath
// End parsing using PHP5 DOMXML methods.
} else {
if ($this->debug > 1) {
error_log('New LP - Could not open/read file '.$file);
error_log('Could not open/read file '.$file);
}
$this->set_error_msg("File $file could not be read");
return null;
}
// @todo implement learnpath_fix_xerte_template
$fixTemplate = api_get_configuration_value('learnpath_fix_xerte_template');
$proxyPath = api_get_configuration_value('learnpath_proxy_url');
if ($fixTemplate && !empty($proxyPath)) {
/*if ($fixTemplate && !empty($proxyPath)) {
// Check organisations:
if (isset($this->manifest['organizations'])) {
foreach ($this->manifest['organizations'] as $data) {
@ -309,7 +306,7 @@ class scorm extends learnpath
}
}
}
}
}*/
// TODO: Close the DOM handler.
return $this->manifest;
@ -321,31 +318,26 @@ class scorm extends learnpath
* @param string $courseCode
* @param int $userMaxScore
* @param int $sessionId
* @param int $userId
*
* @return bool Returns -1 on error
*/
public function import_manifest(
$courseCode,
$userMaxScore = 1,
$sessionId = 0,
$userId = 0
) {
public function import_manifest($courseCode, $userMaxScore = 1, $sessionId = 0)
{
if ($this->debug > 0) {
error_log('New LP - Entered import_manifest('.$courseCode.')', 0);
error_log('Entered import_manifest('.$courseCode.')', 0);
}
$courseInfo = api_get_course_info($courseCode);
$courseId = $courseInfo['real_id'];
$userId = (int) $userId;
if (empty($userId)) {
$userId = api_get_user_id();
}
// Get table names.
$new_lp = Database::get_course_table(TABLE_LP_MAIN);
$new_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$userMaxScore = (int) $userMaxScore;
$sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId;
$repo = Container::getLpRepository();
$em = Database::getManager();
$lp = null;
foreach ($this->organizations as $id => $dummy) {
$oOrganization = &$this->organizations[$id];
// Prepare and execute insert queries:
@ -365,7 +357,7 @@ class scorm extends learnpath
$lp = new CLp();
$lp
->setCId($courseId)
->setLpType(2)
->setLpType(CLp::SCORM_TYPE)
->setName($myname)
->setRef($oOrganization->get_ref())
->setPath($this->subdir)
@ -373,37 +365,15 @@ class scorm extends learnpath
->setJsLib('scorm_api.php')
->setDisplayOrder($dsp)
->setUseMaxScore($userMaxScore)
->setAsset($this->asset)
->setSessionId($sessionId)
->setParent($courseEntity)
->addCourseLink($courseEntity, api_get_session_entity())
;
$repo = Container::getLpRepository();
$repo->create($lp);
/*if ($lp_id) {
$sql = "UPDATE $new_lp SET id = iid WHERE iid = $lp_id";
Database::query($sql);
$this->lp_id = $lp_id;
// Insert into item_property.
api_item_property_update(
$courseInfo,
TOOL_LEARNPATH,
$this->lp_id,
'LearnpathAdded',
$userId
);
api_item_property_update(
$courseInfo,
TOOL_LEARNPATH,
$this->lp_id,
'visible',
$userId
);
}*/
$lp_id = $lp->getIid();
// Now insert all elements from inside that learning path.
// Make sure we also get the href and sco/asset from the resources.
@ -412,7 +382,6 @@ class scorm extends learnpath
$parent = 0;
$previous = 0;
$level = 0;
foreach ($list as $item) {
if ($item['level'] > $level) {
// Push something into the parents array.
@ -440,22 +409,9 @@ class scorm extends learnpath
}
}
$level = $item['level'];
$field_add = '';
$value_add = '';
if (!empty($item['masteryscore'])) {
$field_add .= 'mastery_score, ';
$value_add .= $item['masteryscore'].',';
}
if (!empty($item['maxtimeallowed'])) {
$field_add .= 'max_time_allowed, ';
$value_add .= "'".$item['maxtimeallowed']."',";
}
$title = Database::escape_string($item['title']);
$title = $item['title'];
$title = api_utf8_decode($title);
$max_score = (int) $item['max_score'];
if (0 === $max_score) {
// If max score is not set The use_max_score parameter
// is check in order to use 100 (chamilo style) or '' (strict scorm)
@ -468,29 +424,41 @@ class scorm extends learnpath
$max_score = "'$max_score'";
}
$identifier = Database::escape_string($item['identifier']);
if (empty($title)) {
$title = get_lang('Untitled');
}
$prereq = Database::escape_string($item['prerequisites']);
$item['datafromlms'] = Database::escape_string($item['datafromlms']);
$item['parameters'] = Database::escape_string($item['parameters']);
$lpItem = new CLpItem();
$lpItem
->setTitle($title)
->setCId($courseId)
->setItemType($type)
->setRef($item['identifier'])
->setPath($path)
->setMinScore(0)
->setMaxScore($max_score)
->setParentItemId($parent)
->setPreviousItemId($previous)
->setNextItemId(0)
->setPrerequisite($item['prerequisites'])
->setDisplayOrder($item['rel_order'])
->setLaunchData($item['datafromlms'])
->setParameters($item['parameters'])
->setLp($lp)
;
$sql = "INSERT INTO $new_lp_item (c_id, lp_id,item_type,ref,title, path,min_score,max_score, $field_add parent_item_id,previous_item_id,next_item_id, prerequisite,display_order,launch_data, parameters)
VALUES ($courseId, $lp_id, '$type', '$identifier', '$title', '$path' , 0, $max_score, $value_add $parent, $previous, 0, '$prereq', ".$item['rel_order'].", '".$item['datafromlms']."', '".$item['parameters']."' )";
if (!empty($item['masteryscore'])) {
$lpItem->setMasteryScore($item['masteryscore']);
}
Database::query($sql);
if ($this->debug > 1) {
error_log('New LP - In import_manifest(), inserting item : '.$sql);
if (!empty($item['maxtimeallowed'])) {
$lpItem->setMaxTimeAllowed($item['maxtimeallowed']);
}
$item_id = Database::insert_id();
$em->persist($lpItem);
$em->flush();
$item_id = $lpItem->getIid();
if ($item_id) {
$sql = "UPDATE $new_lp_item SET id = iid WHERE iid = $item_id";
Database::query($sql);
// Now update previous item to change next_item_id.
$upd = "UPDATE $new_lp_item SET next_item_id = $item_id
WHERE iid = $previous";
@ -502,7 +470,6 @@ class scorm extends learnpath
// Code for indexing, now only index specific fields like terms and the title.
if (!empty($_POST['index_document'])) {
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
$di = new ChamiloIndexer();
isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english';
$di->connectDb(null, null, $lang);
@ -550,6 +517,8 @@ class scorm extends learnpath
}
}
}
return $lp;
}
/**
@ -590,7 +559,7 @@ class scorm extends learnpath
$lpToCheck = null,
$allowHtaccess = false
) {
if ($this->debug > 0) {
if ($this->debug) {
error_log(
'In scorm::import_package('.print_r($zipFileInfo, true).',"'.$currentDir.'") method'
);
@ -598,23 +567,22 @@ class scorm extends learnpath
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
$maxFilledSpace = DocumentManager::get_course_quota($courseInfo['code']);
$zipFilePath = $zipFileInfo['tmp_name'];
$zipFileName = $zipFileInfo['name'];
if ($this->debug > 1) {
error_log(
'New LP - import_package() - zip file path = '.$zipFilePath.', zip file name = '.$zipFileName,
'import_package() - zip file path = '.$zipFilePath.', zip file name = '.$zipFileName,
0
);
}
$courseRelDir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses
$courseSysDir = api_get_path(SYS_COURSE_PATH).$courseRelDir; // Absolute system path for this course.
//$courseRelDir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses
//$courseSysDir = api_get_path(SYS_COURSE_PATH).$courseRelDir; // Absolute system path for this course.
$currentDir = api_replace_dangerous_char(trim($currentDir)); // Current dir we are in, inside scorm/
if ($this->debug > 1) {
error_log('New LP - import_package() - current_dir = '.$currentDir, 0);
error_log('import_package() - current_dir = '.$currentDir, 0);
}
// Get name of the zip file without the extension.
@ -626,33 +594,38 @@ class scorm extends learnpath
$newDir = api_replace_dangerous_char(trim($fileBaseName));
$this->subdir = $newDir;
if ($this->debug > 1) {
error_log('New LP - Received zip file name: '.$zipFilePath);
error_log("New LP - subdir is first set to : ".$this->subdir);
error_log("New LP - base file name is : ".$fileBaseName);
error_log('Received zip file name: '.$zipFilePath);
error_log("subdir is first set to : ".$this->subdir);
error_log("base file name is : ".$fileBaseName);
}
$zipFile = new PclZip($zipFilePath);
// Check the zip content (real size and file extension).
$zipContentArray = $zipFile->listContent();
$zipAdapter = new ZipArchiveAdapter($zipFilePath);
$filesystem = new \League\Flysystem\Filesystem($zipAdapter);
$zipContentArray = $filesystem->listContents();
$packageType = '';
$manifestList = [];
// The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
$realFileSize = 0;
foreach ($zipContentArray as $thisContent) {
if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
$file = $thisContent['filename'];
$fileName = $thisContent['path'];
if (preg_match('~.(php.*|phtml)$~i', $fileName)) {
$file = $fileName;
$this->set_error_msg("File $file contains a PHP script");
} elseif (stristr($thisContent['filename'], 'imsmanifest.xml')) {
if ($thisContent['filename'] == basename($thisContent['filename'])) {
} elseif (stristr($fileName, 'imsmanifest.xml')) {
if ($fileName == basename($fileName)) {
} else {
if ($this->debug > 2) {
error_log("New LP - subdir is now ".$this->subdir);
error_log("subdir is now ".$this->subdir);
}
}
$packageType = 'scorm';
$manifestList[] = $thisContent['filename'];
$manifestList[] = $fileName;
}
if (isset($thisContent['size'])) {
$realFileSize += $thisContent['size'];
}
$realFileSize += $thisContent['size'];
}
// Now get the shortest path (basically, the imsmanifest that is the closest to the root).
@ -667,11 +640,12 @@ class scorm extends learnpath
}
$this->subdir .= '/'.dirname($shortestPath); // Do not concatenate because already done above.
$manifest = $shortestPath;
$this->manifestToString = $filesystem->read($shortestPath);
if ($this->debug) {
error_log("New LP - Package type is now: '$packageType'");
error_log("Package type is now: '$packageType'");
}
if ('' == $packageType) {
if ('' === $packageType) {
Display::addFlash(
Display::return_message(get_lang('This is not a valid SCORM ZIP file !'))
);
@ -679,9 +653,10 @@ class scorm extends learnpath
return false;
}
if (!enough_size($realFileSize, $courseSysDir, $maxFilledSpace)) {
// Todo check filesize
/*if (!enough_size($realFileSize, $courseSysDir, $maxFilledSpace)) {
if ($this->debug > 1) {
error_log('New LP - Not enough space to store package');
error_log('Not enough space to store package');
}
Display::addFlash(
Display::return_message(
@ -692,9 +667,9 @@ class scorm extends learnpath
);
return false;
}
}*/
if ($updateDirContents && $lpToCheck) {
/*if ($updateDirContents && $lpToCheck) {
$originalPath = str_replace('/.', '', $lpToCheck->path);
if ($originalPath != $newDir) {
Display::addFlash(Display::return_message(get_lang('The file to upload is not valid.')));
@ -704,13 +679,14 @@ class scorm extends learnpath
}
// It happens on Linux that $newDir sometimes doesn't start with '/'
if ('/' != $newDir[0]) {
if ('/' !== $newDir[0]) {
$newDir = '/'.$newDir;
}
if ('/' == $newDir[strlen($newDir) - 1]) {
if ('/' === $newDir[strlen($newDir) - 1]) {
$newDir = substr($newDir, 0, -1);
}
}*/
/* Uncompressing phase */
/*
@ -719,7 +695,31 @@ class scorm extends learnpath
- parse & change relative html links
- make sure the filenames are secure (filter funny characters or php extensions)
*/
if (is_dir($courseSysDir.$newDir) ||
// 1. Upload zip file
$request = Container::getRequest();
$uploadFile = null;
if ($request->files->has('user_file')) {
$uploadFile = $request->files->get('user_file');
}
$em = Database::getManager();
$asset = new Asset();
$asset
->setCategory(Asset::SCORM)
->setTitle($zipFileName)
->setFile($uploadFile)
->setCompressed(true)
;
$em->persist($asset);
$em->flush();
// 2. Unzip file
$repo = Container::getAssetRepository();
$repo->unZipFile($asset, $zipAdapter);
$this->asset = $asset;
/*if (is_dir($courseSysDir.$newDir) ||
@mkdir(
$courseSysDir.$newDir,
api_get_permissions_for_new_directories()
@ -727,7 +727,7 @@ class scorm extends learnpath
) {
// PHP method - slower...
if ($this->debug >= 1) {
error_log('New LP - Changing dir to '.$courseSysDir.$newDir);
error_log('Changing dir to '.$courseSysDir.$newDir);
}
chdir($courseSysDir.$newDir);
@ -752,9 +752,11 @@ class scorm extends learnpath
api_chmod_R($courseSysDir.$newDir, api_get_permissions_for_new_directories());
} else {
return false;
}
}*/
//return $courseSysDir.$newDir.$manifest;
return $courseSysDir.$newDir.$manifest;
return $asset;
}
/**
@ -798,7 +800,7 @@ class scorm extends learnpath
$zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip';
// Get a temporary dir for creating the zip file.
//error_log('New LP - cleaning dir '.$zipfoldername, 0);
//error_log('cleaning dir '.$zipfoldername, 0);
my_delete($zipfoldername); // Make sure the temp dir is cleared.
mkdir($zipfoldername, api_get_permissions_for_new_directories());
@ -917,7 +919,7 @@ class scorm extends learnpath
$lp_id = intval($lp_id);
$sql = "SELECT * FROM $lp_table WHERE iid = $lp_id";
if ($this->debug > 2) {
error_log('New LP - scorm::reimport_manifest() '.__LINE__.' - Querying lp: '.$sql);
error_log('scorm::reimport_manifest() '.__LINE__.' - Querying lp: '.$sql);
}
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
@ -950,17 +952,17 @@ class scorm extends learnpath
if (is_file($manifest_file) && is_readable($manifest_file)) {
// Re-parse the manifest file.
if ($this->debug > 1) {
error_log('New LP - In scorm::reimport_manifest() - Parsing manifest '.$manifest_file);
error_log('In scorm::reimport_manifest() - Parsing manifest '.$manifest_file);
}
$manifest = $this->parse_manifest($manifest_file);
// Import new LP in DB (ignore the current one).
if ($this->debug > 1) {
error_log('New LP - In scorm::reimport_manifest() - Importing manifest '.$manifest_file);
error_log('In scorm::reimport_manifest() - Importing manifest '.$manifest_file);
}
$this->import_manifest($this->cc);
} else {
if ($this->debug > 0) {
error_log('New LP - In scorm::reimport_manifest() - Could not find manifest file at '.$manifest_file);
error_log('In scorm::reimport_manifest() - Could not find manifest file at '.$manifest_file);
}
}

@ -22,7 +22,7 @@ class AssetController
use ControllerTrait;
/**
* @Route("/{category}/{path}", methods={"GET"}, requirements={"path"=".+"})
* @Route("/{category}/{path}", methods={"GET"}, requirements={"path"=".+"}, name="chamilo_core_asset_showfile")
*/
public function showFile($category, $path, AssetRepository $assetRepository)
{

@ -12,25 +12,21 @@ use League\Flysystem\FilesystemInterface;
use League\Flysystem\MountManager;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Vich\UploaderBundle\Storage\FlysystemStorage;
use Symfony\Component\Routing\RouterInterface;
class AssetRepository extends ServiceEntityRepository
{
protected $mountManager;
protected $storage;
protected $router;
public function __construct(ManagerRegistry $registry, FlysystemStorage $storage, MountManager $mountManager)
public function __construct(ManagerRegistry $registry, RouterInterface $router, MountManager $mountManager)
{
parent::__construct($registry, Asset::class);
$this->storage = $storage;
$this->router = $router;
$this->mountManager = $mountManager;
}
public function getFilename(ResourceFile $resourceFile)
{
return $this->storage->resolveUri($resourceFile);
}
/**
* @return FilesystemInterface
*/
@ -62,6 +58,24 @@ class AssetRepository extends ServiceEntityRepository
}
}
public function getFolder(Asset $asset):? string
{
if ($asset->hasFile()) {
$file = $asset->getTitle();
return '/'.$asset->getCategory().'/'.$file.'/';
}
return null;
}
public function getAssetUrl(Asset $asset)
{
return $this->router->generate(
'chamilo_core_asset_showfile',
['category' => $asset->getCategory(), 'path' => $asset->getTitle()]
);
}
public function getFileContent(Asset $asset): string
{
try {

@ -24,6 +24,7 @@ class CLp extends AbstractResource implements ResourceInterface
{
public const LP_TYPE = 1;
public const SCORM_TYPE = 2;
public const AICC_TYPE = 3;
/**
* @var int

Loading…
Cancel
Save