From 35584a9f7f26f8e3a378072a022d7159d985b95d Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Sat, 15 Dec 2007 04:59:40 +0100 Subject: [PATCH] [svn r13990] Fixed another bug in prerequisites whereby using the "next" button could force an item with incompleted prerequisites to show. See http://www.dokeos.com/forum/viewtopic.php?p=40032#40032 --- main/newscorm/learnpath.class.php | 17 ++++++++--------- main/newscorm/learnpathItem.class.php | 13 ++++++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 318b66a4fa..f7771f5f74 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -665,7 +665,7 @@ class learnpath { if($completed == true) { //if all the children were completed $parent->set_status('completed'); - $parent->save(false); + $parent->save(false,$this->prerequisites_match($parent->get_id())); $this->update_queue[$parent->get_id()] = $parent->get_status(); if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);} $this->autocomplete_parents($parent->get_id()); //recursive call @@ -2996,7 +2996,7 @@ class learnpath { { if($this->debug>0){error_log('New LP - In learnpath::next()',0);} $this->last = $this->get_current_item_id(); - $this->items[$this->last]->save(false); + $this->items[$this->last]->save(false,$this->prerequisites_match($this->last)); $this->autocomplete_parents($this->last); $new_index = $this->get_next_index(); if($this->debug>2){error_log('New LP - New index: '.$new_index,0);} @@ -3069,7 +3069,7 @@ class learnpath { { if($this->debug>0){error_log('New LP - In learnpath::previous()',0);} $this->last = $this->get_current_item_id(); - $this->items[$this->last]->save(false); + $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; @@ -3188,7 +3188,8 @@ class learnpath { if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);} if($this->debug>2){error_log(''.print_r($this->items,true),0);} if(is_object($this->items[$this->current])){ - $res = $this->items[$this->current]->save(false); + //$res = $this->items[$this->current]->save(false); + $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->append_message('new_item_status: '.$status); @@ -3216,7 +3217,8 @@ class learnpath { } if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);} if(is_object($this->items[$item_id])){ - $res = $this->items[$item_id]->save($from_outside); + $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id)); + //$res = $this->items[$item_id]->save($from_outside); $this->autocomplete_parents($item_id); $status = $this->items[$item_id]->get_status(); $this->append_message('new_item_status: '.$status); @@ -3470,10 +3472,7 @@ class learnpath { $this->autocomplete_parents($this->current); $prereq_check = $this->prerequisites_match($this->current); - if($prereq_check === true) //launch the prerequisites check and set error if needed - { - $this->items[$this->current]->save(false); - } + $this->items[$this->current]->save(false,$prereq_check); //$this->update_queue[$this->last] = $this->items[$this->last]->get_status(); }else{ //if sco, then it is supposed to have been updated by some other call diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index e24189ba1d..02c0018836 100644 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -1519,9 +1519,10 @@ class learnpathItem{ /** * Saves data in the database * @param boolean Save from URL params (1) or from object attributes (0) + * @param boolean The results of a check on prerequisites for this item. True if prerequisites are completed, false otherwise. Defaults to false. Only used if not sco or au * @return boolean True on success, false on failure */ - function save($from_outside=true) + function save($from_outside=true,$prereqs_complete=false) { if($this->debug>0){error_log('New LP - In learnpathItem::save()',0);} @@ -1609,7 +1610,10 @@ class learnpathItem{ $type = strtolower($this->type); switch($type){ case 'asset': - $this->set_status($this->possible_status[2]); + if($prereqs_complete) + { + $this->set_status($this->possible_status[2]); + } break; case TOOL_HOTPOTATOES: break; @@ -1618,7 +1622,10 @@ class learnpathItem{ default: //for now, everything that is not sco and not asset is set to //completed when saved - $this->set_status($this->possible_status[2]); + if($prereqs_complete) + { + $this->set_status($this->possible_status[2]); + } break; } }