Learning path: Add audio from different folder BT#17524

pull/3357/head
Julio Montoya 5 years ago
parent 6cb3746eff
commit 039984b97a
  1. 18
      main/inc/lib/document.lib.php
  2. 135
      main/lp/learnpath.class.php
  3. 297
      main/lp/learnpathItem.class.php
  4. 38
      main/lp/lp_add_audio.php
  5. 27
      main/lp/lp_admin_view.php
  6. 4
      main/lp/lp_controller.php
  7. 17
      main/lp/lp_move_item.php

@ -772,8 +772,6 @@ class DocumentManager
if ($can_see_invisible) { if ($can_see_invisible) {
// condition for the session // condition for the session
$session_id = api_get_session_id(); $session_id = api_get_session_id();
//$condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id');
$session_id = $session_id ?: api_get_session_id(); $session_id = $session_id ?: api_get_session_id();
$condition_session = " AND (last.session_id = '$session_id' OR (last.session_id = '0' OR last.session_id IS NULL) )"; $condition_session = " AND (last.session_id = '$session_id' OR (last.session_id = '0' OR last.session_id IS NULL) )";
$condition_session .= self::getSessionFolderFilters($path, $session_id); $condition_session .= self::getSessionFolderFilters($path, $session_id);
@ -3326,6 +3324,7 @@ class DocumentManager
* @param int $folderId * @param int $folderId
* @param bool $addCloseButton * @param bool $addCloseButton
* @param bool $addAudioPreview * @param bool $addAudioPreview
* @param array $filterByExtension
* *
* @return string * @return string
*/ */
@ -3341,7 +3340,8 @@ class DocumentManager
$showOnlyFolders = false, $showOnlyFolders = false,
$folderId = false, $folderId = false,
$addCloseButton = true, $addCloseButton = true,
$addAudioPreview = false $addAudioPreview = false,
$filterByExtension = []
) { ) {
if (empty($course_info['real_id']) || empty($course_info['code']) || !is_array($course_info)) { if (empty($course_info['real_id']) || empty($course_info['code']) || !is_array($course_info)) {
return ''; return '';
@ -3406,6 +3406,17 @@ class DocumentManager
} }
} }
$extensionConditionToString = '';
if (!empty($filterByExtension)) {
$extensionCondition = [];
foreach ($filterByExtension as $extension) {
$extensionCondition[] = " docs.path LIKE '%.$extension' ";
}
if (!empty($extensionCondition)) {
$extensionConditionToString .= " AND (".implode('OR', $extensionCondition).") ";
}
}
$parentData = []; $parentData = [];
if ($folderId !== false) { if ($folderId !== false) {
$parentData = self::get_document_data_by_id( $parentData = self::get_document_data_by_id(
@ -3453,6 +3464,7 @@ class DocumentManager
last.c_id = {$course_info['real_id']} last.c_id = {$course_info['real_id']}
$folderCondition $folderCondition
$levelCondition $levelCondition
$extensionConditionToString
$add_folder_filter $add_folder_filter
ORDER BY docs.filetype DESC, docs.title ASC"; ORDER BY docs.filetype DESC, docs.title ASC";

@ -54,6 +54,7 @@ class learnpath
public $error = ''; public $error = '';
public $force_commit = false; // For SCORM only- if true will send a scorm LMSCommit() request on each LMSSetValue() public $force_commit = false; // For SCORM only- if true will send a scorm LMSCommit() request on each LMSSetValue()
public $index; // The index of the active learnpath_item in $ordered_items array. public $index; // The index of the active learnpath_item in $ordered_items array.
/** @var learnpathItem[] */
public $items = []; public $items = [];
public $last; // item_id of last item viewed in the learning path. public $last; // item_id of last item viewed in the learning path.
public $last_item_seen = 0; // In case we have already come in this lp, reuse the last item seen if authorized. public $last_item_seen = 0; // In case we have already come in this lp, reuse the last item seen if authorized.
@ -2103,23 +2104,24 @@ class learnpath
public function get_mediaplayer($lpItemId, $autostart = 'true') public function get_mediaplayer($lpItemId, $autostart = 'true')
{ {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$_course = api_get_course_info(); $courseInfo = api_get_course_info();
if (empty($_course)) { $lpItemId = (int) $lpItemId;
if (empty($courseInfo) || empty($lpItemId)) {
return '';
}
$item = isset($this->items[$lpItemId]) ? $this->items[$lpItemId] : null;
if (empty($item)) {
return ''; return '';
} }
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); $tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$lpItemId = (int) $lpItemId;
/** @var learnpathItem $item */
$item = isset($this->items[$lpItemId]) ? $this->items[$lpItemId] : null;
$itemViewId = 0;
if ($item) {
$itemViewId = (int) $item->db_item_view_id; $itemViewId = (int) $item->db_item_view_id;
}
// Getting all the information about the item. // Getting all the information about the item.
$sql = "SELECT lpi.audio, lpi.item_type, lp_view.status $sql = "SELECT lp_view.status
FROM $tbl_lp_item as lpi FROM $tbl_lp_item as lpi
INNER JOIN $tbl_lp_item_view as lp_view INNER JOIN $tbl_lp_item_view as lp_view
ON (lpi.iid = lp_view.lp_item_id) ON (lpi.iid = lp_view.lp_item_id)
@ -2130,11 +2132,12 @@ class learnpath
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_assoc($result); $row = Database::fetch_assoc($result);
$output = ''; $output = '';
$audio = $item->audio;
if (!empty($row['audio'])) { if (!empty($audio)) {
$list = $_SESSION['oLP']->get_toc(); $list = $_SESSION['oLP']->get_toc();
switch ($row['item_type']) { switch ($item->get_type()) {
case 'quiz': case 'quiz':
$type_quiz = false; $type_quiz = false;
foreach ($list as $toc) { foreach ($list as $toc) {
@ -2151,24 +2154,15 @@ class learnpath
} }
} }
break; break;
case TOOL_READOUT_TEXT:; case TOOL_READOUT_TEXT:
$autostart_audio = 'false'; $autostart_audio = 'false';
break; break;
default: default:
$autostart_audio = 'true'; $autostart_audio = 'true';
} }
$courseInfo = api_get_course_info(); $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$audio;
$audio = $row['audio']; $url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$audio.'?'.api_get_cidreq();
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio;
$url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio.'?'.api_get_cidreq();
if (!file_exists($file)) {
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
$url = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio.'?'.api_get_cidreq();
}
$player = Display::getMediaPlayer( $player = Display::getMediaPlayer(
$file, $file,
@ -8237,15 +8231,25 @@ class learnpath
$item_description = ''; $item_description = '';
$item_path_fck = ''; $item_path_fck = '';
$parent = 0;
$previousId = null;
if ($id != 0 && is_array($extra_info)) { if ($id != 0 && is_array($extra_info)) {
$item_title = $extra_info['title']; $item_title = $extra_info['title'];
$item_description = $extra_info['description']; $item_description = $extra_info['description'];
$item_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']); $item_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
$item_path_fck = '/scorm/'.$this->path.'/'.stripslashes($extra_info['path']); $item_path_fck = '/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
}
$parent = 0;
if ($id != 0 && is_array($extra_info)) {
$parent = $extra_info['parent_item_id']; $parent = $extra_info['parent_item_id'];
$previousId = $extra_info['previous_item_id'];
}
if ($extra_info instanceOf learnpathItem) {
$item_title = $extra_info->get_title();
$item_description = $extra_info->get_description();
$path = $extra_info->get_path();
$item_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/scorm/'.$this->path.'/'.stripslashes($path);
$item_path_fck = '/scorm/'.$this->path.'/'.stripslashes($path);
$parent = $extra_info->get_parent();
$previousId = $extra_info->previous;
} }
$id = (int) $id; $id = (int) $id;
@ -8254,7 +8258,7 @@ class learnpath
lp_id = ".$this->lp_id." AND lp_id = ".$this->lp_id." AND
iid != $id"; iid != $id";
if ($item_type == 'dir') { if ($item_type === 'dir') {
$sql .= " AND parent_item_id = 0"; $sql .= " AND parent_item_id = 0";
} }
@ -8319,7 +8323,7 @@ class learnpath
} }
} }
if ($action != 'move') { if ($action !== 'move') {
$this->setItemTitle($form); $this->setItemTitle($form);
} else { } else {
$form->addElement('hidden', 'title'); $form->addElement('hidden', 'title');
@ -8359,11 +8363,9 @@ class learnpath
if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id && if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id &&
$arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) { $arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) {
//this is the same! //this is the same!
if (isset($extra_info['previous_item_id']) && if (isset($previousId) && $previousId == $arrLP[$i]['id']) {
$extra_info['previous_item_id'] == $arrLP[$i]['id']
) {
$s_selected_position = $arrLP[$i]['id']; $s_selected_position = $arrLP[$i]['id'];
} elseif ($action == 'add') { } elseif ($action === 'add') {
$s_selected_position = $arrLP[$i]['id']; $s_selected_position = $arrLP[$i]['id'];
} }
@ -8414,8 +8416,8 @@ class learnpath
//assets can't be modified //assets can't be modified
//$item_type == 'asset' || //$item_type == 'asset' ||
if (($item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) { if (($item_type === 'sco') && ($extension === 'html' || $extension === 'htm')) {
if ($item_type == 'sco') { if ($item_type === 'sco') {
$form->addElement( $form->addElement(
'html', 'html',
'<script>alert("'.get_lang('WarningWhenEditingScorm').'")</script>' '<script>alert("'.get_lang('WarningWhenEditingScorm').'")</script>'
@ -9612,7 +9614,7 @@ class learnpath
/** /**
* Displays the menu for manipulating a step. * Displays the menu for manipulating a step.
* *
* @param id $item_id * @param int $item_id
* @param string $item_type * @param string $item_type
* *
* @return string * @return string
@ -9633,11 +9635,11 @@ class learnpath
$audio_player = null; $audio_player = null;
// We display an audio player if needed. // We display an audio player if needed.
if (!empty($row['audio'])) { if (!empty($row['audio'])) {
$webAudioPath = '../..'.api_get_path(REL_COURSE_PATH).$_course['path'].'/document/audio/'.$row['audio']; $audio = learnpathItem::fixAudio($row['audio']);
$webAudioPath = '../..'.api_get_path(REL_COURSE_PATH).$_course['path'].'/document'.$audio;
$audio_player .= '<div class="lp_mediaplayer" id="container">' $audio_player .= '<div class="lp_mediaplayer" id="container">
.'<audio src="'.$webAudioPath.'" controls>' <audio src="'.$webAudioPath.'" controls>
.'</div><br>'; </div><br />';
} }
$url = api_get_self().'?'.api_get_cidreq().'&view=build&id='.$item_id.'&lp_id='.$this->lp_id; $url = api_get_self().'?'.api_get_cidreq().'&view=build&id='.$item_id.'&lp_id='.$this->lp_id;
@ -9804,64 +9806,59 @@ class learnpath
/** /**
* Display the form to allow moving an item. * Display the form to allow moving an item.
* *
* @param int $item_id Item ID * @param learnpathItem $item Item ID
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error * @throws HTML_QuickForm_Error
* *
* @return string HTML form * @return string HTML form
*/ */
public function display_move_item($item_id) public function display_move_item($item)
{ {
$return = ''; $return = '';
if (is_numeric($item_id)) { if ($item) {
$item_id = (int) $item_id; $item_id = $item->getIid();
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $type = $item->get_type();
$sql = "SELECT * FROM $tbl_lp_item
WHERE iid = $item_id";
$res = Database::query($sql);
$row = Database::fetch_array($res);
switch ($row['item_type']) { switch ($type) {
case 'dir': case 'dir':
case 'asset': case 'asset':
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_item_form( $return .= $this->display_item_form(
$row['item_type'], $type,
get_lang('MoveCurrentChapter'), get_lang('MoveCurrentChapter'),
'move', 'move',
$item_id, $item_id,
$row $item
); );
break; break;
case TOOL_DOCUMENT: case TOOL_DOCUMENT:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_document_form('move', $item_id, $row); $return .= $this->display_document_form('move', $item_id, $item);
break; break;
case TOOL_LINK: case TOOL_LINK:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_link_form('move', $item_id, $row); $return .= $this->display_link_form('move', $item_id, $item);
break; break;
case TOOL_HOTPOTATOES: case TOOL_HOTPOTATOES:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_link_form('move', $item_id, $row); $return .= $this->display_link_form('move', $item_id, $item);
break; break;
case TOOL_QUIZ: case TOOL_QUIZ:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_quiz_form('move', $item_id, $row); $return .= $this->display_quiz_form('move', $item_id, $item);
break; break;
case TOOL_STUDENTPUBLICATION: case TOOL_STUDENTPUBLICATION:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_student_publication_form('move', $item_id, $row); $return .= $this->display_student_publication_form('move', $item_id, $item);
break; break;
case TOOL_FORUM: case TOOL_FORUM:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_forum_form('move', $item_id, $row); $return .= $this->display_forum_form('move', $item_id, $item);
break; break;
case TOOL_THREAD: case TOOL_THREAD:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_forum_form('move', $item_id, $row); $return .= $this->display_forum_form('move', $item_id, $item);
break; break;
} }
} }

@ -79,6 +79,8 @@ class learnpathItem
private $last_scorm_session_time = 0; private $last_scorm_session_time = 0;
private $prerequisiteMaxScore; private $prerequisiteMaxScore;
private $prerequisiteMinScore; private $prerequisiteMinScore;
public $courseInfo;
public $courseId;
/** /**
* Prepares the learning path item for later launch. * Prepares the learning path item for later launch.
@ -87,23 +89,21 @@ class learnpathItem
* *
* @param int $id Learning path item ID * @param int $id Learning path item ID
* @param int $user_id User ID * @param int $user_id User ID
* @param int $course_id Course int id * @param int $courseId Course int id
* @param array|null $item_content An array with the contents of the item * @param array|null $item_content An array with the contents of the item
*/ */
public function __construct( public function __construct(
$id, $id,
$user_id = 0, $user_id = 0,
$course_id = 0, $courseId = 0,
$item_content = null $item_content = null
) { ) {
$items_table = Database::get_course_table(TABLE_LP_ITEM); $items_table = Database::get_course_table(TABLE_LP_ITEM);
$id = (int) $id; $id = (int) $id;
$this->courseId = $courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId;
$this->courseInfo = api_get_course_info_by_id($this->courseId);
if (empty($item_content)) { if (empty($item_content)) {
if (empty($course_id)) {
$course_id = api_get_course_int_id();
} else {
$course_id = (int) $course_id;
}
$sql = "SELECT * FROM $items_table $sql = "SELECT * FROM $items_table
WHERE iid = $id"; WHERE iid = $id";
$res = Database::query($sql); $res = Database::query($sql);
@ -136,10 +136,9 @@ class learnpathItem
$this->setPrerequisiteMinScore($row['prerequisite_min_score']); $this->setPrerequisiteMinScore($row['prerequisite_min_score']);
$this->oldTotalTime = 0; $this->oldTotalTime = 0;
$this->view_max_score = 0; $this->view_max_score = 0;
$this->seriousgame_mode = 0;
if (isset($row['launch_data'])) { $this->audio = self::fixAudio($row['audio']);
$this->launch_data = $row['launch_data']; $this->launch_data = $row['launch_data'];
}
$this->save_on_close = true; $this->save_on_close = true;
$this->db_id = $id; $this->db_id = $id;
@ -147,7 +146,7 @@ class learnpathItem
if (!empty($this->lp_id)) { if (!empty($this->lp_id)) {
$sql = "SELECT iid FROM $items_table $sql = "SELECT iid FROM $items_table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_id = ".$this->lp_id." AND lp_id = ".$this->lp_id." AND
parent_item_id = $id"; parent_item_id = $id";
$res = Database::query($sql); $res = Database::query($sql);
@ -158,7 +157,7 @@ class learnpathItem
} }
// Get search_did. // Get search_did.
if (api_get_setting('search_enabled') === 'true') { if ('true' === api_get_setting('search_enabled')) {
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'SELECT * $sql = 'SELECT *
FROM %s FROM %s
@ -185,32 +184,33 @@ class learnpathItem
} }
} }
} }
$this->seriousgame_mode = 0;
$this->audio = null;
if (isset($row['audio'])) {
// Fix old audio format /file.wav to /audio/file.wav
$parts = explode('/', $row['audio']);
$parts = array_filter($parts);
if (count($parts) === 1) {
$row['audio'] = '/audio'.$row['audio'];
} }
$this->audio = $row['audio'];
public static function fixAudio($audio)
{
$courseInfo = api_get_course_info();
if (empty($audio) || empty($courseInfo)) {
return '';
} }
// Old structure
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio;
if (file_exists($file)) {
$audio = '/audio/'.$audio;
$audio = str_replace('//', '/', $audio);
return $audio;
} }
/** $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$audio;
* Adds a child to the current item.
* if (file_exists($file)) {
* @param int $item The child item ID
*/ return $audio;
public function add_child($item)
{
if (!empty($item)) {
// Do not check in DB as we expect the call to come from the
// learnpath class which should be aware of any fake.
$this->children[] = $item;
} }
return '';
} }
/** /**
@ -261,7 +261,7 @@ class learnpathItem
} }
$this->current_stop_time = time(); $this->current_stop_time = time();
$type = $this->get_type(); $type = $this->get_type();
if ($type != 'sco') { if ($type !== 'sco') {
if ($type == TOOL_QUIZ || $type == TOOL_HOTPOTATOES) { if ($type == TOOL_QUIZ || $type == TOOL_HOTPOTATOES) {
$this->get_status( $this->get_status(
true, true,
@ -287,10 +287,10 @@ class learnpathItem
{ {
$lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$lp_item = Database::get_course_table(TABLE_LP_ITEM); $lp_item = Database::get_course_table(TABLE_LP_ITEM);
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
$sql = "DELETE FROM $lp_item_view $sql = "DELETE FROM $lp_item_view
WHERE c_id = $course_id AND lp_item_id = ".$this->db_id; WHERE c_id = $courseId AND lp_item_id = ".$this->db_id;
Database::query($sql); Database::query($sql);
$sql = "SELECT * FROM $lp_item $sql = "SELECT * FROM $lp_item
@ -314,22 +314,6 @@ class learnpathItem
return true; return true;
} }
/**
* Drops a child from the children array.
*
* @param string $item index of child item to drop
*/
public function drop_child($item)
{
if (!empty($item)) {
foreach ($this->children as $index => $child) {
if ($child == $item) {
$this->children[$index] = null;
}
}
}
}
/** /**
* Gets the current attempt_id for this user on this item. * Gets the current attempt_id for this user on this item.
* *
@ -455,12 +439,12 @@ class learnpathItem
*/ */
public function get_file_path($path_to_scorm_dir = '') public function get_file_path($path_to_scorm_dir = '')
{ {
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
$path = $this->get_path(); $path = $this->get_path();
$type = $this->get_type(); $type = $this->get_type();
if (empty($path)) { if (empty($path)) {
if ($type == 'dir') { if ($type === 'dir') {
return ''; return '';
} else { } else {
return '-1'; return '-1';
@ -475,7 +459,7 @@ class learnpathItem
$sql = 'SELECT path $sql = 'SELECT path
FROM '.$table_doc.' FROM '.$table_doc.'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$courseId.' AND
iid = '.$path; iid = '.$path;
$res = Database::query($sql); $res = Database::query($sql);
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
@ -521,11 +505,11 @@ class learnpathItem
public function load_interactions() public function load_interactions()
{ {
$this->interactions = []; $this->interactions = [];
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT id FROM $tbl $sql = "SELECT id FROM $tbl
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = ".$this->db_id." AND lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_view_count(); view_count = ".$this->get_view_count();
@ -535,7 +519,7 @@ class learnpathItem
$lp_iv_id = $row[0]; $lp_iv_id = $row[0];
$iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION); $iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
$sql = "SELECT * FROM $iva_table $sql = "SELECT * FROM $iva_table
WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id "; WHERE c_id = $courseId AND lp_iv_id = $lp_iv_id ";
$res_sql = Database::query($sql); $res_sql = Database::query($sql);
while ($row = Database::fetch_array($res_sql)) { while ($row = Database::fetch_array($res_sql)) {
$this->interactions[$row['interaction_id']] = [ $this->interactions[$row['interaction_id']] = [
@ -566,13 +550,13 @@ class learnpathItem
// If the user is an invitee, we consider there's no interaction // If the user is an invitee, we consider there's no interaction
return 0; return 0;
} }
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
if ($checkdb) { if ($checkdb) {
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT iid FROM $tbl $sql = "SELECT iid FROM $tbl
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = ".$this->db_id." AND lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id(); view_count = ".$this->get_attempt_id();
@ -585,7 +569,7 @@ class learnpathItem
); );
$sql = "SELECT count(id) as mycount $sql = "SELECT count(id) as mycount
FROM $iva_table FROM $iva_table
WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id "; WHERE c_id = $courseId AND lp_iv_id = $lp_iv_id ";
$res_sql = Database::query($sql); $res_sql = Database::query($sql);
if (Database::num_rows($res_sql) > 0) { if (Database::num_rows($res_sql) > 0) {
$row = Database::fetch_array($res_sql); $row = Database::fetch_array($res_sql);
@ -1481,7 +1465,7 @@ class learnpathItem
*/ */
public function get_status($check_db = true, $update_local = false) public function get_status($check_db = true, $update_local = false)
{ {
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
$debug = self::DEBUG; $debug = self::DEBUG;
if ($debug > 0) { if ($debug > 0) {
error_log('learnpathItem::get_status() on item '.$this->db_id, 0); error_log('learnpathItem::get_status() on item '.$this->db_id, 0);
@ -1490,11 +1474,11 @@ class learnpathItem
if ($debug > 2) { if ($debug > 2) {
error_log('learnpathItem::get_status(): checking db', 0); error_log('learnpathItem::get_status(): checking db', 0);
} }
if (!empty($this->db_item_view_id) && !empty($course_id)) { if (!empty($this->db_item_view_id) && !empty($courseId)) {
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT status FROM $table $sql = "SELECT status FROM $table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
iid = '".$this->db_item_view_id."' AND iid = '".$this->db_item_view_id."' AND
view_count = '".$this->get_attempt_id()."'"; view_count = '".$this->get_attempt_id()."'";
$res = Database::query($sql); $res = Database::query($sql);
@ -1572,7 +1556,7 @@ class learnpathItem
$query_db = false $query_db = false
) { ) {
$time = null; $time = null;
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
if (!isset($given_time)) { if (!isset($given_time)) {
if (self::DEBUG > 2) { if (self::DEBUG > 2) {
error_log( error_log(
@ -1585,7 +1569,7 @@ class learnpathItem
$sql = "SELECT start_time, total_time $sql = "SELECT start_time, total_time
FROM $table FROM $table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
iid = '".$this->db_item_view_id."' AND iid = '".$this->db_item_view_id."' AND
view_count = '".$this->get_attempt_id()."'"; view_count = '".$this->get_attempt_id()."'";
$res = Database::query($sql); $res = Database::query($sql);
@ -1972,7 +1956,7 @@ class learnpathItem
); );
} }
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
// Deal with &, |, ~, =, <>, {}, ,, X*, () in reverse order. // Deal with &, |, ~, =, <>, {}, ,, X*, () in reverse order.
@ -2347,7 +2331,7 @@ class learnpathItem
orig_lp_id = '.$this->lp_id.' AND orig_lp_id = '.$this->lp_id.' AND
orig_lp_item_id = '.$prereqs_string.' AND orig_lp_item_id = '.$prereqs_string.' AND
status <> "incomplete" AND status <> "incomplete" AND
c_id = '.$course_id.' c_id = '.$courseId.'
ORDER BY exe_date DESC ORDER BY exe_date DESC
LIMIT 0, 1'; LIMIT 0, 1';
$rs_quiz = Database::query($sql); $rs_quiz = Database::query($sql);
@ -2397,7 +2381,7 @@ class learnpathItem
$sql = 'SELECT exe_result, exe_weighting $sql = 'SELECT exe_result, exe_weighting
FROM '.Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES).' FROM '.Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES).'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$courseId.' AND
exe_exo_id = '.$items[$refs_list[$prereqs_string]]->path.' AND exe_exo_id = '.$items[$refs_list[$prereqs_string]]->path.' AND
exe_user_id = '.$user_id.' AND exe_user_id = '.$user_id.' AND
orig_lp_id = '.$this->lp_id.' AND orig_lp_id = '.$this->lp_id.' AND
@ -2505,7 +2489,7 @@ class learnpathItem
if ($returnstatus && $this->prevent_reinit == 1) { if ($returnstatus && $this->prevent_reinit == 1) {
$sql = "SELECT iid FROM $lp_view $sql = "SELECT iid FROM $lp_view
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
user_id = $user_id AND user_id = $user_id AND
lp_id = $this->lp_id AND lp_id = $this->lp_id AND
session_id = $sessionId session_id = $sessionId
@ -2517,7 +2501,7 @@ class learnpathItem
$sql = "SELECT status FROM $lp_item_view $sql = "SELECT status FROM $lp_item_view
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_view_id = $my_lp_id AND lp_view_id = $my_lp_id AND
lp_item_id = $refs_list[$prereqs_string] lp_item_id = $refs_list[$prereqs_string]
LIMIT 0, 1"; LIMIT 0, 1";
@ -2934,19 +2918,19 @@ class learnpathItem
* Sets the lp_view id this item view is registered to. * Sets the lp_view id this item view is registered to.
* *
* @param int $lp_view_id lp_view DB ID * @param int $lp_view_id lp_view DB ID
* @param int $course_id * @param int $courseId
* *
* @return bool * @return bool
* *
* @todo //todo insert into lp_item_view if lp_view not exists * @todo //todo insert into lp_item_view if lp_view not exists
*/ */
public function set_lp_view($lp_view_id, $course_id = null) public function set_lp_view($lp_view_id, $courseId = null)
{ {
$lp_view_id = (int) $lp_view_id; $lp_view_id = (int) $lp_view_id;
$course_id = (int) $course_id; $courseId = (int) $courseId;
if (empty($course_id)) { if (empty($courseId)) {
$course_id = api_get_course_int_id(); $courseId = api_get_course_int_id();
} }
$lpItemId = $this->get_id(); $lpItemId = $this->get_id();
@ -2969,7 +2953,7 @@ class learnpathItem
// Get the lp_item_view with the highest view_count. // Get the lp_item_view with the highest view_count.
$sql = "SELECT * FROM $item_view_table $sql = "SELECT * FROM $item_view_table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = $lpItemId AND lp_item_id = $lpItemId AND
lp_view_id = $lp_view_id lp_view_id = $lp_view_id
ORDER BY view_count DESC"; ORDER BY view_count DESC";
@ -3005,7 +2989,7 @@ class learnpathItem
$table = Database::get_course_table(TABLE_LP_IV_INTERACTION); $table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_iv_id = '".$this->db_item_view_id."'"; lp_iv_id = '".$this->db_item_view_id."'";
$res = Database::query($sql); $res = Database::query($sql);
@ -3018,7 +3002,7 @@ class learnpathItem
$table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE); $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_iv_id = '".$this->db_item_view_id."'"; lp_iv_id = '".$this->db_item_view_id."'";
$this->objectives_count = 0; $this->objectives_count = 0;
@ -3385,12 +3369,12 @@ class learnpathItem
// Step 1 : get actual total time stored in db // Step 1 : get actual total time stored in db
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$course_id = api_get_course_int_id(); $courseId = $this->courseId;
$sql = 'SELECT total_time, status $sql = 'SELECT total_time, status
FROM '.$item_view_table.' FROM '.$item_view_table.'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$courseId.' AND
lp_item_id = "'.$this->db_id.'" AND lp_item_id = "'.$this->db_id.'" AND
lp_view_id = "'.$this->view_id.'" AND lp_view_id = "'.$this->view_id.'" AND
view_count = "'.$this->get_attempt_id().'"'; view_count = "'.$this->get_attempt_id().'"';
@ -3459,7 +3443,7 @@ class learnpathItem
$sql = "UPDATE $item_view_table $sql = "UPDATE $item_view_table
SET total_time = '$total_time' SET total_time = '$total_time'
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = {$this->db_id} AND lp_item_id = {$this->db_id} AND
lp_view_id = {$this->view_id} AND lp_view_id = {$this->view_id} AND
view_count = {$this->get_attempt_id()}"; view_count = {$this->get_attempt_id()}";
@ -3472,24 +3456,6 @@ class learnpathItem
} }
} }
/**
* Set the total_time to 0 into db.
*/
public function scorm_init_time()
{
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$course_id = api_get_course_int_id();
$sql = 'UPDATE '.$table.'
SET total_time = 0,
start_time = '.time().'
WHERE
c_id = '.$course_id.' AND
lp_item_id = "'.$this->db_id.'" AND
lp_view_id = "'.$this->view_id.'" AND
view_count = "'.$this->attempt_id.'"';
Database::query($sql);
}
/** /**
* Write objectives to DB. This method is separate from write_to_db() because otherwise * Write objectives to DB. This method is separate from write_to_db() because otherwise
* objectives are lost as a side effect to AJAX and session concurrent access. * objectives are lost as a side effect to AJAX and session concurrent access.
@ -3505,14 +3471,14 @@ class learnpathItem
// If the user is an invitee, we don't write anything to DB // If the user is an invitee, we don't write anything to DB
return true; return true;
} }
$course_id = api_get_course_int_id(); $courseId = api_get_course_int_id();
if (is_array($this->objectives) && count($this->objectives) > 0) { if (is_array($this->objectives) && count($this->objectives) > 0) {
// Save objectives. // Save objectives.
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT iid $sql = "SELECT iid
FROM $tbl FROM $tbl
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = ".$this->db_id." AND lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND lp_view_id = ".$this->view_id." AND
view_count = ".$this->attempt_id; view_count = ".$this->attempt_id;
@ -3533,7 +3499,7 @@ class learnpathItem
); );
$iva_sql = "SELECT iid FROM $iva_table $iva_sql = "SELECT iid FROM $iva_table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_iv_id = $lp_iv_id AND lp_iv_id = $lp_iv_id AND
objective_id = '".Database::escape_string($objective[0])."'"; objective_id = '".Database::escape_string($objective[0])."'";
$iva_res = Database::query($iva_sql); $iva_res = Database::query($iva_sql);
@ -3550,12 +3516,12 @@ class learnpathItem
"score_raw = '".Database::escape_string($objective[2])."',". "score_raw = '".Database::escape_string($objective[2])."',".
"score_min = '".Database::escape_string($objective[4])."',". "score_min = '".Database::escape_string($objective[4])."',".
"score_max = '".Database::escape_string($objective[3])."' ". "score_max = '".Database::escape_string($objective[3])."' ".
"WHERE c_id = $course_id AND iid = $iva_id"; "WHERE c_id = $courseId AND iid = $iva_id";
Database::query($ivau_sql); Database::query($ivau_sql);
} else { } else {
// Insert new one. // Insert new one.
$params = [ $params = [
'c_id' => $course_id, 'c_id' => $courseId,
'lp_iv_id' => $lp_iv_id, 'lp_iv_id' => $lp_iv_id,
'order_id' => $index, 'order_id' => $index,
'objective_id' => $objective[0], 'objective_id' => $objective[0],
@ -3602,16 +3568,17 @@ class learnpathItem
return true; return true;
} }
$course_id = api_get_course_int_id(); $courseId = api_get_course_int_id();
$mode = $this->get_lesson_mode(); $mode = $this->get_lesson_mode();
$credit = $this->get_credit(); $credit = $this->get_credit();
$total_time = ' '; $total_time = ' ';
$my_status = ' '; $my_status = ' ';
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = 'SELECT status, total_time FROM '.$item_view_table.' $sql = 'SELECT status, total_time
FROM '.$item_view_table.'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$courseId.' AND
lp_item_id="'.$this->db_id.'" AND lp_item_id="'.$this->db_id.'" AND
lp_view_id="'.$this->view_id.'" AND lp_view_id="'.$this->view_id.'" AND
view_count="'.$this->get_attempt_id().'" '; view_count="'.$this->get_attempt_id().'" ';
@ -3635,9 +3602,9 @@ class learnpathItem
} }
} }
if ((($save === false && $this->type == 'sco') || if ((($save === false && $this->type === 'sco') ||
($this->type == 'sco' && ($credit == 'no-credit' || $mode == 'review' || $mode == 'browse'))) && ($this->type === 'sco' && ($credit === 'no-credit' || $mode === 'review' || $mode === 'browse'))) &&
($this->seriousgame_mode != 1 && $this->type == 'sco') ($this->seriousgame_mode != 1 && $this->type === 'sco')
) { ) {
if ($debug) { if ($debug) {
error_log( error_log(
@ -3653,14 +3620,14 @@ class learnpathItem
// Check the row exists. // Check the row exists.
$inserted = false; $inserted = false;
// This a special case for multiple attempts and Chamilo exercises. // This a special case for multiple attempts and Chamilo exercises.
if ($this->type == 'quiz' && if ($this->type === 'quiz' &&
$this->get_prevent_reinit() == 0 && $this->get_prevent_reinit() == 0 &&
$this->get_status() == 'completed' $this->get_status() === 'completed'
) { ) {
// We force the item to be restarted. // We force the item to be restarted.
$this->restart(); $this->restart();
$params = [ $params = [
"c_id" => $course_id, "c_id" => $courseId,
"total_time" => $this->get_total_time(), "total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time, "start_time" => $this->current_start_time,
"score" => $this->get_score(), "score" => $this->get_score(),
@ -3691,7 +3658,7 @@ class learnpathItem
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT * FROM $item_view_table $sql = "SELECT * FROM $item_view_table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = ".$this->db_id." AND lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id(); view_count = ".$this->get_attempt_id();
@ -3707,7 +3674,7 @@ class learnpathItem
// now save into DB. // now save into DB.
if (!$inserted && Database::num_rows($check_res) < 1) { if (!$inserted && Database::num_rows($check_res) < 1) {
$params = [ $params = [
"c_id" => $course_id, "c_id" => $courseId,
"total_time" => $this->get_total_time(), "total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time, "start_time" => $this->current_start_time,
"score" => $this->get_score(), "score" => $this->get_score(),
@ -3747,7 +3714,7 @@ class learnpathItem
]; ];
$where = [ $where = [
'c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' => [ 'c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' => [
$course_id, $courseId,
$this->db_id, $this->db_id,
$this->view_id, $this->view_id,
$this->get_attempt_id(), $this->get_attempt_id(),
@ -3756,7 +3723,7 @@ class learnpathItem
Database::update($item_view_table, $params, $where); Database::update($item_view_table, $params, $where);
} else { } else {
// For all other content types... // For all other content types...
if ($this->type == 'quiz') { if ($this->type === 'quiz') {
if ($debug) { if ($debug) {
error_log("item is quiz:"); error_log("item is quiz:");
} }
@ -3768,9 +3735,6 @@ class learnpathItem
$sql = "SELECT exe_duration $sql = "SELECT exe_duration
FROM $table FROM $table
WHERE exe_id = $exeId"; WHERE exe_id = $exeId";
if ($debug) {
error_log($sql);
}
$res = Database::query($sql); $res = Database::query($sql);
$exeRow = Database::fetch_array($res); $exeRow = Database::fetch_array($res);
$duration = $exeRow['exe_duration']; $duration = $exeRow['exe_duration'];
@ -3790,17 +3754,14 @@ class learnpathItem
]; ];
// Is not multiple attempts // Is not multiple attempts
if ($this->seriousgame_mode == 1 && $this->type == 'sco') { if ($this->seriousgame_mode == 1 && $this->type === 'sco') {
$total_time = " total_time = total_time +".$this->get_total_time().", "; $total_time = " total_time = total_time +".$this->get_total_time().", ";
$my_status = " status = '".$this->get_status(false)."' ,"; $my_status = " status = '".$this->get_status(false)."' ,";
if ($debug) {
error_log("seriousgame_mode time changed: $total_time");
}
} elseif ($this->get_prevent_reinit() == 1) { } elseif ($this->get_prevent_reinit() == 1) {
// Process of status verified into data base. // Process of status verified into data base.
$sql = 'SELECT status FROM '.$item_view_table.' $sql = 'SELECT status FROM '.$item_view_table.'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$courseId.' AND
lp_item_id="'.$this->db_id.'" AND lp_item_id="'.$this->db_id.'" AND
lp_view_id="'.$this->view_id.'" AND lp_view_id="'.$this->view_id.'" AND
view_count="'.$this->get_attempt_id().'" view_count="'.$this->get_attempt_id().'"
@ -3876,16 +3837,12 @@ class learnpathItem
// Verify current status in multiples attempts. // Verify current status in multiples attempts.
$sql = 'SELECT status FROM '.$item_view_table.' $sql = 'SELECT status FROM '.$item_view_table.'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$courseId.' AND
lp_item_id="'.$this->db_id.'" AND lp_item_id="'.$this->db_id.'" AND
lp_view_id="'.$this->view_id.'" AND lp_view_id="'.$this->view_id.'" AND
view_count="'.$this->get_attempt_id().'" '; view_count="'.$this->get_attempt_id().'" ';
$rs_status = Database::query($sql); $rs_status = Database::query($sql);
$current_status = Database::result( $current_status = Database::result($rs_status, 0, 'status');
$rs_status,
0,
'status'
);
if (in_array($current_status, $case_completed)) { if (in_array($current_status, $case_completed)) {
$my_status = ''; $my_status = '';
$total_time = ''; $total_time = '';
@ -3900,7 +3857,7 @@ class learnpathItem
} }
} }
if ($this->type == 'sco') { if ($this->type === 'sco') {
//IF scorm scorm_update_time has already updated total_time in db //IF scorm scorm_update_time has already updated total_time in db
//" . //start_time = ".$this->get_current_start_time().", " . //scorm_init_time does it //" . //start_time = ".$this->get_current_start_time().", " . //scorm_init_time does it
////" max_time_allowed = '".$this->get_max_time_allowed()."'," . ////" max_time_allowed = '".$this->get_max_time_allowed()."'," .
@ -3911,7 +3868,7 @@ class learnpathItem
suspend_data = '".Database::escape_string($this->current_data)."', suspend_data = '".Database::escape_string($this->current_data)."',
lesson_location = '".$this->lesson_location."' lesson_location = '".$this->lesson_location."'
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = ".$this->db_id." AND lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id(); view_count = ".$this->get_attempt_id();
@ -3926,7 +3883,7 @@ class learnpathItem
suspend_data = '".Database::escape_string($this->current_data)."', suspend_data = '".Database::escape_string($this->current_data)."',
lesson_location = '".$this->lesson_location."' lesson_location = '".$this->lesson_location."'
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = ".$this->db_id." AND lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id(); view_count = ".$this->get_attempt_id();
@ -3949,7 +3906,7 @@ class learnpathItem
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT iid FROM $tbl $sql = "SELECT iid FROM $tbl
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_item_id = ".$this->db_id." AND lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id(); view_count = ".$this->get_attempt_id();
@ -3983,7 +3940,7 @@ class learnpathItem
//also check for the interaction ID as it must be unique for this SCO view //also check for the interaction ID as it must be unique for this SCO view
$iva_sql = "SELECT iid FROM $iva_table $iva_sql = "SELECT iid FROM $iva_table
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_iv_id = $lp_iv_id AND lp_iv_id = $lp_iv_id AND
( (
order_id = $index OR order_id = $index OR
@ -4022,7 +3979,7 @@ class learnpathItem
$params, $params,
[ [
'c_id = ? AND iid = ?' => [ 'c_id = ? AND iid = ?' => [
$course_id, $courseId,
$iva_id, $iva_id,
], ],
] ]
@ -4030,7 +3987,7 @@ class learnpathItem
} else { } else {
// Insert new one. // Insert new one.
$params = [ $params = [
'c_id' => $course_id, 'c_id' => $courseId,
'order_id' => $index, 'order_id' => $index,
'lp_iv_id' => $lp_iv_id, 'lp_iv_id' => $lp_iv_id,
'interaction_id' => $interaction[0], 'interaction_id' => $interaction[0],
@ -4067,7 +4024,7 @@ class learnpathItem
* *
* @return bool|string|null * @return bool|string|null
*/ */
public function add_audio() public function addAudio()
{ {
$course_info = api_get_course_info(); $course_info = api_get_course_info();
$filepath = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/'; $filepath = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/';
@ -4140,32 +4097,6 @@ class learnpathItem
return $file_path; return $file_path;
} }
/**
* Adds an audio file to the current item, using a file already in documents.
*
* @param int $documentId
*
* @return string
*/
public function add_audio_from_documents($documentId)
{
$courseInfo = api_get_course_info();
$documentData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
$path = '';
if (!empty($documentData)) {
$path = $documentData['path'];
// Store the mp3 file in the lp_item table.
$table = Database::get_course_table(TABLE_LP_ITEM);
$sql = "UPDATE $table SET
audio = '".Database::escape_string($path)."'
WHERE iid = ".$this->db_id;
Database::query($sql);
}
return $path;
}
/** /**
* Removes the relation between the current item and an audio file. The file * Removes the relation between the current item and an audio file. The file
* is only removed from the lp_item table, but remains in the document table * is only removed from the lp_item table, but remains in the document table
@ -4173,7 +4104,7 @@ class learnpathItem
* *
* @return bool * @return bool
*/ */
public function remove_audio() public function removeAudio()
{ {
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
@ -4194,6 +4125,32 @@ class learnpathItem
Database::query($sql); Database::query($sql);
} }
/**
* Adds an audio file to the current item, using a file already in documents.
*
* @param int $documentId
*
* @return string
*/
public function add_audio_from_documents($documentId)
{
$courseInfo = api_get_course_info();
$documentData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
$path = '';
if (!empty($documentData)) {
$path = $documentData['path'];
// Store the mp3 file in the lp_item table.
$table = Database::get_course_table(TABLE_LP_ITEM);
$sql = "UPDATE $table SET
audio = '".Database::escape_string($path)."'
WHERE iid = ".$this->db_id;
Database::query($sql);
}
return $path;
}
/** /**
* Transform the SCORM status to a string that can be translated by Chamilo * Transform the SCORM status to a string that can be translated by Chamilo
* in different user languages. * in different user languages.
@ -4491,7 +4448,7 @@ class learnpathItem
{ {
$lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$lp_view = Database::get_course_table(TABLE_LP_VIEW); $lp_view = Database::get_course_table(TABLE_LP_VIEW);
$course_id = api_get_course_int_id(); $courseId = api_get_course_int_id();
$user_id = (int) $user_id; $user_id = (int) $user_id;
// Check results from another sessions: // Check results from another sessions:
@ -4500,7 +4457,7 @@ class learnpathItem
// Check items // Check items
$sql = "SELECT iid FROM $lp_view $sql = "SELECT iid FROM $lp_view
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
user_id = $user_id AND user_id = $user_id AND
lp_id = $this->lp_id AND lp_id = $this->lp_id AND
session_id <> 0 session_id <> 0
@ -4511,7 +4468,7 @@ class learnpathItem
$lpIid = $row['iid']; $lpIid = $row['iid'];
$sql = "SELECT status FROM $lp_item_view $sql = "SELECT status FROM $lp_item_view
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
lp_view_id = $lpIid AND lp_view_id = $lpIid AND
lp_item_id = $refs_list[$prereqs_string] lp_item_id = $refs_list[$prereqs_string]
LIMIT 1"; LIMIT 1";

@ -97,24 +97,23 @@ $lpPathInfo = $lp->generate_lp_folder($courseInfo);
DocumentManager::createDefaultAudioFolder($courseInfo); DocumentManager::createDefaultAudioFolder($courseInfo);
$currentDir = '/audio'; $currentDir = '/audio';
$audioFolderId = DocumentManager::get_document_id($courseInfo, $currentDir); $audioFolderId = DocumentManager::get_document_id($courseInfo, $currentDir);
if (isset($_REQUEST['folder_id'])) { if (isset($_REQUEST['folder_id'])) {
$documentData = DocumentManager::get_document_data_by_id($_REQUEST['folder_id'], $courseInfo['code']); $folderIdFromRequest = isset($_REQUEST['folder_id']) ? (int) $_REQUEST['folder_id'] : 0;
$documentData = DocumentManager::get_document_data_by_id($folderIdFromRequest, $courseInfo['code']);
if ($documentData) { if ($documentData) {
$audioFolderId = (int) $_REQUEST['folder_id']; $audioFolderId = $folderIdFromRequest;
$currentDir = $documentData['path']; $currentDir = $documentData['path'];
} else {
$currentDir = '/';
$audioFolderId = false;
} }
} }
$file = null; $file = null;
//$lp_item->audio = '/aaaaa.wav'; if (!empty($lp_item->audio)) {
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/'.$lp_item->audio; $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/'.$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/'.$lp_item->audio.'?'.api_get_cidreq(); $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/'.$lp_item->audio.'?'.api_get_cidreq();
if (!file_exists($file)) {
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].'/'.$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].'/'.$lp_item->audio.'?'.api_get_cidreq();
}
} }
$page = $lp->build_action_menu( $page = $lp->build_action_menu(
@ -152,7 +151,7 @@ $form->addElement('header', '<small class="text-muted">'.get_lang('Or').'</small
$audioLabel = ''; $audioLabel = '';
if (!empty($lp_item->audio)) { if (!empty($lp_item->audio)) {
$audioLabel = '&nbsp; '.get_lang('FileName').': <b>'.$lp_item->audio.'<b/>'; $audioLabel = '<br />'.get_lang('FileName').': <b>'.$lp_item->audio.'<b/>';
} }
$form->addLabel(null, sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title()).$audioLabel); $form->addLabel(null, sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title()).$audioLabel);
@ -178,14 +177,6 @@ $form->addElement('file', 'file');
$form->addElement('hidden', 'id', $lp_item_id); $form->addElement('hidden', 'id', $lp_item_id);
$form->addButtonSave(get_lang('SaveRecordedAudio')); $form->addButtonSave(get_lang('SaveRecordedAudio'));
$folders = DocumentManager::get_all_document_folders(
$courseInfo,
null,
true,
false,
$currentDir
);
$documentTree = DocumentManager::get_document_preview( $documentTree = DocumentManager::get_document_preview(
$courseInfo, $courseInfo,
$lp->get_id(), $lp->get_id(),
@ -198,7 +189,8 @@ $documentTree = DocumentManager::get_document_preview(
true, true,
$audioFolderId, $audioFolderId,
true, true,
true true,
['mp3', 'ogg', 'wav']
); );
$page .= $recordVoiceForm; $page .= $recordVoiceForm;
@ -206,6 +198,14 @@ $page .= '<br>';
$page .= $form->returnForm(); $page .= $form->returnForm();
$page .= '<h3 class="page-header"><small>'.get_lang('Or').'</small> '.get_lang('SelectAnAudioFileFromDocuments').'</h3>'; $page .= '<h3 class="page-header"><small>'.get_lang('Or').'</small> '.get_lang('SelectAnAudioFileFromDocuments').'</h3>';
$folders = DocumentManager::get_all_document_folders(
$courseInfo,
null,
true,
false,
$currentDir
);
$form = new FormValidator( $form = new FormValidator(
'selector', 'selector',
'POST', 'POST',

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use ChamiloSession as Session; use ChamiloSession as Session;
@ -11,7 +12,6 @@ use ChamiloSession as Session;
* @author Roan Embrechts, refactoring and code cleaning * @author Roan Embrechts, refactoring and code cleaning
* @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
* *
* @package chamilo.learnpath
*/ */
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
@ -68,14 +68,14 @@ $lp_theme_css = $learnPath->get_theme();
// POST action handling (uploading mp3, deleting mp3) // POST action handling (uploading mp3, deleting mp3)
if (isset($_POST['save_audio'])) { if (isset($_POST['save_audio'])) {
//Updating the lp.modified_on // Updating the lp.modified_on
$learnPath->set_modified_on(); $learnPath->set_modified_on();
$lp_items_to_remove_audio = []; $lp_items_to_remove_audio = [];
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
// Deleting the audio fragments. // Deleting the audio fragments.
foreach ($_POST as $key => $value) { foreach ($_POST as $key => $value) {
if (substr($key, 0, 9) == 'removemp3') { if (substr($key, 0, 9) === 'removemp3') {
$lp_items_to_remove_audio[] = str_ireplace('removemp3', '', $key); $lp_items_to_remove_audio[] = str_ireplace('removemp3', '', $key);
// Removing the audio from the learning path item. // Removing the audio from the learning path item.
$in = implode(',', $lp_items_to_remove_audio); $in = implode(',', $lp_items_to_remove_audio);
@ -87,23 +87,21 @@ if (isset($_POST['save_audio'])) {
Database::query($sql); Database::query($sql);
} }
// Create the audio folder if it does not exist yet.
DocumentManager::createDefaultAudioFolder($_course);
// Uploading the audio files. // Uploading the audio files.
foreach ($_FILES as $key => $value) { foreach ($_FILES as $key => $value) {
if (substr($key, 0, 7) == 'mp3file' && if (substr($key, 0, 7) === 'mp3file' &&
!empty($_FILES[$key]['tmp_name']) !empty($_FILES[$key]['tmp_name'])
) { ) {
// The id of the learning path item. // The id of the learning path item.
$lp_item_id = str_ireplace('mp3file', '', $key); $lp_item_id = str_ireplace('mp3file', '', $key);
// Create the audio folder if it does not exist yet.
DocumentManager::createDefaultAudioFolder($_course);
// Check if file already exits into document/audio/ // Check if file already exits into document/audio/
$file_name = $_FILES[$key]['name']; $file_name = $_FILES[$key]['name'];
$file_name = stripslashes($file_name); $file_name = stripslashes($file_name);
// Add extension to files without one (if possible). // Add extension to files without one (if possible).
$file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']); $file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']);
$clean_name = api_replace_dangerous_char($file_name); $clean_name = api_replace_dangerous_char($file_name);
// No "dangerous" files. // No "dangerous" files.
$clean_name = disable_dangerous_file($clean_name); $clean_name = disable_dangerous_file($clean_name);
@ -123,7 +121,7 @@ if (isset($_POST['save_audio'])) {
} }
// Upload the file in the documents tool. // Upload the file in the documents tool.
$file_path = handle_uploaded_document( $filePath = handle_uploaded_document(
$_course, $_course,
$_FILES[$key], $_FILES[$key],
api_get_path(SYS_COURSE_PATH).$_course['path'].'/document', api_get_path(SYS_COURSE_PATH).$_course['path'].'/document',
@ -136,18 +134,15 @@ if (isset($_POST['save_audio'])) {
false false
); );
// Getting the filename only.
$file_components = explode('/', $file_path);
$file = $file_components[count($file_components) - 1];
// Store the mp3 file in the lp_item table. // Store the mp3 file in the lp_item table.
$sql = "UPDATE $tbl_lp_item $sql = "UPDATE $tbl_lp_item
SET audio = '".Database::escape_string($file)."' SET audio = '".Database::escape_string($filePath)."'
WHERE iid = ".(int) $lp_item_id; WHERE iid = ".(int) $lp_item_id;
Database::query($sql); Database::query($sql);
} }
} }
//echo Display::return_message(get_lang('ItemUpdated'), 'confirm');
Display::addFlash(Display::return_message(get_lang('ItemUpdated'), 'confirm'));
$url = api_get_self().'?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(); $url = api_get_self().'?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq();
header('Location: '.$url); header('Location: '.$url);
exit; exit;

@ -672,7 +672,7 @@ switch ($action) {
// Remove audio // Remove audio
if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) { if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) {
$lp_item_obj->remove_audio(); $lp_item_obj->removeAudio();
Display::addFlash(Display::return_message(get_lang('FileDeleted'))); Display::addFlash(Display::return_message(get_lang('FileDeleted')));
$url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq(); $url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq();
@ -684,7 +684,7 @@ switch ($action) {
if (isset($_FILES['file']) && !empty($_FILES['file'])) { if (isset($_FILES['file']) && !empty($_FILES['file'])) {
// Updating the lp.modified_on // Updating the lp.modified_on
$_SESSION['oLP']->set_modified_on(); $_SESSION['oLP']->set_modified_on();
$lp_item_obj->add_audio(); $lp_item_obj->addAudio();
Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded'))); Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded')));
} }

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use ChamiloSession as Session; use ChamiloSession as Session;
@ -10,9 +11,8 @@ use ChamiloSession as Session;
* @author Denes Nagy * @author Denes Nagy
* @author Roan Embrechts, refactoring and code cleaning * @author Roan Embrechts, refactoring and code cleaning
* @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
*
* @package chamilo.learnpath
*/ */
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
api_protect_course_script(); api_protect_course_script();
@ -73,13 +73,11 @@ $interbreadcrumb[] = [
// Theme calls // Theme calls
$show_learn_path = true; $show_learn_path = true;
$lp_theme_css = $learnPath->get_theme(); $lp_theme_css = $learnPath->get_theme();
Display::display_header(get_lang('Move'), 'Path'); Display::display_header(get_lang('Move'), 'Path');
$suredel = trim(get_lang('AreYouSureToDeleteJS')); $suredel = trim(get_lang('AreYouSureToDeleteJS'));
?> ?>
<script> <script>
/* <![CDATA[ */
function stripslashes(str) { function stripslashes(str) {
str=str.replace(/\\'/g,'\''); str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"'); str=str.replace(/\\"/g,'"');
@ -89,12 +87,9 @@ function stripslashes(str) {
} }
function confirmation(name) { function confirmation(name) {
name=stripslashes(name); name=stripslashes(name);
if (confirm("<?php echo $suredel; ?> " + name + " ?")) if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
{
return true; return true;
} } else {
else
{
return false; return false;
} }
} }
@ -108,14 +103,14 @@ echo '<div class="col-md-3">';
echo '</div>'; echo '</div>';
echo '<div class="col-md-9">'; echo '<div class="col-md-9">';
if (isset($is_success) && $is_success === true) { if (isset($is_success) && $is_success === true) {
$msg = '<div class="lp_message" style="margin-bottom:10px;">'; $msg = '<div class="lp_message" style="margin-bottom:10px;">';
$msg .= 'The item has been moved.'; $msg .= 'The item has been moved.';
$msg .= '</div>'; $msg .= '</div>';
echo $learnPath->display_item($_GET['id'], $msg); echo $learnPath->display_item($_GET['id'], $msg);
} else { } else {
echo $learnPath->display_move_item($_GET['id']); $item = new learnpathItem($_GET['id']);
echo $learnPath->display_move_item($item);
} }
echo '</div>'; echo '</div>';
echo '</div>'; echo '</div>';

Loading…
Cancel
Save