From 557a5ae4084797e1f59b0bb42c99be3e0fb60309 Mon Sep 17 00:00:00 2001 From: Noel Dieschburg Date: Wed, 6 Jul 2011 11:10:28 +0200 Subject: [PATCH] SCORM attempts : adds a seriousgame mode flag to lp --- main/img/gamepad.gif | Bin 0 -> 1106 bytes main/inc/lib/add_course.lib.inc.php | 3 +- main/install/migrate-db-1.8.6.2-1.8.7-pre.sql | 2 + main/newscorm/learnpath.class.php | 134 ++++++++++++++++++ main/newscorm/learnpathItem.class.php | 50 ++++++- main/newscorm/learnpathList.class.php | 1 + main/newscorm/lp_controller.php | 16 +++ main/newscorm/lp_list.php | 35 +++-- 8 files changed, 221 insertions(+), 20 deletions(-) create mode 100644 main/img/gamepad.gif diff --git a/main/img/gamepad.gif b/main/img/gamepad.gif new file mode 100644 index 0000000000000000000000000000000000000000..81a0c0ec9fffe6dd61abc924a3a4c5ec45231ece GIT binary patch literal 1106 zcmdthk5iHd9LMnoN1W9*-F55QYMyzuU0%CuciSDU?QW%lkE!`1b6fM$g+rKa{)lPa zn(}~n>S^|49i46x4n_=Wgq&g%MHHB40%{06&m#{!umJN%{z6l8kL|zM>)zkbfAFP) zH0sfU-N0_(Nf$s%NT4SrCDUjioeqLv3J9j9rKP8*XJ%z(=e(4gd-mM9yn+G-gOSht zhRI}BekEbBSS&WXu(k{r!D?dP1Mx{=jTD8q8XgdB|We4GbBL z29wG3$Y|Hudb@3-BO@ag%Oi`0Sj*p|L*_BN%{FQrw;SyfgA)$NnA6Pa+LPN&o5vLP-j;&Q{V8-a=SIZzlyut@~NVK<7R2#TSoXOd{r z>n3u0-Iy1{d>+h)c?fQg$LICCc`u#q_6GA9J6bJ+ZAv_ce z1p~p*R45dBIyE&tJv}osJv%!)H#hg}+5G%Gaf=HJ3yWKp7nlCCyu7?bTsXWG4u@A( zR#vw>Ut1$uTVG$_*x1oxHw_nxZzYu}e;(SqyQT?~Ew!JzTl`^7VR zQcg4jjj1v=$kFV`d5>B(+@<0%ji0@C`#a6`HyfVb%@oEQj5|;i_0Hiaa#IE;iE=fm z5X@uqW!BhFzqdx-IdUXLxbv;Ju9ed%yV_6uG=Fn7ZXhB8`ug%|z(%ThJG1fm@X>_< z0hvV67CEb-ZM7eXA|%`_@o`ekv3P%^N<4VrR4f`2XXFVJ#Xi0ssM~yZuh~gH d)O3@AZHxIl`n|fC<<_`b> literal 0 HcmV?d00001 diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index ed6e808329..79054bb2b2 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -1208,7 +1208,8 @@ function update_Db_course($courseDbName, $language = null) "author varchar(255) not null default '', " . //stores the theme of the LP "session_id int unsigned not null default 0, " . //the session_id "prerequisite int unsigned not null default 0," . // pre requisite for next lp - "hide_toc_frame tinyint NOT NULL DEFAULT 0". + "hide_toc_frame tinyint NOT NULL DEFAULT 0,". + "seriousgame_mode tinyint NOT NULL DEFAULT 0". ")" . $charset_clause; if(!Database::query($sql)) { diff --git a/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql b/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql index f120b9525a..e1d688255d 100644 --- a/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql +++ b/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql @@ -216,6 +216,8 @@ ALTER TABLE lp ADD prerequisite int unsigned NOT NULL DEFAULT 0; ALTER TABLE student_publication MODIFY COLUMN description TEXT DEFAULT NULL; ALTER TABLE student_publication ADD COLUMN user_id INTEGER NOT NULL AFTER session_id; INSERT INTO course_setting(variable,value,category) VALUES ('email_alert_students_on_new_homework',0,'work'); +-- CBlue custom ALTER TABLE lp ADD COLUMN hide_toc_frame TINYINT NOT NULL DEFAULT 0; +ALTER TABLE lp ADD COLUMN seriousgame_mode TINYINT NOT NULL DEFAULT 0; alter table lp_item_view modify column suspend_data longtext; diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 70d4272a5a..c5caf7b98b 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -47,6 +47,9 @@ class learnpath { // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1) public $prevent_reinit = 1; + // Set KTM mode for scorm lp + public $seriousgame_mode = 0; + // Describes the mode of progress bar display public $progress_bar_mode = '%'; @@ -127,6 +130,7 @@ class learnpath { $this->theme = $row['theme']; $this->maker = $row['content_maker']; $this->prevent_reinit = $row['prevent_reinit']; + $this->seriousgame_mode = $row['seriousgame_mode']; $this->license = $row['content_license']; $this->scorm_debug = $row['debug']; $this->js_lib = $row['js_lib']; @@ -4212,6 +4216,136 @@ class learnpath { } return -1; } + + /** + * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag + * + * @return string 'single', 'multi' or 'seriousgame' + * @author ndiechburg + **/ + public function get_attempt_mode() + { + if (!isset($this->seriousgame_mode)) { //Set default value for seriousgame_mode + $this->seriousgame_mode=0; + } + if (!isset($this->prevent_reinit)) { // Set default value for prevent_reinit + $this->prevent_reinit =1; + } + if ($this->seriousgame_mode == 1 && $this->prevent_reinit == 1) { + return 'seriousgame'; + } + if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 1) { + return 'single'; + } + if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 0) { + return 'multiple'; + } + return 'single'; + } + + /** + * Register the attempt mode into db thanks to flags prevent_reinit and seriousgame_mode flags + * + * @param string 'seriousgame', 'single' or 'multiple' + * @return boolean + * @author ndiechburg + **/ + public function set_attempt_mode($mode) + { + switch ($mode) { + case 'seriousgame' : + $sg_mode = 1; + $prevent_reinit = 1; + break; + case 'single' : + $sg_mode = 0; + $prevent_reinit = 1; + break; + case 'multiple' : + $sg_mode = 0; + $prevent_reinit = 0; + break; + default : + $sg_mode = 0; + $prevent_reinit = 0; + break; + } + $this->prevent_reinit = $prevent_reinit; + $this->seriousgame_mode = $sg_mode; + $lp_table = Database :: get_course_table(TABLE_LP_MAIN); + $sql = "UPDATE $lp_table SET prevent_reinit = $prevent_reinit , seriousgame_mode = $sg_mode WHERE id = " . $this->get_id(); + $res = Database::query($sql); + if ($res) { + return true; + } + else { + return false; + } + } + + /** + * switch between multiple attempt, single attempt or serious_game mode (only for scorm) + * + * @return boolean + * @author ndiechburg + **/ + public function switch_attempt_mode() + { + if ($this->debug > 0) { + error_log('New LP - In learnpath::switch_attempt_mode()', 0); + } + $mode = $this->get_attempt_mode(); + switch ($mode) { + case 'single' : + $next_mode = 'multiple'; + break; + case 'multiple' : + $next_mode = 'seriousgame'; + break; + case 'seriousgame' : + $next_mode = 'single'; + break; + default : + $next_mode = 'single'; + break; + } + $this->set_attempt_mode($next_mode); + } + + /** + * Swithc the lp in ktm mode. This is a special scorm mode with unique attempt but possibility to do again a completed item. + * + * @return boolean true if seriousgame_mode has been set to 1, false otherwise + * @author ndiechburg + **/ + public function set_seriousgame_mode() + { + if ($this->debug > 0) { + 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 id = " . $this->get_id(); + $res = Database::query($sql); + if (Database :: num_rows($res) > 0) { + $row = Database :: fetch_array($res); + $force = $row['seriousgame_mode']; + if ($force == 1) { + $force = 0; + } elseif ($force == 0) { + $force = 1; + } + $sql = "UPDATE $lp_table SET seriousgame_mode = $force WHERE id = " . $this->get_id(); + $res = Database::query($sql); + $this->seriousgame_mode = $force; + return $force; + } else { + if ($this->debug > 2) { + error_log('New LP - Problem in set_seriousgame_mode() - could not find LP ' . $this->get_id() . ' in DB', 0); + } + } + return -1; + + } /** * Updates the "scorm_debug" value that shows or hide the debug window * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case) diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index 33bf54674b..cc3336b532 100644 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -47,6 +47,7 @@ class learnpathItem { public $prereqs = array(); public $previous; public $prevent_reinit = 1; // 0 = multiple attempts 1 = one attempt + public $seriousgame_mode; public $ref; public $save_on_close = true; public $search_did = NULL; @@ -101,6 +102,7 @@ class learnpathItem { } $this->save_on_close = true; $this->db_id = $id; + $this->seriousgame_mode = $this->get_seriousgame_mode(); // get search_did if (api_get_setting('search_enabled')=='true') { @@ -644,6 +646,37 @@ class learnpathItem { if(self::debug>2){error_log('New LP - End of learnpathItem::get_prevent_reinit() - Returned '.$this->prevent_reinit,0);} return $this->prevent_reinit; } + /** + * Returns 1 if seriousgame_mode is activated, 0 otherwise + * + * @return int (0 or 1) + * @author ndiechburg + **/ + public function get_seriousgame_mode() + { + if(self::debug>2){error_log('New LP - In learnpathItem::get_seriousgame_mode()',0);} + if(!isset($this->seriousgame_mode)){ + if(!empty($this->lp_id)){ + $db = Database::get_course_table(TABLE_LP_MAIN); + $sql = "SELECT * FROM $db WHERE id = ".$this->lp_id; + $res = @Database::query($sql); + if(Database::num_rows($res)<1) + { + $this->error = "Could not find parent learnpath in learnpath table"; + if(self::debug>2){error_log('New LP - End of learnpathItem::get_seriousgame_mode() - Returning false',0);} + return false; + }else{ + $row = Database::fetch_array($res); + $this->seriousgame_mode = $row['seriousgame_mode']; + } + }else{ + $this->seriousgame_mode = 0; //KTM mode is always off by default + } + } + if(self::debug>2){error_log('New LP - End of learnpathItem::get_seriousgame_mode() - Returned '.$this->seriousgame_mode,0);} + return $this->seriousgame_mode; + } + /** * Gets the item's reference column * @return string The item's reference field (generally used for SCORM identifiers) @@ -1656,17 +1689,23 @@ class learnpathItem { public function restart() { if(self::debug>0){error_log('New LP - In learnpathItem::restart()',0);} - if ($this->type == 'sco') { //If this is a sco, chamilo can't update the time without explicit scorm call + 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->curtrent_stop_time = 0; //Those 0 value have this effect } $this->save(); + //SPECIAL KTM : We reuse same attempt_id + if ($this->get_seriousgame_mode() == 1 && $this->type == 'sco') { + $this->current_start_time = 0; + $this->current_stop_time = 0; + return true; + } $allowed = $this->is_restart_allowed(); if($allowed === -1){ //nothing allowed, do nothing }elseif($allowed === 1){ //restart as new attempt is allowed, record a new attempt - $this->attempt_id = $this->attempt_id + 1; //simply reuse the previous attempt_id + $this->attempt_id = $this->attempt_id + 1; //simply reuse the previous attempt_id $this->current_score = 0; $this->current_start_time = 0; $this->current_stop_time = 0; @@ -2255,7 +2294,7 @@ class learnpathItem { $save=true; } - if (($save===false && $this->type == 'sco') ||(($this->type == 'sco') && ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse'))) + if ((($save===false && $this->type == 'sco') ||(($this->type == 'sco') && ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse'))) && ($this->seriousgame_mode!=1 && $this->type == 'sco')) { //this info shouldn't be saved as the credit or lesson mode info prevent it if(self::debug>1){error_log('New LP - In learnpathItem::write_to_db() - credit('.$credit.') or lesson_mode('.$mode.') prevent recording!',0);} @@ -2379,7 +2418,10 @@ class learnpathItem { $case_completed=array('completed','passed','browsed'); //is not multiple attempts - if ($this->get_prevent_reinit()==1) { + if ($this->seriousgame_mode==1 && $this->type=='sco') { + $total_time =" total_time = total_time +".$this->get_total_time().", "; + $my_status = " status = '".$this->get_status(false)."' ,"; + } elseif ($this->get_prevent_reinit()==1) { // process of status verified into data base $sql_verified='SELECT status FROM '.$item_view_table.' WHERE lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->attempt_id.'" ;'; diff --git a/main/newscorm/learnpathList.class.php b/main/newscorm/learnpathList.class.php index ffd542f3e6..f5ec44db3e 100644 --- a/main/newscorm/learnpathList.class.php +++ b/main/newscorm/learnpathList.class.php @@ -87,6 +87,7 @@ class learnpathList { 'lp_visibility' => $vis, 'lp_published' => $pub, 'lp_prevent_reinit' => $row['prevent_reinit'], + 'seriousgame_mode' => $row['seriousgame_mode'], 'lp_scorm_debug' => $row['debug'], 'lp_display_order' => $row['display_order'], 'lp_preview_image' => stripslashes($row['preview_image']) diff --git a/main/newscorm/lp_controller.php b/main/newscorm/lp_controller.php index 59584387f2..e3f3f9dfb2 100644 --- a/main/newscorm/lp_controller.php +++ b/main/newscorm/lp_controller.php @@ -817,6 +817,7 @@ switch($action) $_SESSION['oLP']->update_default_scorm_commit(); require 'lp_list.php'; break; + /* Those 2 switches have been replaced by switc_attempt_mode switch case 'switch_reinit': if($debug>0) error_log('New LP - switch_reinit action triggered',0); if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; } @@ -824,6 +825,21 @@ switch($action) $_SESSION['oLP']->update_reinit(); require 'lp_list.php'; break; + case 'switch_seriousgame_mode': + if($debug>0) error_log('New LP - switch_seriousgame_mode action triggered',0); + if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; } + $_SESSION['refresh'] = 1; + $_SESSION['oLP']->set_seriousgame_mode(); + require 'lp_list.php'; + break; + */ + case 'switch_attempt_mode': + if($debug>0) error_log('New LP - switch_reinit action triggered',0); + if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; } + $_SESSION['refresh'] = 1; + $_SESSION['oLP']->switch_attempt_mode(); + require 'lp_list.php'; + break; case 'switch_scorm_debug': if($debug>0) error_log('New LP - switch_scorm_debug action triggered',0); if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; } diff --git a/main/newscorm/lp_list.php b/main/newscorm/lp_list.php index 3c1aaa1820..45ddf328cf 100644 --- a/main/newscorm/lp_list.php +++ b/main/newscorm/lp_list.php @@ -341,24 +341,29 @@ if (is_array($flat_list)) { } - /* MULTIPLE ATTEMPTS */ - if ($current_session == $details['lp_session']) { - if($details['lp_prevent_reinit']==1){ - $dsp_reinit = '' . - 'Allow reinit' . - ' '; - }else{ - $dsp_reinit = '' . - 'Prevent reinit' . - ' '; - } + /* MULTIPLE ATTEMPTS OR SERIOUS GAME MODE */ + + if ($current_session == $details['lp_session']) { + if ($details['seriousgame_mode'] == 1 && $details['lp_prevent_reinit'] == 1) { //seriousgame mode | next = single + dir('serious'); + $dsp_reinit = '' . + 'Prevent reinit' . + ' '; + } + if ($details['seriousgame_mode'] == 0 && $details['lp_prevent_reinit'] == 1) { //single mode | next = multiple + $dsp_reinit = '' . + 'Allow reinit' . + ' '; + } + if ($details['seriousgame_mode'] == 0 && $details['lp_prevent_reinit'] == 0) { //multiple mode | next = seriousgame + $dsp_reinit = '' . + 'Serious game mode' . + ' '; + } } else { - $dsp_reinit = 'Allow reinit'; + $dsp_reinit .= ''; } - - - /* FUll screen VIEW */ if ($current_session == $details['lp_session']) {