diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php
index a0bb6dda90..185b5cd5cc 100644
--- a/main/inc/lib/document.lib.php
+++ b/main/inc/lib/document.lib.php
@@ -772,8 +772,6 @@ class DocumentManager
if ($can_see_invisible) {
// condition for the session
$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();
$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);
@@ -3326,6 +3324,7 @@ class DocumentManager
* @param int $folderId
* @param bool $addCloseButton
* @param bool $addAudioPreview
+ * @param array $filterByExtension
*
* @return string
*/
@@ -3341,7 +3340,8 @@ class DocumentManager
$showOnlyFolders = false,
$folderId = false,
$addCloseButton = true,
- $addAudioPreview = false
+ $addAudioPreview = false,
+ $filterByExtension = []
) {
if (empty($course_info['real_id']) || empty($course_info['code']) || !is_array($course_info)) {
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 = [];
if ($folderId !== false) {
$parentData = self::get_document_data_by_id(
@@ -3453,6 +3464,7 @@ class DocumentManager
last.c_id = {$course_info['real_id']}
$folderCondition
$levelCondition
+ $extensionConditionToString
$add_folder_filter
ORDER BY docs.filetype DESC, docs.title ASC";
diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php
index 48b66669af..6e20516847 100755
--- a/main/lp/learnpath.class.php
+++ b/main/lp/learnpath.class.php
@@ -54,6 +54,7 @@ class learnpath
public $error = '';
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.
+ /** @var learnpathItem[] */
public $items = [];
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.
@@ -2103,23 +2104,24 @@ class learnpath
public function get_mediaplayer($lpItemId, $autostart = 'true')
{
$course_id = api_get_course_int_id();
- $_course = api_get_course_info();
- if (empty($_course)) {
- return '';
- }
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
+ $courseInfo = api_get_course_info();
$lpItemId = (int) $lpItemId;
- /** @var learnpathItem $item */
+ if (empty($courseInfo) || empty($lpItemId)) {
+ return '';
+ }
$item = isset($this->items[$lpItemId]) ? $this->items[$lpItemId] : null;
- $itemViewId = 0;
- if ($item) {
- $itemViewId = (int) $item->db_item_view_id;
+
+ if (empty($item)) {
+ return '';
}
+ $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
+ $tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
+ $itemViewId = (int) $item->db_item_view_id;
+
// 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
INNER JOIN $tbl_lp_item_view as lp_view
ON (lpi.iid = lp_view.lp_item_id)
@@ -2130,11 +2132,12 @@ class learnpath
$result = Database::query($sql);
$row = Database::fetch_assoc($result);
$output = '';
+ $audio = $item->audio;
- if (!empty($row['audio'])) {
+ if (!empty($audio)) {
$list = $_SESSION['oLP']->get_toc();
- switch ($row['item_type']) {
+ switch ($item->get_type()) {
case 'quiz':
$type_quiz = false;
foreach ($list as $toc) {
@@ -2151,24 +2154,15 @@ class learnpath
}
}
break;
- case TOOL_READOUT_TEXT:;
+ case TOOL_READOUT_TEXT:
$autostart_audio = 'false';
break;
default:
$autostart_audio = 'true';
}
- $courseInfo = api_get_course_info();
- $audio = $row['audio'];
-
- $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();
- }
+ $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$audio;
+ $url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$audio.'?'.api_get_cidreq();
$player = Display::getMediaPlayer(
$file,
@@ -8237,15 +8231,25 @@ class learnpath
$item_description = '';
$item_path_fck = '';
+ $parent = 0;
+ $previousId = null;
if ($id != 0 && is_array($extra_info)) {
$item_title = $extra_info['title'];
$item_description = $extra_info['description'];
$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']);
- }
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
$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;
@@ -8254,7 +8258,7 @@ class learnpath
lp_id = ".$this->lp_id." AND
iid != $id";
- if ($item_type == 'dir') {
+ if ($item_type === 'dir') {
$sql .= " AND parent_item_id = 0";
}
@@ -8319,7 +8323,7 @@ class learnpath
}
}
- if ($action != 'move') {
+ if ($action !== 'move') {
$this->setItemTitle($form);
} else {
$form->addElement('hidden', 'title');
@@ -8359,11 +8363,9 @@ class learnpath
if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id &&
$arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) {
//this is the same!
- if (isset($extra_info['previous_item_id']) &&
- $extra_info['previous_item_id'] == $arrLP[$i]['id']
- ) {
+ if (isset($previousId) && $previousId == $arrLP[$i]['id']) {
$s_selected_position = $arrLP[$i]['id'];
- } elseif ($action == 'add') {
+ } elseif ($action === 'add') {
$s_selected_position = $arrLP[$i]['id'];
}
@@ -8414,8 +8416,8 @@ class learnpath
//assets can't be modified
//$item_type == 'asset' ||
- if (($item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
- if ($item_type == 'sco') {
+ if (($item_type === 'sco') && ($extension === 'html' || $extension === 'htm')) {
+ if ($item_type === 'sco') {
$form->addElement(
'html',
''
@@ -9612,7 +9614,7 @@ class learnpath
/**
* Displays the menu for manipulating a step.
*
- * @param id $item_id
+ * @param int $item_id
* @param string $item_type
*
* @return string
@@ -9633,11 +9635,11 @@ class learnpath
$audio_player = null;
// We display an audio player if needed.
if (!empty($row['audio'])) {
- $webAudioPath = '../..'.api_get_path(REL_COURSE_PATH).$_course['path'].'/document/audio/'.$row['audio'];
-
- $audio_player .= '
';
+ $audio = learnpathItem::fixAudio($row['audio']);
+ $webAudioPath = '../..'.api_get_path(REL_COURSE_PATH).$_course['path'].'/document'.$audio;
+ $audio_player .= '
';
}
$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.
*
- * @param int $item_id Item ID
+ * @param learnpathItem $item Item ID
*
* @throws Exception
* @throws HTML_QuickForm_Error
*
* @return string HTML form
*/
- public function display_move_item($item_id)
+ public function display_move_item($item)
{
$return = '';
- if (is_numeric($item_id)) {
- $item_id = (int) $item_id;
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
-
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE iid = $item_id";
- $res = Database::query($sql);
- $row = Database::fetch_array($res);
+ if ($item) {
+ $item_id = $item->getIid();
+ $type = $item->get_type();
- switch ($row['item_type']) {
+ switch ($type) {
case 'dir':
case 'asset':
- $return .= $this->display_manipulate($item_id, $row['item_type']);
+ $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_item_form(
- $row['item_type'],
+ $type,
get_lang('MoveCurrentChapter'),
'move',
$item_id,
- $row
+ $item
);
break;
case TOOL_DOCUMENT:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('move', $item_id, $row);
+ $return .= $this->display_manipulate($item_id, $type);
+ $return .= $this->display_document_form('move', $item_id, $item);
break;
case TOOL_LINK:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
+ $return .= $this->display_manipulate($item_id, $type);
+ $return .= $this->display_link_form('move', $item_id, $item);
break;
case TOOL_HOTPOTATOES:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
+ $return .= $this->display_manipulate($item_id, $type);
+ $return .= $this->display_link_form('move', $item_id, $item);
break;
case TOOL_QUIZ:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('move', $item_id, $row);
+ $return .= $this->display_manipulate($item_id, $type);
+ $return .= $this->display_quiz_form('move', $item_id, $item);
break;
case TOOL_STUDENTPUBLICATION:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('move', $item_id, $row);
+ $return .= $this->display_manipulate($item_id, $type);
+ $return .= $this->display_student_publication_form('move', $item_id, $item);
break;
case TOOL_FORUM:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
+ $return .= $this->display_manipulate($item_id, $type);
+ $return .= $this->display_forum_form('move', $item_id, $item);
break;
case TOOL_THREAD:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
+ $return .= $this->display_manipulate($item_id, $type);
+ $return .= $this->display_forum_form('move', $item_id, $item);
break;
}
}
diff --git a/main/lp/learnpathItem.class.php b/main/lp/learnpathItem.class.php
index 99fc0ac089..ce12049c04 100755
--- a/main/lp/learnpathItem.class.php
+++ b/main/lp/learnpathItem.class.php
@@ -79,6 +79,8 @@ class learnpathItem
private $last_scorm_session_time = 0;
private $prerequisiteMaxScore;
private $prerequisiteMinScore;
+ public $courseInfo;
+ public $courseId;
/**
* Prepares the learning path item for later launch.
@@ -87,23 +89,21 @@ class learnpathItem
*
* @param int $id Learning path item 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
*/
public function __construct(
$id,
$user_id = 0,
- $course_id = 0,
+ $courseId = 0,
$item_content = null
) {
$items_table = Database::get_course_table(TABLE_LP_ITEM);
$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($course_id)) {
- $course_id = api_get_course_int_id();
- } else {
- $course_id = (int) $course_id;
- }
$sql = "SELECT * FROM $items_table
WHERE iid = $id";
$res = Database::query($sql);
@@ -136,10 +136,9 @@ class learnpathItem
$this->setPrerequisiteMinScore($row['prerequisite_min_score']);
$this->oldTotalTime = 0;
$this->view_max_score = 0;
-
- if (isset($row['launch_data'])) {
- $this->launch_data = $row['launch_data'];
- }
+ $this->seriousgame_mode = 0;
+ $this->audio = self::fixAudio($row['audio']);
+ $this->launch_data = $row['launch_data'];
$this->save_on_close = true;
$this->db_id = $id;
@@ -147,7 +146,7 @@ class learnpathItem
if (!empty($this->lp_id)) {
$sql = "SELECT iid FROM $items_table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_id = ".$this->lp_id." AND
parent_item_id = $id";
$res = Database::query($sql);
@@ -158,7 +157,7 @@ class learnpathItem
}
// 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);
$sql = 'SELECT *
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'];
- }
}
- /**
- * Adds a child to the current item.
- *
- * @param int $item The child item ID
- */
- public function add_child($item)
+ public static function fixAudio($audio)
{
- 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;
+ $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;
+
+ if (file_exists($file)) {
+
+ return $audio;
+ }
+
+ return '';
}
/**
@@ -261,7 +261,7 @@ class learnpathItem
}
$this->current_stop_time = time();
$type = $this->get_type();
- if ($type != 'sco') {
+ if ($type !== 'sco') {
if ($type == TOOL_QUIZ || $type == TOOL_HOTPOTATOES) {
$this->get_status(
true,
@@ -287,10 +287,10 @@ class learnpathItem
{
$lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$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
- 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);
$sql = "SELECT * FROM $lp_item
@@ -314,22 +314,6 @@ class learnpathItem
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.
*
@@ -455,12 +439,12 @@ class learnpathItem
*/
public function get_file_path($path_to_scorm_dir = '')
{
- $course_id = api_get_course_int_id();
+ $courseId = $this->courseId;
$path = $this->get_path();
$type = $this->get_type();
if (empty($path)) {
- if ($type == 'dir') {
+ if ($type === 'dir') {
return '';
} else {
return '-1';
@@ -475,7 +459,7 @@ class learnpathItem
$sql = 'SELECT path
FROM '.$table_doc.'
WHERE
- c_id = '.$course_id.' AND
+ c_id = '.$courseId.' AND
iid = '.$path;
$res = Database::query($sql);
$row = Database::fetch_array($res);
@@ -521,11 +505,11 @@ class learnpathItem
public function load_interactions()
{
$this->interactions = [];
- $course_id = api_get_course_int_id();
+ $courseId = $this->courseId;
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT id FROM $tbl
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_view_count();
@@ -535,7 +519,7 @@ class learnpathItem
$lp_iv_id = $row[0];
$iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
$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);
while ($row = Database::fetch_array($res_sql)) {
$this->interactions[$row['interaction_id']] = [
@@ -566,13 +550,13 @@ class learnpathItem
// If the user is an invitee, we consider there's no interaction
return 0;
}
- $course_id = api_get_course_int_id();
+ $courseId = $this->courseId;
if ($checkdb) {
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT iid FROM $tbl
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id();
@@ -585,7 +569,7 @@ class learnpathItem
);
$sql = "SELECT count(id) as mycount
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);
if (Database::num_rows($res_sql) > 0) {
$row = Database::fetch_array($res_sql);
@@ -1481,7 +1465,7 @@ class learnpathItem
*/
public function get_status($check_db = true, $update_local = false)
{
- $course_id = api_get_course_int_id();
+ $courseId = $this->courseId;
$debug = self::DEBUG;
if ($debug > 0) {
error_log('learnpathItem::get_status() on item '.$this->db_id, 0);
@@ -1490,11 +1474,11 @@ class learnpathItem
if ($debug > 2) {
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);
$sql = "SELECT status FROM $table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
iid = '".$this->db_item_view_id."' AND
view_count = '".$this->get_attempt_id()."'";
$res = Database::query($sql);
@@ -1572,7 +1556,7 @@ class learnpathItem
$query_db = false
) {
$time = null;
- $course_id = api_get_course_int_id();
+ $courseId = $this->courseId;
if (!isset($given_time)) {
if (self::DEBUG > 2) {
error_log(
@@ -1585,7 +1569,7 @@ class learnpathItem
$sql = "SELECT start_time, total_time
FROM $table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
iid = '".$this->db_item_view_id."' AND
view_count = '".$this->get_attempt_id()."'";
$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();
// Deal with &, |, ~, =, <>, {}, ,, X*, () in reverse order.
@@ -2347,7 +2331,7 @@ class learnpathItem
orig_lp_id = '.$this->lp_id.' AND
orig_lp_item_id = '.$prereqs_string.' AND
status <> "incomplete" AND
- c_id = '.$course_id.'
+ c_id = '.$courseId.'
ORDER BY exe_date DESC
LIMIT 0, 1';
$rs_quiz = Database::query($sql);
@@ -2397,7 +2381,7 @@ class learnpathItem
$sql = 'SELECT exe_result, exe_weighting
FROM '.Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES).'
WHERE
- c_id = '.$course_id.' AND
+ c_id = '.$courseId.' AND
exe_exo_id = '.$items[$refs_list[$prereqs_string]]->path.' AND
exe_user_id = '.$user_id.' AND
orig_lp_id = '.$this->lp_id.' AND
@@ -2505,7 +2489,7 @@ class learnpathItem
if ($returnstatus && $this->prevent_reinit == 1) {
$sql = "SELECT iid FROM $lp_view
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
user_id = $user_id AND
lp_id = $this->lp_id AND
session_id = $sessionId
@@ -2517,7 +2501,7 @@ class learnpathItem
$sql = "SELECT status FROM $lp_item_view
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_view_id = $my_lp_id AND
lp_item_id = $refs_list[$prereqs_string]
LIMIT 0, 1";
@@ -2934,19 +2918,19 @@ class learnpathItem
* Sets the lp_view id this item view is registered to.
*
* @param int $lp_view_id lp_view DB ID
- * @param int $course_id
+ * @param int $courseId
*
* @return bool
*
* @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;
- $course_id = (int) $course_id;
+ $courseId = (int) $courseId;
- if (empty($course_id)) {
- $course_id = api_get_course_int_id();
+ if (empty($courseId)) {
+ $courseId = api_get_course_int_id();
}
$lpItemId = $this->get_id();
@@ -2969,7 +2953,7 @@ class learnpathItem
// Get the lp_item_view with the highest view_count.
$sql = "SELECT * FROM $item_view_table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = $lpItemId AND
lp_view_id = $lp_view_id
ORDER BY view_count DESC";
@@ -3005,7 +2989,7 @@ class learnpathItem
$table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
$sql = "SELECT * FROM $table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_iv_id = '".$this->db_item_view_id."'";
$res = Database::query($sql);
@@ -3018,7 +3002,7 @@ class learnpathItem
$table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
$sql = "SELECT * FROM $table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_iv_id = '".$this->db_item_view_id."'";
$this->objectives_count = 0;
@@ -3385,12 +3369,12 @@ class learnpathItem
// Step 1 : get actual total time stored in db
$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
FROM '.$item_view_table.'
WHERE
- c_id = '.$course_id.' AND
+ c_id = '.$courseId.' AND
lp_item_id = "'.$this->db_id.'" AND
lp_view_id = "'.$this->view_id.'" AND
view_count = "'.$this->get_attempt_id().'"';
@@ -3459,7 +3443,7 @@ class learnpathItem
$sql = "UPDATE $item_view_table
SET total_time = '$total_time'
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = {$this->db_id} AND
lp_view_id = {$this->view_id} AND
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
* 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
return true;
}
- $course_id = api_get_course_int_id();
+ $courseId = api_get_course_int_id();
if (is_array($this->objectives) && count($this->objectives) > 0) {
// Save objectives.
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT iid
FROM $tbl
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND
view_count = ".$this->attempt_id;
@@ -3533,7 +3499,7 @@ class learnpathItem
);
$iva_sql = "SELECT iid FROM $iva_table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_iv_id = $lp_iv_id AND
objective_id = '".Database::escape_string($objective[0])."'";
$iva_res = Database::query($iva_sql);
@@ -3550,12 +3516,12 @@ class learnpathItem
"score_raw = '".Database::escape_string($objective[2])."',".
"score_min = '".Database::escape_string($objective[4])."',".
"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);
} else {
// Insert new one.
$params = [
- 'c_id' => $course_id,
+ 'c_id' => $courseId,
'lp_iv_id' => $lp_iv_id,
'order_id' => $index,
'objective_id' => $objective[0],
@@ -3602,16 +3568,17 @@ class learnpathItem
return true;
}
- $course_id = api_get_course_int_id();
+ $courseId = api_get_course_int_id();
$mode = $this->get_lesson_mode();
$credit = $this->get_credit();
$total_time = ' ';
$my_status = ' ';
$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
- c_id = '.$course_id.' AND
+ c_id = '.$courseId.' AND
lp_item_id="'.$this->db_id.'" AND
lp_view_id="'.$this->view_id.'" AND
view_count="'.$this->get_attempt_id().'" ';
@@ -3635,9 +3602,9 @@ class learnpathItem
}
}
- if ((($save === false && $this->type == 'sco') ||
- ($this->type == 'sco' && ($credit == 'no-credit' || $mode == 'review' || $mode == 'browse'))) &&
- ($this->seriousgame_mode != 1 && $this->type == 'sco')
+ if ((($save === false && $this->type === 'sco') ||
+ ($this->type === 'sco' && ($credit === 'no-credit' || $mode === 'review' || $mode === 'browse'))) &&
+ ($this->seriousgame_mode != 1 && $this->type === 'sco')
) {
if ($debug) {
error_log(
@@ -3653,14 +3620,14 @@ class learnpathItem
// Check the row exists.
$inserted = false;
// 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_status() == 'completed'
+ $this->get_status() === 'completed'
) {
// We force the item to be restarted.
$this->restart();
$params = [
- "c_id" => $course_id,
+ "c_id" => $courseId,
"total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time,
"score" => $this->get_score(),
@@ -3691,7 +3658,7 @@ class learnpathItem
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT * FROM $item_view_table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id();
@@ -3707,7 +3674,7 @@ class learnpathItem
// now save into DB.
if (!$inserted && Database::num_rows($check_res) < 1) {
$params = [
- "c_id" => $course_id,
+ "c_id" => $courseId,
"total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time,
"score" => $this->get_score(),
@@ -3747,7 +3714,7 @@ class learnpathItem
];
$where = [
'c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' => [
- $course_id,
+ $courseId,
$this->db_id,
$this->view_id,
$this->get_attempt_id(),
@@ -3756,7 +3723,7 @@ class learnpathItem
Database::update($item_view_table, $params, $where);
} else {
// For all other content types...
- if ($this->type == 'quiz') {
+ if ($this->type === 'quiz') {
if ($debug) {
error_log("item is quiz:");
}
@@ -3768,9 +3735,6 @@ class learnpathItem
$sql = "SELECT exe_duration
FROM $table
WHERE exe_id = $exeId";
- if ($debug) {
- error_log($sql);
- }
$res = Database::query($sql);
$exeRow = Database::fetch_array($res);
$duration = $exeRow['exe_duration'];
@@ -3790,17 +3754,14 @@ class learnpathItem
];
// 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().", ";
$my_status = " status = '".$this->get_status(false)."' ,";
- if ($debug) {
- error_log("seriousgame_mode time changed: $total_time");
- }
} elseif ($this->get_prevent_reinit() == 1) {
// Process of status verified into data base.
$sql = 'SELECT status FROM '.$item_view_table.'
WHERE
- c_id = '.$course_id.' AND
+ c_id = '.$courseId.' AND
lp_item_id="'.$this->db_id.'" AND
lp_view_id="'.$this->view_id.'" AND
view_count="'.$this->get_attempt_id().'"
@@ -3876,16 +3837,12 @@ class learnpathItem
// Verify current status in multiples attempts.
$sql = 'SELECT status FROM '.$item_view_table.'
WHERE
- c_id = '.$course_id.' AND
+ c_id = '.$courseId.' AND
lp_item_id="'.$this->db_id.'" AND
lp_view_id="'.$this->view_id.'" AND
view_count="'.$this->get_attempt_id().'" ';
$rs_status = Database::query($sql);
- $current_status = Database::result(
- $rs_status,
- 0,
- 'status'
- );
+ $current_status = Database::result($rs_status, 0, 'status');
if (in_array($current_status, $case_completed)) {
$my_status = '';
$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
//" . //start_time = ".$this->get_current_start_time().", " . //scorm_init_time does it
////" max_time_allowed = '".$this->get_max_time_allowed()."'," .
@@ -3911,7 +3868,7 @@ class learnpathItem
suspend_data = '".Database::escape_string($this->current_data)."',
lesson_location = '".$this->lesson_location."'
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id();
@@ -3926,7 +3883,7 @@ class learnpathItem
suspend_data = '".Database::escape_string($this->current_data)."',
lesson_location = '".$this->lesson_location."'
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id();
@@ -3949,7 +3906,7 @@ class learnpathItem
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT iid FROM $tbl
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_item_id = ".$this->db_id." AND
lp_view_id = ".$this->view_id." AND
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
$iva_sql = "SELECT iid FROM $iva_table
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_iv_id = $lp_iv_id AND
(
order_id = $index OR
@@ -4022,7 +3979,7 @@ class learnpathItem
$params,
[
'c_id = ? AND iid = ?' => [
- $course_id,
+ $courseId,
$iva_id,
],
]
@@ -4030,7 +3987,7 @@ class learnpathItem
} else {
// Insert new one.
$params = [
- 'c_id' => $course_id,
+ 'c_id' => $courseId,
'order_id' => $index,
'lp_iv_id' => $lp_iv_id,
'interaction_id' => $interaction[0],
@@ -4067,7 +4024,7 @@ class learnpathItem
*
* @return bool|string|null
*/
- public function add_audio()
+ public function addAudio()
{
$course_info = api_get_course_info();
$filepath = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/';
@@ -4140,32 +4097,6 @@ class learnpathItem
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
* is only removed from the lp_item table, but remains in the document table
@@ -4173,7 +4104,7 @@ class learnpathItem
*
* @return bool
*/
- public function remove_audio()
+ public function removeAudio()
{
$courseInfo = api_get_course_info();
@@ -4194,6 +4125,32 @@ class learnpathItem
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
* in different user languages.
@@ -4491,7 +4448,7 @@ class learnpathItem
{
$lp_item_view = Database::get_course_table(TABLE_LP_ITEM_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;
// Check results from another sessions:
@@ -4500,7 +4457,7 @@ class learnpathItem
// Check items
$sql = "SELECT iid FROM $lp_view
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
user_id = $user_id AND
lp_id = $this->lp_id AND
session_id <> 0
@@ -4511,7 +4468,7 @@ class learnpathItem
$lpIid = $row['iid'];
$sql = "SELECT status FROM $lp_item_view
WHERE
- c_id = $course_id AND
+ c_id = $courseId AND
lp_view_id = $lpIid AND
lp_item_id = $refs_list[$prereqs_string]
LIMIT 1";
diff --git a/main/lp/lp_add_audio.php b/main/lp/lp_add_audio.php
index cd203e18e0..4a7056648e 100755
--- a/main/lp/lp_add_audio.php
+++ b/main/lp/lp_add_audio.php
@@ -97,24 +97,23 @@ $lpPathInfo = $lp->generate_lp_folder($courseInfo);
DocumentManager::createDefaultAudioFolder($courseInfo);
$currentDir = '/audio';
$audioFolderId = DocumentManager::get_document_id($courseInfo, $currentDir);
+
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) {
- $audioFolderId = (int) $_REQUEST['folder_id'];
+ $audioFolderId = $folderIdFromRequest;
$currentDir = $documentData['path'];
+ } else {
+ $currentDir = '/';
+ $audioFolderId = false;
}
}
$file = null;
-//$lp_item->audio = '/aaaaa.wav';
-if (isset($lp_item->audio) && !empty($lp_item->audio)) {
+if (!empty($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();
-
- 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(
@@ -152,7 +151,7 @@ $form->addElement('header', ''.get_lang('Or').'audio)) {
- $audioLabel = ' '.get_lang('FileName').': '.$lp_item->audio.'';
+ $audioLabel = '
'.get_lang('FileName').': '.$lp_item->audio.'';
}
$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->addButtonSave(get_lang('SaveRecordedAudio'));
-$folders = DocumentManager::get_all_document_folders(
- $courseInfo,
- null,
- true,
- false,
- $currentDir
-);
-
$documentTree = DocumentManager::get_document_preview(
$courseInfo,
$lp->get_id(),
@@ -198,7 +189,8 @@ $documentTree = DocumentManager::get_document_preview(
true,
$audioFolderId,
true,
- true
+ true,
+ ['mp3', 'ogg', 'wav']
);
$page .= $recordVoiceForm;
@@ -206,6 +198,14 @@ $page .= '
';
$page .= $form->returnForm();
$page .= '';
+$folders = DocumentManager::get_all_document_folders(
+ $courseInfo,
+ null,
+ true,
+ false,
+ $currentDir
+);
+
$form = new FormValidator(
'selector',
'POST',
diff --git a/main/lp/lp_admin_view.php b/main/lp/lp_admin_view.php
index ff3ee2d14c..b1374f5783 100755
--- a/main/lp/lp_admin_view.php
+++ b/main/lp/lp_admin_view.php
@@ -1,4 +1,5 @@
- cleaning and update for new SCORM tool
*
- * @package chamilo.learnpath
*/
$this_section = SECTION_COURSES;
@@ -68,42 +68,40 @@ $lp_theme_css = $learnPath->get_theme();
// POST action handling (uploading mp3, deleting mp3)
if (isset($_POST['save_audio'])) {
- //Updating the lp.modified_on
+ // Updating the lp.modified_on
$learnPath->set_modified_on();
$lp_items_to_remove_audio = [];
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
// Deleting the audio fragments.
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);
// Removing the audio from the learning path item.
$in = implode(',', $lp_items_to_remove_audio);
}
}
if (count($lp_items_to_remove_audio) > 0) {
- $sql = "UPDATE $tbl_lp_item SET audio = ''
+ $sql = "UPDATE $tbl_lp_item SET audio = ''
WHERE iid IN (".$in.")";
Database::query($sql);
}
+ // Create the audio folder if it does not exist yet.
+ DocumentManager::createDefaultAudioFolder($_course);
+
// Uploading the audio files.
foreach ($_FILES as $key => $value) {
- if (substr($key, 0, 7) == 'mp3file' &&
+ if (substr($key, 0, 7) === 'mp3file' &&
!empty($_FILES[$key]['tmp_name'])
) {
// The id of the learning path item.
$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/
$file_name = $_FILES[$key]['name'];
$file_name = stripslashes($file_name);
// Add extension to files without one (if possible).
$file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']);
-
$clean_name = api_replace_dangerous_char($file_name);
// No "dangerous" files.
$clean_name = disable_dangerous_file($clean_name);
@@ -123,7 +121,7 @@ if (isset($_POST['save_audio'])) {
}
// Upload the file in the documents tool.
- $file_path = handle_uploaded_document(
+ $filePath = handle_uploaded_document(
$_course,
$_FILES[$key],
api_get_path(SYS_COURSE_PATH).$_course['path'].'/document',
@@ -136,18 +134,15 @@ if (isset($_POST['save_audio'])) {
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.
- $sql = "UPDATE $tbl_lp_item
- SET audio = '".Database::escape_string($file)."'
+ $sql = "UPDATE $tbl_lp_item
+ SET audio = '".Database::escape_string($filePath)."'
WHERE iid = ".(int) $lp_item_id;
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();
header('Location: '.$url);
exit;
diff --git a/main/lp/lp_controller.php b/main/lp/lp_controller.php
index a00081a7e4..eb62d89c1d 100755
--- a/main/lp/lp_controller.php
+++ b/main/lp/lp_controller.php
@@ -672,7 +672,7 @@ switch ($action) {
// Remove audio
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')));
$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'])) {
// Updating the lp.modified_on
$_SESSION['oLP']->set_modified_on();
- $lp_item_obj->add_audio();
+ $lp_item_obj->addAudio();
Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded')));
}
diff --git a/main/lp/lp_move_item.php b/main/lp/lp_move_item.php
index f01ba578b2..13bd9fd515 100755
--- a/main/lp/lp_move_item.php
+++ b/main/lp/lp_move_item.php
@@ -1,4 +1,5 @@
- cleaning and update for new SCORM tool
- *
- * @package chamilo.learnpath
*/
+
$this_section = SECTION_COURSES;
api_protect_course_script();
@@ -73,13 +73,11 @@ $interbreadcrumb[] = [
// Theme calls
$show_learn_path = true;
$lp_theme_css = $learnPath->get_theme();
-
Display::display_header(get_lang('Move'), 'Path');
$suredel = trim(get_lang('AreYouSureToDeleteJS'));
?>