diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 85e762430f..db1a1153f4 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -662,7 +662,10 @@ class learnpath // Create the audio folder if it does not exist yet. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; if (!is_dir($filepath.'audio')) { - mkdir($filepath.'audio', api_get_permissions_for_new_directories()); + mkdir( + $filepath.'audio', + api_get_permissions_for_new_directories() + ); $audio_id = add_document( $_course, '/audio', @@ -797,7 +800,8 @@ class learnpath // There is already one such name, update the current one a bit. $i++; $name = $name.' - '.$i; - $check_name = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND name = '$name'"; + $check_name = "SELECT * FROM $tbl_lp + WHERE c_id = $course_id AND name = '$name'"; $res_name = Database::query($check_name); } // New name does not exist yet; keep it. @@ -822,7 +826,8 @@ class learnpath break; case 'manual': default: - $get_max = "SELECT MAX(display_order) FROM $tbl_lp WHERE c_id = $course_id"; + $get_max = "SELECT MAX(display_order) + FROM $tbl_lp WHERE c_id = $course_id"; $res_max = Database::query($get_max); if (Database::num_rows($res_max) < 1) { $dsp = 1; @@ -877,7 +882,14 @@ class learnpath 'LearnpathAdded', $userId ); - api_set_default_visibility($id, TOOL_LEARNPATH, 0, $courseInfo, $session_id, $userId); + api_set_default_visibility( + $id, + TOOL_LEARNPATH, + 0, + $courseInfo, + $session_id, + $userId + ); return $id; } break; @@ -1121,7 +1133,8 @@ class learnpath WHERE c_id = ".$course_id." AND (link LIKE '$link%' AND image='scormbuilder.gif')"; Database::query($sql); - $sql = "DELETE FROM $lp WHERE c_id = ".$course_id." AND id = ".$this->lp_id; + $sql = "DELETE FROM $lp + WHERE c_id = ".$course_id." AND id = ".$this->lp_id; Database::query($sql); // Updates the display order of all lps. $this->update_display_order(); @@ -1140,6 +1153,7 @@ class learnpath $id, api_get_session_id() ); + if ($link_info !== false) { GradebookUtils::remove_resource_from_course_gradebook($link_info['id']); } @@ -1230,7 +1244,11 @@ class learnpath Database::query($sql_upd); // Now update all following items with new display order. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 - WHERE c_id = ".$course_id." AND lp_id = $lp AND parent_item_id = $parent AND display_order > $display"; + WHERE + c_id = ".$course_id." AND + lp_id = $lp AND + parent_item_id = $parent AND + display_order > $display"; Database::query($sql_all); //Removing prerequisites since the item will not longer exist @@ -1240,7 +1258,9 @@ class learnpath // Remove from search engine if enabled. if (api_get_setting('search_enabled') == 'true') { $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); - $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; + $sql = 'SELECT * FROM %s + WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d + LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id); $res = Database::query($sql); if (Database::num_rows($res) > 0) { @@ -1249,7 +1269,9 @@ class learnpath $di = new ChamiloIndexer(); $di->remove_document((int) $row2['search_did']); } - $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; + $sql = 'DELETE FROM %s + WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d + LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id); Database::query($sql); } @@ -1653,14 +1675,16 @@ class learnpath } $lp_item = Database::get_course_table(TABLE_LP_ITEM); - $sql_parent = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = $id"; + $sql_parent = "SELECT * FROM $lp_item + WHERE c_id = $course_id AND id = $id"; $res_parent = Database::query($sql_parent); if (Database::num_rows($res_parent) > 0) { $row_parent = Database::fetch_array($res_parent); $parent = $row_parent['parent_item_id']; - $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent - ORDER BY display_order"; - $res_bros = Database::query($sql_bros); + $sql = "SELECT * FROM $lp_item + WHERE c_id = ".$course_id." AND parent_item_id = $parent + ORDER BY display_order"; + $res_bros = Database::query($sql); $list = []; while ($row_bro = Database::fetch_array($res_bros)) { $list[] = $row_bro; @@ -2037,7 +2061,7 @@ class learnpath if ($this->debug > 2) { error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type, 0); } - while (!empty ($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') AND $index < $this->max_ordered_items) { + while (!empty ($this->ordered_items[$index]) && ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') && $index < $this->max_ordered_items) { $index++; if ($index == $this->max_ordered_items) { if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') { @@ -2132,7 +2156,10 @@ class learnpath break; // Exit the foreach loop. } elseif ( preg_match('/aicc\//i', $thisContent['filename']) || - in_array(strtolower(pathinfo($thisContent['filename'], PATHINFO_EXTENSION)), array('crs', 'au', 'des', 'cst')) + in_array( + strtolower(pathinfo($thisContent['filename'], PATHINFO_EXTENSION)), + array('crs', 'au', 'des', 'cst') + ) ) { $ext = strtolower(pathinfo($thisContent['filename'], PATHINFO_EXTENSION)); switch ($ext) { @@ -2222,6 +2249,8 @@ class learnpath /** * Returns the HTML necessary to print a mediaplayer block inside a page + * @param int $lpItemId + * @param string $autostart * @return string The mediaplayer HTML */ public function get_mediaplayer($lpItemId, $autostart = 'true') @@ -3068,7 +3097,7 @@ class learnpath /** * Gets the learning path type as static method - * @param boolean Return the name? If false, return the ID. Default is false. + * @param int $lp_id * @return mixed Type ID or name, depending on the parameter */ public static function get_type_static($lp_id = 0) @@ -3096,7 +3125,7 @@ class learnpath * @param integer Parent ID of the items to look for * @return array Ordered list of item IDs (empty array on error) */ - public static function get_flat_ordered_items_list($lp, $parent = 0, $course_id = null) + public static function get_flat_ordered_items_list($lp, $parent = 0, $course_id = 0) { if (empty($course_id)) { $course_id = api_get_course_int_id(); @@ -3119,7 +3148,11 @@ class learnpath $res = Database::query($sql); while ($row = Database::fetch_array($res)) { - $sublist = self::get_flat_ordered_items_list($lp, $row['id'], $course_id); + $sublist = self::get_flat_ordered_items_list( + $lp, + $row['id'], + $course_id + ); $list[] = $row['id']; foreach ($sublist as $item) { $list[] = $item; @@ -3185,7 +3218,11 @@ class learnpath } $title = $item['title']; if (empty($title)) { - $title = self::rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']); + $title = self::rl_get_resource_name( + api_get_course_id(), + $this->get_id(), + $item['id'] + ); } $title = Security::remove_XSS($item['title']); @@ -3328,8 +3365,11 @@ class learnpath li.parameters as liparams FROM $lp_table l INNER JOIN $lp_item_table li - ON (li.lp_id = l.id AND l.c_id = $course_id AND li.c_id = $course_id ) - WHERE li.id = $item_id "; + ON (li.lp_id = l.id AND l.c_id = li.c_id) + WHERE + li.id = $item_id AND + li.c_id = $course_id AND + "; if ($this->debug > 2) { error_log('New LP - In learnpath::get_link() - selecting item '.$sql, 0); } @@ -3347,13 +3387,17 @@ class learnpath } $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path(); if ($type == 'http') { - $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path + //web path + $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); } else { $course_path = $sys_course_path; //system path } - // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc), then change the lp type to thread it as a normal Chamilo LP not a SCO. - if (in_array($lp_item_type, array('quiz', 'document', 'final_item', 'link', 'forum', 'thread', 'student_publication'))) { + // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc), + // then change the lp type to thread it as a normal Chamilo LP not a SCO. + if (in_array($lp_item_type, + array('quiz', 'document', 'final_item', 'link', 'forum', 'thread', 'student_publication')) + ) { $lp_type = 1; } @@ -3549,7 +3593,6 @@ class learnpath // some contents use this form: resource.htm?resource=http://blablabla // which means we have to find a protocol at the path's start, otherwise // it should not be considered as an external URL. - if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) { if ($this->debug > 2) { error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path, 0); @@ -3613,7 +3656,7 @@ class learnpath } $search = ''; // Use $attempt_num to enable multi-views management (disabled so far). - if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) { + if ($attempt_num != 0 && intval(strval($attempt_num)) == $attempt_num) { $search = 'AND view_count = '.$attempt_num; } // When missing $attempt_num, search for a unique lp_view record for this lp and user. @@ -3744,8 +3787,11 @@ class learnpath } $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $sql_sel = "SELECT * - FROM " . $tbl_lp_item." - WHERE c_id = ".$course_id." AND id = ".$id; + FROM $tbl_lp_item + WHERE + c_id = $course_id AND + id = $id + "; $res_sel = Database::query($sql_sel); // Check if elem exists. if (Database::num_rows($res_sel) < 1) { @@ -3830,7 +3876,8 @@ class learnpath error_log('Movement down detected', 0); } if ($next != 0) { - $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND id = $next"; + $sql_sel2 = "SELECT * FROM $tbl_lp_item + WHERE c_id = ".$course_id." AND id = $next"; if ($this->debug > 2) { error_log('Selecting next: '.$sql_sel2, 0); } @@ -3843,14 +3890,17 @@ class learnpath $next_next = $row2['next_item_id']; // Update previous item (switch with current). if ($previous != 0) { - $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next + $sql_upd2 = "UPDATE $tbl_lp_item + SET next_item_id = $next WHERE c_id = ".$course_id." AND id = $previous"; Database::query($sql_upd2); } // Update current item (switch with previous). if ($id != 0) { $sql_upd2 = "UPDATE $tbl_lp_item SET - previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 + previous_item_id = $next, + next_item_id = $next_next, + display_order = display_order + 1 WHERE c_id = ".$course_id." AND id = $id"; Database::query($sql_upd2); } @@ -3858,7 +3908,9 @@ class learnpath // Update next item (new previous item). if ($next != 0) { $sql_upd2 = "UPDATE $tbl_lp_item SET - previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 + previous_item_id = $previous, + next_item_id = $id, + display_order = display_order-1 WHERE c_id = ".$course_id." AND id = $next"; Database::query($sql_upd2); } @@ -4125,7 +4177,10 @@ class learnpath error_log('New LP - In learnpath::previous()', 0); } $this->last = $this->get_current_item_id(); - $this->items[$this->last]->save(false, $this->prerequisites_match($this->last)); + $this->items[$this->last]->save( + false, + $this->prerequisites_match($this->last) + ); $this->autocomplete_parents($this->last); $new_index = $this->get_previous_index(); $this->index = $new_index; @@ -4568,7 +4623,10 @@ class learnpath if (isset($this->items[$this->current]) && is_object($this->items[$this->current]) ) { - $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current)); + $res = $this->items[$this->current]->save( + false, + $this->prerequisites_match($this->current) + ); $this->autocomplete_parents($this->current); $status = $this->items[$this->current]->get_status(); $this->update_queue[$this->current] = $status; @@ -4597,7 +4655,9 @@ class learnpath if (empty($item_id)) { $item_id = $this->get_current_item_id(); } - if (isset($this->items[$item_id]) && is_object($this->items[$item_id])) { + if (isset($this->items[$item_id]) && + is_object($this->items[$item_id]) + ) { if ($debug) { error_log('Object exists'); } @@ -5585,7 +5645,8 @@ class learnpath error_log('New LP - In learnpath::set_seriousgame_mode()', 0); } $lp_table = Database::get_course_table(TABLE_LP_MAIN); - $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = ".$this->get_id(); + $sql = "SELECT * FROM $lp_table + WHERE c_id = ".$course_id." AND id = ".$this->get_id(); $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); @@ -5905,7 +5966,12 @@ class learnpath } } - $return_audio .= Display::span($icon.' '.$title).Display::tag('td', $audio, array('style'=>'')); + $return_audio .= Display::span($icon.' '.$title). + Display::tag( + 'td', + $audio, + array('style' => '') + ); $return_audio .= ''; $move_icon = ''; $move_item_icon = ''; @@ -5920,7 +5986,12 @@ class learnpath if (!$update_audio || $update_audio <> 'true') { if ($arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) { $move_icon .= ''; - $move_icon .= Display::return_icon('move_everywhere.png', get_lang('Move'), array(), ICON_SIZE_TINY); + $move_icon .= Display::return_icon( + 'move_everywhere.png', + get_lang('Move'), + array(), + ICON_SIZE_TINY + ); $move_icon .= ''; } } @@ -5929,7 +6000,12 @@ class learnpath if (!in_array($arrLP[$i]['item_type'], array('sco', 'asset', 'final_item'))) { if ($arrLP[$i]['item_type'] != 'dir') { $edit_icon .= ''; - $edit_icon .= Display::return_icon('edit.png', get_lang('LearnpathEditModule'), array(), ICON_SIZE_TINY); + $edit_icon .= Display::return_icon( + 'edit.png', + get_lang('LearnpathEditModule'), + array(), + ICON_SIZE_TINY + ); $edit_icon .= ''; if (!in_array($arrLP[$i]['item_type'], ['forum', 'thread'])) { @@ -6077,7 +6153,12 @@ class learnpath ); } $audio_icon = Display::url( - Display::return_icon('audio.png', get_lang('UplUpload'), array(), ICON_SIZE_TINY), + Display::return_icon( + 'audio.png', + get_lang('UplUpload'), + array(), + ICON_SIZE_TINY + ), $url.'&action=add_audio', ['class' => 'btn btn-default'] ); @@ -6148,7 +6229,11 @@ class learnpath } $list = '