$sql_del_view = "DELETE FROM $lp_item_view WHERE c_id = $course_id AND lp_item_id = ".$this->db_id;
//error_log('New LP - Deleting from lp_item_view: '.$sql_del_view, 0);
$res_del_view = Database::query($sql_del_view);
if (self::debug > 0) { error_log('Deleting from lp_item_view: '.$sql_del_view, 0); }
Database::query($sql_del_view);
$sql_sel = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
$res_sel = Database::query($sql_sel);
if (Database::num_rows($res_sel) <1){returnfalse;}
$row = Database::fetch_array($res_sel);
$sql_del_item = "DELETE FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
//error_log('New LP - Deleting from lp_item: '.$sql_del_view, 0);
$res_del_item = Database::query($sql_del_item);
if (Database::num_rows($res_sel) <1){
return false;
}
$sql_del_item = "DELETE FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
Database::query($sql_del_item);
if (self::debug > 0) { error_log('Deleting from lp_item: '.$sql_del_view); }
if (api_get_setting('search_enabled') == 'true') {
if (!is_null($this->search_did)) {
@ -245,7 +246,6 @@ class learnpathItem {
$di->remove_document($this->search_did);
}
}
return true;
}
@ -255,7 +255,7 @@ class learnpathItem {
* @return void
*/
public function drop_child($item) {
if (self::debug > 0) { error_log('New LP - In learnpathItem::drop_child()', 0); }
if (self::debug > 0) { error_log('learnpathItem::drop_child()', 0); }
if (!empty($item)) {
foreach ($this->children as $index => $child) {
if ($child == $item) {
@ -270,7 +270,7 @@ class learnpathItem {
* @return integer The attempt_id for this item view by this user, or 1 if none defined
*/
public function get_attempt_id() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_attempt_id() on item '.$this->db_id, 0); }
if (self::debug > 0) { error_log('learnpathItem::get_attempt_id() on item '.$this->db_id, 0); }
$res = 1;
if (!empty($this->attempt_id)) {
$res = $this->attempt_id;
@ -284,7 +284,7 @@ class learnpathItem {
* @return array Array of children items IDs
*/
public function get_children() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_children()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_children()', 0); }
$list = array();
foreach ($this->children as $child) {
if (!empty($child)) {
@ -308,7 +308,7 @@ class learnpathItem {
* @return string 'credit' or 'no-credit'. Defaults to 'credit' because if we don't know enough about this item, it's probably because it was never used before.
*/
public function get_credit() {
if (self::debug > 1) {error_log('New LP - In learnpathItem::get_credit()', 0); }
if (self::debug > 1) {error_log('learnpathItem::get_credit()', 0); }
$credit = 'credit';
// Now check the value of prevent_reinit (if it's 0, return credit as the default was).
if ($this->get_prevent_reinit() != 0) { // If prevent_reinit == 1 (or more).
@ -316,11 +316,13 @@ class learnpathItem {
// Check the status in the database rather than in the object, as checking in the object
// would always return "no-credit" when we want to set it to completed.
$status = $this->get_status(true);
if (self::debug > 2) { error_log('New LP - In learnpathItem::get_credit() - get_prevent_reinit!=0 and status is '.$status, 0); }
if (self::debug > 2) { error_log('learnpathItem::get_credit() - get_prevent_reinit!=0 and status is '.$status, 0); }
//0=not attempted - 1 = incomplete
if ($status != $this->possible_status[0] && $status != $this->possible_status[1]) {
$credit = 'no-credit';
}
}
if (self::debug > 1) {error_log("learnpathItem::get_credit() returns: $credit"); }
return $credit;
}
@ -329,7 +331,7 @@ class learnpathItem {
* @return integer Current start time, or current time if none
*/
public function get_current_start_time() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_current_start_time()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_current_start_time()', 0); }
if (empty($this->current_start_time)) {
return time();
} else {
@ -342,7 +344,7 @@ class learnpathItem {
* @return string Description
*/
public function get_description() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_description()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_description()', 0); }
if (empty($this->description)) { return ''; }
return $this->description;
}
@ -353,7 +355,7 @@ class learnpathItem {
*/
public function get_file_path($path_to_scorm_dir = '') {
$course_id = api_get_course_int_id();
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_file_path()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_file_path()', 0); }
$path = $this->get_path();
$type = $this->get_type();
if (empty($path)) {
@ -397,7 +399,7 @@ class learnpathItem {
* @return integer Database ID for the current item
*/
public function get_id() {
if (self::debug > 1) {error_log('New LP - In learnpathItem::get_id()', 0); }
if (self::debug > 1) {error_log('learnpathItem::get_id()', 0); }
if (!empty($this->db_id)) {
return $this->db_id;
}
@ -439,7 +441,7 @@ class learnpathItem {
* @return int The current number of interactions recorder
*/
public function get_interactions_count($checkdb = false) {
if (self::debug > 1) { error_log('New LP - In learnpathItem::get_interactions_count()', 0); }
if (self::debug > 1) { error_log('learnpathItem::get_interactions_count()', 0); }
$return = 0;
$course_id = api_get_course_int_id();
@ -494,7 +496,7 @@ class learnpathItem {
* @return int The current number of objectives recorder
*/
public function get_objectives_count() {
if (self::debug > 1) { error_log('New LP - In learnpathItem::get_objectives_count()', 0);}
if (self::debug > 1) { error_log('learnpathItem::get_objectives_count()', 0);}
$res = 0;
if (!empty($this->objectives_count)) {
$res = $this->objectives_count;
@ -507,7 +509,7 @@ class learnpathItem {
* @return string Launch data as found in imsmanifest and stored in Chamilo (read only). Defaults to ''.
*/
public function get_launch_data() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_launch_data()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_launch_data()', 0); }
if (!empty($this->launch_data)) {
return $this->launch_data;
}
@ -519,7 +521,7 @@ class learnpathItem {
* @return string lesson location as recorded by the SCORM and AICC elements. Defaults to ''
*/
public function get_lesson_location() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_lesson_location()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_lesson_location()', 0); }
if (self::debug > 2) { error_log('New LP - In learnpathItem::get_scorm_time(): given time empty, current_start_time = '.$this->current_start_time, 0); }
if (self::debug > 2) { error_log('learnpathItem::get_scorm_time(): given time empty, current_start_time = '.$this->current_start_time, 0); }
if (self::debug > 2) { error_log('New LP - In learnpathItem::get_scorm_time('.$scorm_time.')', 0); }
if (self::debug > 2) { error_log('learnpathItem::get_scorm_time('.$scorm_time.')', 0); }
return $scorm_time;
}
@ -1104,7 +1106,7 @@ class learnpathItem {
* @return string Title
*/
public function get_title() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_title()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_title()', 0); }
if (empty($this->title)) { return ''; }
return $this->title;
}
@ -1114,7 +1116,7 @@ class learnpathItem {
* @return integer Total time
*/
public function get_total_time() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_total_time()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_total_time()', 0); }
if ($this->current_start_time == 0) { // Shouldn't be necessary thanks to the open() method.
$this->current_start_time = time();
}
@ -1128,7 +1130,7 @@ class learnpathItem {
if ($time <0){
return 0;
} else {
if (self::debug > 2) { error_log('New LP - In learnpathItem::get_total_time() - Current stop time = '.$this->current_stop_time.', current start time = '.$this->current_start_time.' Returning '.$time, 0); }
if (self::debug > 2) { error_log('learnpathItem::get_total_time() - Current stop time = '.$this->current_stop_time.', current start time = '.$this->current_start_time.' Returning '.$time, 0); }
return $time;
}
}
@ -1142,7 +1144,7 @@ class learnpathItem {
if (!empty($this->type)) {
$res = $this->type;
}
if (self::debug > 2) { error_log('New LP - In learnpathItem::get_type() - Returning '.$res.' for item '.$this->db_id, 0); }
if (self::debug > 2) { error_log('learnpathItem::get_type() - Returning '.$res.' for item '.$this->db_id, 0); }
return $res;
}
@ -1151,7 +1153,7 @@ class learnpathItem {
* @return int Number of attempts or 0
*/
public function get_view_count() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::get_view_count()', 0); }
if (self::debug > 0) { error_log('learnpathItem::get_view_count()', 0); }
if (!empty($this->attempt_id)) {
return $this->attempt_id;
} else {
@ -1165,10 +1167,10 @@ class learnpathItem {
*/
function is_done(){
if ($this->status_is(array('completed', 'passed', 'succeeded', 'failed'))) {
if (self::debug > 2) { error_log('New LP - In learnpath::is_done() - Item '.$this->get_id().' is complete', 0); }
if (self::debug > 2) { error_log('learnpath::is_done() - Item '.$this->get_id().' is complete', 0); }
return true;
}else{
if (self::debug > 2) { error_log('New LP - In learnpath::is_done() - Item '.$this->get_id().' is not complete', 0); }
if (self::debug > 2) { error_log('learnpath::is_done() - Item '.$this->get_id().' is not complete', 0); }
return false;
}
}
@ -1180,7 +1182,7 @@ class learnpathItem {
* 1 if it is allowed. Defaults to 1
*/
public function is_restart_allowed() {
if (self::debug > 2) { error_log('New LP - In learnpathItem::is_restart_allowed()', 0); }
if (self::debug > 2) { error_log('learnpathItem::is_restart_allowed()', 0); }
$restart = 1;
$mystatus = $this->get_status(true);
if ($this->get_prevent_reinit() > 0){ // If prevent_reinit == 1 (or more)
@ -1204,7 +1206,7 @@ class learnpathItem {
* @return boolean True on success, false on failure.
*/
public function open($allow_new_attempt = false) {
if (self::debug > 0) { error_log('New LP - In learnpathItem::open()', 0); }
if (self::debug > 0) { error_log('learnpathItem::open()', 0); }
if ($this->prevent_reinit == 0) {
$this->current_score = 0;
$this->current_start_time = time();
@ -1239,7 +1241,7 @@ class learnpathItem {
* @return string HTML file (displayable in an <iframe>) or empty string if no path defined
*/
function output() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::output()', 0); }
if (self::debug > 0) { error_log('learnpathItem::output()', 0); }
if (!empty($this->path) and is_file($this->path)) {
$output = '';
$output .= file_get_contents($this->path);
@ -1257,7 +1259,7 @@ class learnpathItem {
* @return boolean True if the list of prerequisites given is entirely satisfied, false otherwise
*/
public function parse_prereq($prereqs_string, $items, $refs_list, $user_id) {
if (self::debug > 0) { error_log('New LP - In learnpathItem::parse_prereq() for learnpath '.$this->lp_id.' with string '.$prereqs_string, 0); }
if (self::debug > 0) { error_log('learnpathItem::parse_prereq() for learnpath '.$this->lp_id.' with string '.$prereqs_string, 0); }
$course_id = api_get_course_int_id();
// Deal with &, |, ~, =, <>, {}, ,, X*, () in reverse order.
@ -1644,7 +1646,7 @@ class learnpathItem {
* @return boolean True on success, false otherwise
*/
public function restart() {
if (self::debug > 0) { error_log('New LP - In learnpathItem::restart()', 0); }
if (self::debug > 0) { error_log('learnpathItem::restart()', 0); }
if ($this->type == 'sco') { //If this is a sco, chamilo can't update the time without explicit scorm call
$this->current_start_time = 0;
$this->current_stop_time = 0; //Those 0 value have this effect
@ -1699,59 +1701,57 @@ class learnpathItem {
* @return boolean True on success, false on failure
*/
public function save($from_outside = true, $prereqs_complete = false) {
if (self::debug > 0) { error_log('New LP - In learnpathItem::save()', 0); }
// If mastery_score is set AND the current score reaches the mastery score AND the current status is different from 'completed', then set it to 'passed'.
$sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".api_get_user_id()."' ORDER BY login_date DESC LIMIT 0,1";