[svn r15916] Add an input text to choose a number of random question to display

FS#2784
skala
Julian Prud'homme 17 years ago
parent 664a2fc01d
commit f020ddc532
  1. 39
      main/exercice/exercise.class.php
  2. 1
      main/inc/lib/add_course.lib.inc.php
  3. 2
      main/install/migrate-db-1.8.5-1.8.6-pre.sql

@ -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 15845 2008-07-24 19:21:23Z dperales $
* @version $Id: exercise.class.php 15916 2008-08-05 14:33:49Z elixir_julian $
*/
@ -42,6 +42,7 @@ class Exercise
var $active;
var $timeLimit;
var $attempts;
var $nbRandomQuestions;
var $questionList; // array with the list of this exercise's questions
@ -79,7 +80,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, max_attempt FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
$sql="SELECT title,description,sound,type,random,active, results_disabled, max_attempt,nb_random_questions FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
$result=api_sql_query($sql,__FILE__,__LINE__);
// if the exercise has been found
@ -94,6 +95,7 @@ class Exercise
$this->active=$object->active;
$this->results_disabled =$object->results_disabled;
$this->attempts = $object->max_attempt;
$this->nbRandomQuestions = $object->nb_random_questions;
$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__);
@ -187,6 +189,11 @@ class Exercise
{
return $this->type;
}
function selectNbRandomQuestions()
{
return $this->nbRandomQuestions;
}
/**
* tells if questions are selected randomly, and if so returns the draws
@ -404,6 +411,11 @@ class Exercise
{
$this->type=$type;
}
function updateNbRandomQuestions($nb_random_questions)
{
$this->nbRandomQuestions = $nb_random_questions;
}
/**
* sets to 0 if questions are not selected randomly
@ -467,6 +479,7 @@ class Exercise
$random=$this->random;
$active=$this->active;
$results_disabled = intval($this->results_disabled);
$nb_random_questions = intval($this->nbRandomQuestions);
// exercise already exists
if($id)
@ -479,14 +492,15 @@ class Exercise
random='".Database::escape_string($random)."',
active='".Database::escape_string($active)."',
max_attempt='".Database::escape_string($attempts)."', " .
"results_disabled='".Database::escape_string($results_disabled)."'
"results_disabled='".Database::escape_string($results_disabled)."',
nb_random_questions = '".Database::escape_string($nb_random_questions)."'
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, max_attempt)
$sql="INSERT INTO $TBL_EXERCICES(title,description,sound,type,random,active, results_disabled, max_attempt, nb_random_questions)
VALUES(
'".Database::escape_string($exercise)."',
'".Database::escape_string($description)."',
@ -495,7 +509,8 @@ class Exercise
'".Database::escape_string($random)."',
'".Database::escape_string($active)."',
'".Database::escape_string($results_disabled)."',
'".Database::escape_string($attempts)."'
'".Database::escape_string($attempts)."',
'".Database::escape_string($nb_random_questions)."'
)";
api_sql_query($sql,__FILE__,__LINE__);
@ -699,6 +714,17 @@ class Exercise
$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'));
$form -> addElement('html','<div class="row">
<div class="label">&nbsp;</div>
<div class="formw">
<a href="javascript://" onclick="if(document.getElementById(\'options\').style.display == \'none\'){document.getElementById(\'options\').style.display = \'block\';}else{document.getElementById(\'options\').style.display = \'none\';}"><img src="../img/add_na.gif" alt="" />'.get_lang('AdvancedParameters').'</a>
</div>
</div>');
$form -> addElement('html','<div id="options" style="display: none;">');
$form -> addElement('text', 'nbRandomQuestions', get_lang('RandomQuestionsToDisplay').' : ',array('size'=>'3'));
$form -> addElement('html','</div>');
// submit
$form -> addElement('submit', 'submitExercise', get_lang('Ok'));
@ -710,6 +736,7 @@ class Exercise
$defaults = array();
if($this -> id > 0)
{
$defaults['nbRandomQuestions'] = $this -> selectNbRandomQuestions();
$defaults['exerciseAttempts'] = $this -> selectAttempts();
$defaults['exerciseType'] = $this -> selectType();
$defaults['exerciseTitle'] = $this -> selectTitle();
@ -718,6 +745,7 @@ class Exercise
}
else{
$defaults['exerciseType'] = 1;
$defaults['nbRandomQuestions'] = 0;
$defaults['exerciseAttempts'] = 0;
//$defaults['randomQuestions'] = 0;
$defaults['exerciseDescription'] = '';
@ -740,6 +768,7 @@ class Exercise
$this -> updateDescription($form -> getSubmitValue('exerciseDescription'));
$this -> updateType($form -> getSubmitValue('exerciseType'));
$this -> setRandom($form -> getSubmitValue('randomQuestions'));
$this -> updateNbRandomQuestions($form -> getSubmitValue('nbRandomQuestions'));
$this -> save();
}

@ -593,6 +593,7 @@ function update_Db_course($courseDbName)
results_disabled TINYINT UNSIGNED NOT NULL DEFAULT 0,
access_condition TEXT DEFAULT NULL,
max_attempt int NOT NULL default 0,
nb_random_questions TINYINT NULL default 0,
PRIMARY KEY (id)
)";
api_sql_query($sql, __FILE__, __LINE__);

@ -30,6 +30,7 @@ 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 quiz_rel_question ADD question_order mediumint unsigned NOT NULL default 1;
ALTER TABLE quiz ADD max_attempt int NOT NULL default 0;
ALTER TABLE quiz ADD nb_random_questions TINYINT NULL DEFAULT '0';
ALTER TABLE survey ADD one_question_per_page bool NOT NULL default 0;
ALTER TABLE survey ADD shuffle bool NOT NULL default 0;
ALTER TABLE survey ADD survey_version varchar(255) NOT NULL default '';
@ -41,3 +42,4 @@ ALTER TABLE survey_question ADD survey_group_sec2 int unsigned NOT NULL default
CREATE TABLE survey_group ( id int unsigned NOT NULL auto_increment, name varchar(20) NOT NULL, description varchar(255) NOT NULL, survey_id int unsigned NOT NULL, PRIMARY KEY (id) );
ALTER TABLE survey_question_option ADD value int NOT NULL default 0;
UPDATE tool SET category = 'interaction' WHERE name = 'forum';

Loading…
Cancel
Save