[svn r15802] Enable attempts limit in quiz tool

skala
Yannick Warnier 17 years ago
parent 3d41ca367c
commit e52ae380d2
  1. 4
      main/coursecopy/classes/CourseBuilder.class.php
  2. 4
      main/coursecopy/classes/CourseRestorer.class.php
  3. 7
      main/coursecopy/classes/Quiz.class.php
  4. 27
      main/exercice/exercice_submit.php
  5. 35
      main/exercice/exercise.class.php
  6. 3
      main/inc/lib/add_course.lib.inc.php
  7. 47
      main/install/migrate-db-1.8.5-1.8.6-pre.sql

@ -1,4 +1,4 @@
<?php // $Id: CourseBuilder.class.php 13309 2007-09-27 07:29:58Z yannoo $
<?php // $Id: CourseBuilder.class.php 15802 2008-07-17 04:52:13Z yannoo $
/*
==============================================================================
Dokeos - elearning and course management software
@ -262,7 +262,7 @@ class CourseBuilder
$doc = Database::fetch_object(api_sql_query("SELECT id FROM ".$table_doc." WHERE path = '/audio/".$obj->sound."'"));
$obj->sound = $doc->id;
}
$quiz = new Quiz($obj->id, $obj->title, $obj->description, $obj->random, $obj->type, $obj->active, $obj->sound);
$quiz = new Quiz($obj->id, $obj->title, $obj->description, $obj->random, $obj->type, $obj->active, $obj->sound, $obj->attempts);
$sql = 'SELECT * FROM '.$table_rel.' WHERE exercice_id = '.$obj->id;
$db_result2 = api_sql_query($sql, __FILE__, __LINE__);
while ($obj2 = Database::fetch_object($db_result2))

@ -1,4 +1,4 @@
<?php // $Id: CourseRestorer.class.php 15301 2008-05-16 03:21:42Z yannoo $
<?php // $Id: CourseRestorer.class.php 15802 2008-07-17 04:52:13Z yannoo $
/*
==============================================================================
Dokeos - elearning and course management software
@ -600,7 +600,7 @@ class CourseRestorer
$doc = str_replace('/audio/', '', $doc->path);
}
}
$sql = "INSERT INTO ".$table_qui." SET title = '".Database::escape_string($quiz->title)."', description = '".Database::escape_string($quiz->description)."', type = '".$quiz->quiz_type."', random = '".$quiz->random."', active = '".$quiz->active."', sound = '".Database::escape_string($doc)."' ";
$sql = "INSERT INTO ".$table_qui." SET title = '".Database::escape_string($quiz->title)."', description = '".Database::escape_string($quiz->description)."', type = '".$quiz->quiz_type."', random = '".$quiz->random."', active = '".$quiz->active."', sound = '".Database::escape_string($doc)."', max_attempt = '".$quiz->attempts."' ";
api_sql_query($sql, __FILE__, __LINE__);
$new_id = Database::get_last_insert_id();
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;

@ -1,4 +1,4 @@
<?php // $Id: Quiz.class.php 3305 2005-02-03 12:44:01Z bmol $
<?php // $Id: Quiz.class.php 15802 2008-07-17 04:52:13Z yannoo $
/*
==============================================================================
Dokeos - elearning and course management software
@ -60,6 +60,8 @@ class Quiz extends Resource
* Questions
*/
var $question_ids;
var $attempts;
/**
* Create a new Quiz
* @param string $title
@ -68,7 +70,7 @@ class Quiz extends Resource
* @param int $type
* @param int $active
*/
function Quiz($id,$title,$description,$random,$type,$active,$media)
function Quiz($id,$title,$description,$random,$type,$active,$media,$attempts=0)
{
parent::Resource($id,RESOURCE_QUIZ);
$this->title = $title;
@ -77,6 +79,7 @@ class Quiz extends Resource
$this->quiz_type = $type;
$this->active = $active;
$this->media = $media;
$this->attempts = $attempts;
$this->question_ids = array();
}
/**

@ -36,8 +36,8 @@
* the administrator
* @package dokeos.exercise
* @author Olivier Brouckaert
* @author Julio Montoya Armas switchable fill in blank option added
* @version $Id: exercice_submit.php 15799 2008-07-17 00:14:02Z yannoo $
* @author Julio Montoya multiple fill in blank option added
* @version $Id: exercice_submit.php 15802 2008-07-17 04:52:13Z yannoo $
*/
@ -235,7 +235,8 @@ if(!is_object($objExercise))
header('Location: exercice.php');
exit();
}
$quizID = $objExercise->selectId();
$exerciseAttempts=$objExercise->selectAttempts();
$exerciseTitle=$objExercise->selectTitle();
$exerciseDescription=$objExercise->selectDescription();
$exerciseDescription=stripslashes($exerciseDescription);
@ -431,6 +432,24 @@ else
echo "<h3>".$exerciseTitle."</h3>";
if( $exerciseAttempts > 0 && !$is_allowed_to_edit ){
$user_id = api_get_user_id();
$sql = 'SELECT count(*)
FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES).'
WHERE exe_exo_id = '.$quizID.' '.
'and exe_user_id = '.$user_id.'
';
$aquery = api_sql_query($sql, __FILE__, __LINE__);
$attempt = Database::fetch_array($aquery);
if( true ){
Display::display_warning_message(sprintf(get_lang('ReachedMaxAttempts'),$exerciseTitle,$exerciseAttempts));
Display::display_footer();
exit;
}
}
if(!empty($error))
{
Display::display_error_message($error,false);
@ -487,7 +506,7 @@ else
}
$s="<p>$exerciseDescription</p>";
if($exerciseType==2){
if($origin == 'learnpath' && $exerciseType==2){
$s2 = "&exerciseId=".$exerciseId;
}
$s.=" <form method='post' action='".api_get_self()."?autocomplete=off".$s2."' name='frm_exercise' $onsubmit>

@ -25,7 +25,7 @@
* Exercise class: This class allows to instantiate an object of type Exercise
* @package dokeos.exercise
* @author Olivier Brouckaert
* @version $Id: exercise.class.php 15797 2008-07-16 22:04:57Z yannoo $
* @version $Id: exercise.class.php 15802 2008-07-17 04:52:13Z yannoo $
*/
@ -41,6 +41,7 @@ class Exercise
var $random;
var $active;
var $timeLimit;
var $attempts;
var $questionList; // array with the list of this exercise's questions
@ -78,7 +79,7 @@ class Exercise
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
#$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql="SELECT title,description,sound,type,random,active, results_disabled FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
$sql="SELECT title,description,sound,type,random,active, results_disabled, max_attempt FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
$result=api_sql_query($sql,__FILE__,__LINE__);
// if the exercise has been found
@ -92,7 +93,7 @@ class Exercise
$this->random=$object->random;
$this->active=$object->active;
$this->results_disabled =$object->results_disabled;
$this->attempts = $object->max_attempt;
$sql="SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($id)."' ORDER BY question_order";
$result=api_sql_query($sql,__FILE__,__LINE__);
@ -136,6 +137,11 @@ class Exercise
{
return $this->exercise;
}
function selectAttempts()
{
return $this->attempts;
}
/**
* returns the time limit
*/
@ -311,6 +317,11 @@ class Exercise
{
$this->exercise=$title;
}
function updateAttempts($title)
{
$this->attempts=$title;
}
/**
* changes the exercise description
@ -442,6 +453,7 @@ class Exercise
$description=addslashes($this->description);
$sound=addslashes($this->sound);
$type=$this->type;
$attempts=$this->attempts;
$random=$this->random;
$active=$this->active;
$results_disabled = intval($this->results_disabled);
@ -456,14 +468,15 @@ class Exercise
type='".Database::escape_string($type)."',
random='".Database::escape_string($random)."',
active='".Database::escape_string($active)."',
results_disabled='".Database::escape_string($results_disabled)."'
max_attempt='".Database::escape_string($attempts)."', " .
"results_disabled='".Database::escape_string($results_disabled)."'
WHERE id='".Database::escape_string($id)."'";
api_sql_query($sql,__FILE__,__LINE__);
}
// creates a new exercise
else
{
$sql="INSERT INTO $TBL_EXERCICES(title,description,sound,type,random,active, results_disabled)
$sql="INSERT INTO $TBL_EXERCICES(title,description,sound,type,random,active, results_disabled, max_attempt)
VALUES(
'".Database::escape_string($exercise)."',
'".Database::escape_string($description)."',
@ -471,7 +484,8 @@ class Exercise
'".Database::escape_string($type)."',
'".Database::escape_string($random)."',
'".Database::escape_string($active)."',
'".Database::escape_string($results_disabled)."'
'".Database::escape_string($results_disabled)."',
'".Database::escape_string($attempts)."'
)";
api_sql_query($sql,__FILE__,__LINE__);
@ -674,17 +688,19 @@ class Exercise
/*$random = array();
$random[] = FormValidator :: createElement ('text', 'randomQuestions', null,null,'0');
$form -> addGroup($random,null,get_lang('RandomQuestions').' : ','<br />');*/
$form -> addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2'));
// submit
$form -> addElement('submit', 'submitExercise', get_lang('QuestCreate'));
$form -> addElement('submit', 'submitExercise', get_lang('Ok'));
// rules
$form -> addRule ('exerciseTitle', get_lang('GiveExerciseName'), 'required');
$form -> addRule ('exerciseAttempts', get_lang('Numeric'), 'numeric');
// defaults
$defaults = array();
if($this -> id > 0)
{
$defaults['exerciseAttempts'] = $this -> selectAttempts();
$defaults['exerciseType'] = $this -> selectType();
$defaults['exerciseTitle'] = $this -> selectTitle();
$defaults['exerciseDescription'] = $this -> selectDescription();
@ -692,6 +708,7 @@ class Exercise
}
else{
$defaults['exerciseType'] = 1;
$defaults['exerciseAttempts'] = 0;
//$defaults['randomQuestions'] = 0;
$defaults['exerciseDescription'] = '';
}
@ -708,7 +725,7 @@ class Exercise
*/
function processCreation($form)
{
$this -> updateAttempts($form -> getSubmitValue('exerciseAttempts'));
$this -> updateTitle($form -> getSubmitValue('exerciseTitle'));
$this -> updateDescription($form -> getSubmitValue('exerciseDescription'));
$this -> updateType($form -> getSubmitValue('exerciseType'));

@ -591,6 +591,7 @@ function update_Db_course($courseDbName)
active tinyint NOT NULL default 0,
results_disabled TINYINT UNSIGNED NOT NULL DEFAULT 0,
access_condition TEXT DEFAULT NULL,
max_attempt int NOT NULL default 0,
PRIMARY KEY (id)
)";
api_sql_query($sql, __FILE__, __LINE__);
@ -2203,4 +2204,4 @@ function readPropertiesInArchive($archive, $isCompressed = TRUE)
rmdir($tmpDirName);
return $courseProperties;
}
?>
?>

@ -1,25 +1,26 @@
-- This script updates the databases structure before migrating the data from
-- version 1.8.5 to version 1.8.6
-- it is intended as a standalone script, however, because of the multiple
-- databases related difficulties, it should be parsed by a PHP script in
-- order to connect to and update the right databases.
-- There is one line per query, allowing the PHP function file() to read
-- all lines separately into an array. The xxMAINxx-type markers are there
-- to tell the PHP script which database we're talking about.
-- By always using the keyword "TABLE" in the queries, we should be able
-- to retrieve and modify the table name from the PHP script if needed, which
-- will allow us to deal with the unique-database-type installations
--
-- This first part is for the main database
-- xxMAINxx
INSERT INTO settings_current (variable, subkey,type,category,selected_value,title,comment,scope,subkeytext)VALUES ('registration', 'phone', 'textfield', 'User', 'false', 'RegistrationRequiredFormsTitle','RegistrationRequiredFormsComment', NULL, 'Phone');
ALTER TABLE php_session CHANGE session_value session_value MEDIUMTEXT NOT NULL;
-- xxSTATSxx
-- xxUSERxx
-- xxCOURSExx
-- This script updates the databases structure before migrating the data from
-- version 1.8.5 to version 1.8.6
-- it is intended as a standalone script, however, because of the multiple
-- databases related difficulties, it should be parsed by a PHP script in
-- order to connect to and update the right databases.
-- There is one line per query, allowing the PHP function file() to read
-- all lines separately into an array. The xxMAINxx-type markers are there
-- to tell the PHP script which database we're talking about.
-- By always using the keyword "TABLE" in the queries, we should be able
-- to retrieve and modify the table name from the PHP script if needed, which
-- will allow us to deal with the unique-database-type installations
--
-- This first part is for the main database
-- xxMAINxx
INSERT INTO settings_current (variable, subkey,type,category,selected_value,title,comment,scope,subkeytext)VALUES ('registration', 'phone', 'textfield', 'User', 'false', 'RegistrationRequiredFormsTitle','RegistrationRequiredFormsComment', NULL, 'Phone');
ALTER TABLE php_session CHANGE session_value session_value MEDIUMTEXT NOT NULL;
-- xxSTATSxx
-- xxUSERxx
-- xxCOURSExx
ALTER TABLE lp ADD theme varchar(255) not null default '';
ALTER TABLE survey ADD mail_subject VARCHAR( 255 ) NOT NULL AFTER reminder_mail ;
ALTER TABLE survey ADD mail_subject VARCHAR( 255 ) NOT NULL AFTER reminder_mail ;
ALTER TABLE quiz_rel_question ADD question_order mediumint unsigned NOT NULL default 1;
ALTER TABLE quiz ADD max_attempt int NOT NULL default 0;

Loading…
Cancel
Save