Source for file exercise.class.php
Documentation is available at exercise.class.php
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
* Exercise class: This class allows to instantiate an object of type Exercise
* @package dokeos.exercise
* @author Olivier Brouckaert
* @version $Id: exercise.class.php 14786 2008-04-08 14:11:46Z elixir_inter $
var $questionList; // array with the list of this exercise's questions
* constructor of the class
* @author - Olivier Brouckaert
* reads exercise informations from the data base
* @author - Olivier Brouckaert
* @param - integer $id - exercise ID
* @return - boolean - true if exercise exists, otherwise false
#$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql= "SELECT title,description,sound,type,random,active, results_disabled FROM $TBL_EXERCICES WHERE id='$id'";
// if the exercise has been found
$this->sound= $object->sound;
$this->type= $object->type;
$this->random= $object->random;
$this->active= $object->active;
$this->results_disabled = $object->results_disabled;
$sql= "SELECT question_id,position FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='$id' ORDER BY position";
// fills the array with the question ID for this exercise
// the key of the array is the question position
// makes sure that the question position is unique
$this->questionList[$object->position]= $object->question_id;
* returns the exercise ID
* @author - Olivier Brouckaert
* @return - integer - exercise ID
* returns the exercise title
* @author - Olivier Brouckaert
* @return - string - exercise title
* returns the exercise description
* @author - Olivier Brouckaert
* @return - string - exercise description
* returns the exercise sound file
* @author - Olivier Brouckaert
* @return - string - exercise description
* returns the exercise type
* @author - Olivier Brouckaert
* @return - integer - exercise type
* tells if questions are selected randomly, and if so returns the draws
* @author - Olivier Brouckaert
* @return - integer - 0 if not random, otherwise the draws
* Same as isRandom() but has a name applied to values different than 0 or 1
* returns the exercise status (1 = enabled ; 0 = disabled)
* @author - Olivier Brouckaert
* @return - boolean - true if enabled, otherwise false
* returns the array with the question ID list
* @author - Olivier Brouckaert
* @return - array - question ID list
* returns the number of questions in this exercise
* @author - Olivier Brouckaert
* @return - integer - number of questions
* selects questions randomly in the question list
* @author - Olivier Brouckaert
* @return - array - if the exercise is not set to take questions randomly, returns the question list
* without randomizing, otherwise, returns the list with questions selected randomly
// if the exercise is not a random exercise, or if there are not at least 2 questions
$randQuestionList= array();
// loop for the number of draws
for($i= 0;$i < $draws;$i++ )
// selects a question randomly
// if the question has already been selected, continues in the loop
// if we have found the question chosed above
$randQuestionList[$key]= $val;
return $randQuestionList;
* returns 'true' if the question ID is in the question list
* @author - Olivier Brouckaert
* @param - integer $questionId - question ID
* @return - boolean - true if in the list, otherwise false
* changes the exercise title
* @author - Olivier Brouckaert
* @param - string $title - exercise title
* changes the exercise description
* @author - Olivier Brouckaert
* @param - string $description - exercise description
* changes the exercise sound file
* @author - Olivier Brouckaert
* @param - string $sound - exercise sound file
* @param - string $delete - ask to delete the file
global $audioPath, $documentPath,$_course, $_user;
if($sound['size'] && (strstr($sound['type'],'audio') || strstr($sound['type'],'video')))
$this->sound= $sound['name'];
$query= "SELECT 1 FROM $TBL_DOCUMENT "
/*$query="INSERT INTO $TBL_DOCUMENT(path,filetype) VALUES "
." ('".str_replace($documentPath,'',$audioPath).'/'.$this->sound."','file')";
api_sql_query($query,__FILE__,__LINE__);*/
//$id = Database::get_last_insert_id();
//$time = date("Y-m-d H:i:s", $time);
// insert into the item_property table, using default visibility of "visible"
/*$query = "INSERT INTO $TBL_ITEM_PROPERTY "
."(tool, ref, insert_user_id,to_group_id, insert_date, lastedit_date, lastedit_type) "
."('".TOOL_DOCUMENT."', $id, $_user['user_id'], 0, '$time', '$time', 'DocumentAdded' )";
api_sql_query($query,__FILE__,__LINE__);*/
* changes the exercise type
* @author - Olivier Brouckaert
* @param - integer $type - exercise type
* sets to 0 if questions are not selected randomly
* if questions are selected randomly, sets the draws
* @author - Olivier Brouckaert
* @param - integer $random - 0 if not random, otherwise the draws
* @author - Olivier Brouckaert
* @author - Olivier Brouckaert
$this->results_disabled = true;
$this->results_disabled = false;
* updates the exercise in the data base
* @author - Olivier Brouckaert
$results_disabled = intval($this->results_disabled);
// exercise already exists
$sql= "UPDATE $TBL_EXERCICES SET title='$exercise',description='$description',sound='$sound',type='$type',random='$random',active='$active',results_disabled='$results_disabled' WHERE id='$id'";
// creates a new exercise
$sql= "INSERT INTO $TBL_EXERCICES(title,description,sound,type,random,active, results_disabled) VALUES('$exercise','$description','$sound','$type','$random','$active',$results_disabled)";
// updates the question position
$sql= "UPDATE $TBL_QUESTIONS SET position='$position' WHERE id='$questionId'";
* moves a question up in the list
* @author - Olivier Brouckaert
* @param - integer $id - question ID to move up
// position of question in the array
// position of previous question in the array
// error, can't move question
// permutes questions in the array
* moves a question down in the list
* @author - Olivier Brouckaert
* @param - integer $id - question ID to move down
// position of question in the array
// position of next question in the array
// error, can't move question
// permutes questions in the array
* adds a question into the question list
* @author - Olivier Brouckaert
* @param - integer $questionId - question ID
* @return - boolean - true if the question has been added, otherwise false
// checks if the question ID is not in the list
// selects the max position
* removes a question from the question list
* @author - Olivier Brouckaert
* @param - integer $questionId - question ID
* @return - boolean - true if the question has been removed, otherwise false
// searches the position of the question ID in the list
// deletes the position from the array containing the wanted question ID
* deletes the exercise from the database
* Notice : leaves the question in the data base
* @author - Olivier Brouckaert
$sql= "UPDATE $TBL_EXERCICES SET active='-1' WHERE id='". $this->id. "'";
* Creates the form to create / edit an exercise
* @param FormValidator $form the formvalidator instance (by reference)
$form -> addElement('text', 'exerciseTitle', get_lang('ExerciseName'). ' : ','class="input_titles"');
$fck_attribute = array();
$fck_attribute['Height'] = '250';
$fck_attribute['Width'] = '100%';
$fck_attribute['ToolbarSet'] = 'NewTest';
$form -> addElement ('html_editor', 'exerciseDescription', get_lang('ExerciseDescription'). ' : ');
$radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('SimpleExercise'),'1');
$radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2');
$form -> addGroup($radios, null, get_lang('ExerciseType'). ' : ', '<br />');
$random[] = FormValidator :: createElement ('text', 'randomQuestions', null,null,'0');
$form -> addGroup($random,null,get_lang('RandomQuestions').' : ','<br />');*/
$form -> addElement('submit', 'submitExercise', get_lang('Ok'));
$form -> addRule ('exerciseTitle', get_lang('GiveExerciseName'), 'required');
$defaults['exerciseType'] = $this -> selectType();
//$defaults['randomQuestions'] = $this -> isRandom();
$defaults['exerciseType'] = 1;
//$defaults['randomQuestions'] = 0;
$defaults['exerciseDescription'] = '';
$form -> setDefaults($defaults);
* function which process the creation of exercises
* @param FormValidator $form the formvalidator instance
$this -> updateTitle($form -> getSubmitValue('exerciseTitle'));
$this -> updateType($form -> getSubmitValue('exerciseType'));
$this -> setRandom($form -> getSubmitValue('randomQuestions'));
|