diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 0f997f0bd0..76e3a641de 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -77,8 +77,6 @@ class learnpath public $course_int_id; public $course_info = array(); - - /** * Get the depth level of LP item * @param $in_tab_items @@ -95,7 +93,6 @@ 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. @@ -201,9 +198,13 @@ class learnpath $lp_table = Database::get_course_table(TABLE_LP_VIEW); // Selecting by view_count descending allows to get the highest view_count first. - $sql = "SELECT * FROM $lp_table WHERE c_id = $course_id AND lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC"; + $sql = "SELECT * FROM $lp_table + WHERE c_id = $course_id AND lp_id = '$lp_id' AND user_id = '$user_id' $session + ORDER BY view_count DESC"; $res = Database::query($sql); - if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); } + if ($this->debug > 2) { + error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); + } if (Database :: num_rows($res) > 0) { if ($this->debug > 2) { @@ -220,9 +221,10 @@ class learnpath error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0); } $this->attempt = 1; - $sql_ins = "INSERT INTO $lp_table (c_id, lp_id, user_id, view_count, session_id) VALUES ($course_id, $lp_id, $user_id, 1, $session_id)"; - $res_ins = Database::query($sql_ins); - $this->lp_view_id = Database :: insert_id(); + $sql_ins = "INSERT INTO $lp_table (c_id, lp_id, user_id, view_count, session_id) + VALUES ($course_id, $lp_id, $user_id, 1, $session_id)"; + Database::query($sql_ins); + $this->lp_view_id = Database::insert_id(); if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0); } @@ -230,7 +232,9 @@ class learnpath // Initialise items. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM); - $sql = "SELECT * FROM $lp_item_table WHERE c_id = $course_id AND lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order"; + $sql = "SELECT * FROM $lp_item_table + WHERE c_id = $course_id AND lp_id = '".$this->lp_id."' + ORDER BY parent_item_id, display_order"; $res = Database::query($sql); if ($this->debug > 2) { diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index 73af6a7908..a1bbcff396 100644 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -65,20 +65,25 @@ class learnpathItem const debug = 0; // Logging parameter. /** - * Class constructor. Prepares the learnpath_item for later launch + * Prepares the learnpath_item for later launch * * Don't forget to use set_lp_view() if applicable after creating the item. * Setting an lp_view will finalise the item_view data collection * @param integer Learnpath item ID * @param integer User ID * @param integer course int id + * @param array $item_content * @return boolean True on success, false on failure */ public function __construct($id, $user_id = null, $course_id = null, $item_content = null) { // Get items table. - if (!isset($user_id)) { $user_id = api_get_user_id(); } - if (self::debug > 0) { error_log("learnpathItem constructor: id: $id user_id: $user_id course_id: $course_id item_content: $item_content", 0); } + if (!isset($user_id)) { + $user_id = api_get_user_id(); + } + if (self::debug > 0) { + error_log("learnpathItem constructor: id: $id user_id: $user_id course_id: $course_id item_content: $item_content", 0); + } $id = intval($id); if (empty($item_content)) { @@ -89,7 +94,6 @@ class learnpathItem $course_id = intval($course_id); } $sql = "SELECT * FROM $items_table WHERE c_id = $course_id AND id = $id"; - //error_log('New LP - Creating item object from DB: '.$sql, 0); $res = Database::query($sql); if (Database::num_rows($res) < 1) { $this->error = 'Could not find given learnpath item in learnpath_item table'; @@ -116,11 +120,13 @@ class learnpathItem $this->display_order = $row['display_order']; $this->prereq_string = $row['prerequisite']; $this->max_time_allowed = $row['max_time_allowed']; + if (isset($row['launch_data'])){ $this->launch_data = $row['launch_data']; } $this->save_on_close = true; $this->db_id = $id; + //$this->seriousgame_mode = $this->get_seriousgame_mode(); $this->seriousgame_mode = 0; @@ -1835,7 +1841,8 @@ class learnpathItem * @param integer Level * @return void */ - public function set_level($int = 0) { + public function set_level($int = 0) + { if (self::debug > 0) { error_log('learnpathItem::set_level('.$int.')', 0); } if (!empty($int) AND $int == strval(intval($int))) { $this->level = $int; } } @@ -1843,6 +1850,7 @@ class learnpathItem /** * Sets the lp_view id this item view is registered to * @param integer lp_view DB ID + * @param int $course_id * @return void * @todo //todo insert into lp_item_view if lp_view not exists */ @@ -1853,6 +1861,9 @@ class learnpathItem } else { $course_id = intval($course_id); } + + $lpItemId = $this->get_id(); + if (self::debug > 0) { error_log('learnpathItem::set_lp_view('.$lp_view_id.')', 0); } if (!empty($lp_view_id) and $lp_view_id = intval(strval($lp_view_id))) { $this->view_id = $lp_view_id; @@ -1861,7 +1872,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 - lp_item_id = ".$this->get_id()." AND + lp_item_id = ".$lpItemId." AND lp_view_id = ".$lp_view_id." ORDER BY view_count DESC"; @@ -1879,6 +1890,7 @@ class learnpathItem $this->current_stop_time = $this->current_start_time + $row['total_time']; $this->lesson_location = $row['lesson_location']; $this->core_exit = $row['core_exit']; + if (self::debug > 2) { error_log('learnpathItem::set_lp_view() - Updated item object with database values', 0); } // Now get the number of interactions for this little guy.