SCORM attempts : adds a seriousgame mode flag to lp

skala
Noel Dieschburg 15 years ago
parent 184a7f26c3
commit 557a5ae408
  1. BIN
      main/img/gamepad.gif
  2. 3
      main/inc/lib/add_course.lib.inc.php
  3. 2
      main/install/migrate-db-1.8.6.2-1.8.7-pre.sql
  4. 134
      main/newscorm/learnpath.class.php
  5. 50
      main/newscorm/learnpathItem.class.php
  6. 1
      main/newscorm/learnpathList.class.php
  7. 16
      main/newscorm/lp_controller.php
  8. 35
      main/newscorm/lp_list.php

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -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))
{

@ -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;

@ -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 <noel@cblue.be>
**/
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 <noel@cblue.be>
**/
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 <noel@cblue.be>
**/
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 <noel@cblue.be>
**/
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)

@ -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 <noel@cblue.be>
**/
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.'" ;';

@ -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'])

@ -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'; }

@ -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 = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_reinit&lp_id='.$id.'">' .
'<img src="../img/kaboodleloop_gray.gif" border="0" alt="Allow reinit" title="'.get_lang("AllowMultipleAttempts").'"/>' .
'</a>&nbsp;';
}else{
$dsp_reinit = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_reinit&lp_id='.$id.'">' .
'<img src="../img/kaboodleloop.gif" border="0" alt="Prevent reinit" title="'.get_lang("PreventMultipleAttempts").'"/>' .
'</a>&nbsp;';
}
/* 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 = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_attempt_mode&lp_id='.$id.'">' .
'<img src="../img/gamepad.gif" border="0" alt="Prevent reinit" title="'.get_lang("PreventMultipleAttempts").'"/>' .
'</a>&nbsp;';
}
if ($details['seriousgame_mode'] == 0 && $details['lp_prevent_reinit'] == 1) { //single mode | next = multiple
$dsp_reinit = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_attempt_mode&lp_id='.$id.'">' .
'<img src="../img/kaboodleloop_gray.gif" border="0" alt="Allow reinit" title="'.get_lang("AllowMultipleAttempts").'"/>' .
'</a>&nbsp;';
}
if ($details['seriousgame_mode'] == 0 && $details['lp_prevent_reinit'] == 0) { //multiple mode | next = seriousgame
$dsp_reinit = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_attempt_mode&lp_id='.$id.'">' .
'<img src="../img/kaboodleloop.gif" border="0" alt="Serious game mode" title="'.get_lang("SeriousGameMode").'"/>' .
'</a>&nbsp;';
}
} else {
$dsp_reinit = '<img src="../img/kaboodleloop_gray.gif" border="0" alt="Allow reinit" title="'.get_lang("AllowMultipleAttempts").'"/>';
$dsp_reinit .= '<img src="../img/kaboodleloop_gray.gif" border="0" alt="" title="'.get_lang("AllowMultipleAttempts").'"/>';
}
/* FUll screen VIEW */
if ($current_session == $details['lp_session']) {

Loading…
Cancel
Save