diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 3e9757af7a..5d5ddc238e 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -79,9 +79,9 @@ class learnpath /** * Class constructor. Needs a database handler, a course code and a learnpath id from the database. * Also builds the list of items into $this->items. - * @param string Course code - * @param integer Learnpath ID - * @param integer User ID + * @param string $course Course code + * @param integer $lp_id + * @param integer $user_id * @return boolean True on success, false on error */ public function __construct($course, $lp_id, $user_id) @@ -2306,14 +2306,14 @@ class learnpath return $output; } - /** * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements * @param integer Additional steps to fake as completed * @return list Percentage or number and symbol (% or /xx) */ - public function get_progress_bar_text($mode = '', $add = 0) { + public function get_progress_bar_text($mode = '', $add = 0) + { if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar_text()', 0); } @@ -2346,12 +2346,11 @@ class learnpath } $percentage = number_format($percentage, 0); $text = '%'; - } - elseif ($mode == 'abs') { + } elseif ($mode == 'abs') { $percentage = $i; $text = '/' . $total_items; } - return array ( + return array( $percentage, $text ); @@ -4019,11 +4018,12 @@ class learnpath /** * Saves the given item - * @param integer Item ID. Optional (will take from $_REQUEST if null) - * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true + * @param integer $item_id. Optional (will take from $_REQUEST if null) + * @param boolean $from_outside Save from url params (true) or from current attributes (false). Optional. Defaults to true * @return boolean */ - public function save_item($item_id = null, $from_outside = true) { + public function save_item($item_id = null, $from_outside = true) + { $debug = $this->debug; if ($debug) { error_log('In learnpath::save_item(' . $item_id . ',' . intval($from_outside). ')', 0); diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index f731be7a1f..00ebc3018f 100755 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -1668,9 +1668,9 @@ class learnpathItem /** * Gets the item status - * @param boolean Do or don't check into the database for the latest value. Optional. Default is true - * @param boolean Do or don't update the local attribute value with what's been found in DB - * @return string Current status or 'Not attempted' if no status set yet + * @param boolean $check_db Do or don't check into the database for the latest value. Optional. Default is true + * @param boolean $update_local Do or don't update the local attribute value with what's been found in DB + * @return string Current status or 'Not attempted' if no status set yet */ public function get_status($check_db = true, $update_local = false) { @@ -1684,8 +1684,11 @@ class learnpathItem } if (!empty($this->db_item_view_id)) { $table = Database::get_course_table(TABLE_LP_ITEM_VIEW); - $sql = "SELECT status FROM $table WHERE c_id = $course_id AND id = '" . $this->db_item_view_id . "' AND view_count = '" . $this->get_attempt_id( - ) . "'"; + $sql = "SELECT status FROM $table + WHERE + c_id = $course_id AND + id = '" . $this->db_item_view_id . "' AND + view_count = '" . $this->get_attempt_id() . "'"; if (self::debug > 2) { error_log( 'learnpathItem::get_status() - Checking DB: ' . $sql, @@ -3131,8 +3134,9 @@ class learnpathItem TABLE_LP_IV_INTERACTION ); $sql = "SELECT * FROM $item_view_interaction_table - WHERE c_id = $course_id - AND lp_iv_id = '" . $this->db_item_view_id . "'"; + WHERE + c_id = $course_id AND + lp_iv_id = '" . $this->db_item_view_id . "'"; //error_log('sql10->'.$sql); $res = Database::query($sql); if ($res !== false) { @@ -3145,8 +3149,9 @@ class learnpathItem TABLE_LP_IV_OBJECTIVE ); $sql = "SELECT * FROM $item_view_objective_table - WHERE c_id = $course_id - AND lp_iv_id = '" . $this->db_item_view_id . "'"; + WHERE + c_id = $course_id AND + lp_iv_id = '" . $this->db_item_view_id . "'"; //error_log('sql11->'.$sql); $res = Database::query($sql); if ($res !== false) { @@ -3265,21 +3270,22 @@ class learnpathItem /** * Sets the status for this item - * @param string Status - must be one of the values defined in $this->possible_status - * @return boolean True on success, false on error + * @param string $status must be one of the values defined in $this->possible_status + * @return boolean True on success, false on error */ public function set_status($status) { if (self::debug > 0) { error_log('learnpathItem::set_status(' . $status . ')', 0); } + $found = false; foreach ($this->possible_status as $possible) { if (preg_match('/^' . $possible . '$/i', $status)) { $found = true; } } - //if (in_array($status, $this->possible_status)) { + if ($found) { $this->status = Database::escape_string($status); if (self::debug > 1) { @@ -3292,8 +3298,9 @@ class learnpathItem } return true; } - //error_log('New LP - '.$status.' was not in the possible status', 0); + $this->status = $this->possible_status[0]; + return false; } @@ -3319,14 +3326,15 @@ class learnpathItem } $new_terms = $a_terms; $new_terms_string = implode(',', $new_terms); - $terms_update_sql = ''; + // TODO: Validate csv string. $terms = Database::escape_string(api_htmlentities($new_terms_string, ENT_QUOTES, $charset)); - $terms_update_sql = "UPDATE $lp_item + $sql = "UPDATE $lp_item SET terms = '$terms' - WHERE c_id = $course_id - AND id=" . $this->get_id(); - $res = Database::query($terms_update_sql); + WHERE + c_id = $course_id AND + id=" . $this->get_id(); + Database::query($sql); // Save it to search engine. if (api_get_setting('search_enabled') == 'true') { $di = new ChamiloIndexer(); diff --git a/main/newscorm/lp_controller.php b/main/newscorm/lp_controller.php index 575c2abee8..e28fee80b3 100755 --- a/main/newscorm/lp_controller.php +++ b/main/newscorm/lp_controller.php @@ -355,6 +355,7 @@ if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $ $_SESSION['oLP'] = $oLP; } } + if ($debug > 0) error_log('New LP - Passed oLP creation check', 0); $is_allowed_to_edit = api_is_allowed_to_edit(false, true, false, false);