Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent 94646c66c1
commit 5f22d03c21
  1. 11
      main/exercice/answer.class.php
  2. 20
      main/exercice/exercise.class.php
  3. 51
      main/exercice/exercise.lib.php
  4. 13
      main/exercice/exercise_result.class.php
  5. 2
      main/exercice/fill_blanks.class.php
  6. 31
      main/exercice/freeanswer.class.php
  7. 24
      main/exercice/hotspot.class.php
  8. 1
      main/exercice/matching.class.php
  9. 3
      main/exercice/multiple_answer.class.php
  10. 28
      main/exercice/multiple_answer_combination.class.php
  11. 5
      main/exercice/multiple_answer_combination_true_false.class.php
  12. 1
      main/exercice/multiple_answer_true_false.class.php
  13. 24
      main/exercice/oral_expression.class.php
  14. 88
      main/exercice/question.class.php
  15. 2
      main/exercice/testcategory.class.php
  16. 3
      main/exercice/unique_answer.class.php
  17. 39
      main/exercice/unique_answer_no_option.class.php

@ -1,17 +1,12 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* This class allows to instantiate an object of type Answer * Class Answer
* Allows to instantiate an object of type Answer
* 5 arrays are created to receive the attributes of each answer belonging to a specified question * 5 arrays are created to receive the attributes of each answer belonging to a specified question
* @package chamilo.exercise * @package chamilo.exercise
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @version $Id: answer.class.php 21172 2009-06-01 20:58:05Z darkvela $
*/
/**
* Code
*/
/**
* Answer class
* @package chamilo.exercise * @package chamilo.exercise
*/ */
class Answer class Answer

@ -1,15 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/**
* Exercise class: This class allows to instantiate an object of type Exercise
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya Cleaning exercises
* Modified by Hubert Borderiou #294
*/
/**
* Code
*/
define('ALL_ON_ONE_PAGE', 1); define('ALL_ON_ONE_PAGE', 1);
define('ONE_PER_PAGE', 2); define('ONE_PER_PAGE', 2);
@ -28,6 +19,15 @@ $debug = false; //All exercise scripts should depend in this debug variable
require_once dirname(__FILE__).'/../inc/lib/exercise_show_functions.lib.php'; require_once dirname(__FILE__).'/../inc/lib/exercise_show_functions.lib.php';
/**
* Class Exercise
*
* Allows to instantiate an object of type Exercise
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya Cleaning exercises
* Modified by Hubert Borderiou #294
*/
class Exercise class Exercise
{ {
public $id; public $id;

@ -10,9 +10,7 @@
* @version $Id: exercise.lib.php 22247 2009-07-20 15:57:25Z ivantcholakov $ * @version $Id: exercise.lib.php 22247 2009-07-20 15:57:25Z ivantcholakov $
* Modified by Hubert Borderiou 2011-10-21 Question Category * Modified by Hubert Borderiou 2011-10-21 Question Category
*/ */
/**
* Code
*/
// The initialization class for the online editor is needed here. // The initialization class for the online editor is needed here.
require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php'; require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php';
@ -25,7 +23,18 @@ require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php';
* @param int current item from the list of questions * @param int current item from the list of questions
* @param int number of total questions * @param int number of total questions
* */ * */
function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false) { function showQuestion(
$questionId,
$only_questions = false,
$origin = false,
$current_item = '',
$show_title = true,
$freeze = false,
$user_choice = array(),
$show_comment = false,
$exercise_feedback = null,
$show_answers = false
) {
// Text direction for the current language // Text direction for the current language
$is_ltr_text_direction = api_get_text_direction() != 'rtl'; $is_ltr_text_direction = api_get_text_direction() != 'rtl';
@ -214,7 +223,6 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
} }
} }
for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) { for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
$answer = $objAnswerTmp->selectAnswer($answerId); $answer = $objAnswerTmp->selectAnswer($answerId);
$answerCorrect = $objAnswerTmp->isCorrect($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId);
@ -829,7 +837,12 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
return $nbrAnswers; return $nbrAnswers;
} }
function get_exercise_track_exercise_info($exe_id) { /**
* @param int $exe_id
* @return array
*/
function get_exercise_track_exercise_info($exe_id)
{
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_COURSE = Database::get_main_table(TABLE_MAIN_COURSE); $TBL_COURSE = Database::get_main_table(TABLE_MAIN_COURSE);
@ -855,7 +868,8 @@ function get_exercise_track_exercise_info($exe_id) {
/** /**
* Validates the time control key * Validates the time control key
*/ */
function exercise_time_control_is_valid($exercise_id, $lp_id = 0 , $lp_item_id = 0) { function exercise_time_control_is_valid($exercise_id, $lp_id = 0 , $lp_item_id = 0)
{
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$exercise_id = intval($exercise_id); $exercise_id = intval($exercise_id);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
@ -937,8 +951,15 @@ function get_count_exam_hotpotatoes_results($in_hotpot_path) {
* @param null $where_condition * @param null $where_condition
* @return array|int * @return array|int
*/ */
function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_column, $in_direction, $in_hotpot_path, $in_get_count = false, $where_condition = null) function get_exam_results_hotpotatoes_data(
{ $in_from,
$in_number_of_items,
$in_column,
$in_direction,
$in_hotpot_path,
$in_get_count = false,
$where_condition = null
) {
$course_code = api_get_course_id(); $course_code = api_get_course_id();
// by default in_column = 1 If parameters given, it is the name of the column witch is the bdd field name // by default in_column = 1 If parameters given, it is the name of the column witch is the bdd field name
if ($in_column == 1) { if ($in_column == 1) {
@ -999,8 +1020,15 @@ function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_co
* Gets the exam'data results * Gets the exam'data results
* @todo this function should be moved in a library + no global calls * @todo this function should be moved in a library + no global calls
*/ */
function get_exam_results_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null, $get_count = false) function get_exam_results_data(
{ $from,
$number_of_items,
$column,
$direction,
$exercise_id,
$extra_where_conditions = null,
$get_count = false
) {
//@todo replace all this globals //@todo replace all this globals
global $documentPath, $filter; global $documentPath, $filter;
@ -1229,7 +1257,6 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$sizeof = count($results); $sizeof = count($results);
$user_list_id = array(); $user_list_id = array();
$locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE); $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
//Looping results //Looping results

@ -16,7 +16,8 @@ class ExerciseResult
/** /**
* constructor of the class * constructor of the class
*/ */
public function ExerciseResult($get_questions=false,$get_answers=false) { public function ExerciseResult($get_questions = false, $get_answers = false)
{
} }
/** /**
@ -264,6 +265,7 @@ class ExerciseResult
$this->results = $return; $this->results = $return;
return true; return true;
} }
/** /**
* Exports the complete report as a CSV file * Exports the complete report as a CSV file
* @param string Document path inside the document tool * @param string Document path inside the document tool
@ -391,7 +393,14 @@ class ExerciseResult
* Exports the complete report as an XLS file * Exports the complete report as an XLS file
* @return boolean False on error * @return boolean False on error
*/ */
public function exportCompleteReportXLS($document_path='',$user_id = null, $export_user_fields= false, $export_filter = 0, $exercise_id=0, $hotpotato_name = null) { public function exportCompleteReportXLS(
$document_path = '',
$user_id = null,
$export_user_fields = false,
$export_filter = 0,
$exercise_id = 0,
$hotpotato_name = null
) {
global $charset; global $charset;
$this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); $this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
$filename = 'exercise_results_'.date('YmdGis').'.xls'; $filename = 'exercise_results_'.date('YmdGis').'.xls';

@ -1,7 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
*
* Class FillBlanks * Class FillBlanks
* *
* @author Eric Marguin * @author Eric Marguin

@ -1,31 +1,23 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* File containing the FreeAnswer class. * File containing the FreeAnswer class.
* This class allows to instantiate an object of type FREE_ANSWER, * This class allows to instantiate an object of type FREE_ANSWER,
* extending the class question * extending the class question
* @package chamilo.exercise * @package chamilo.exercise
* @author Eric Marguin * @author Eric Marguin
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
*/
/**
* Code
*/ */
if (!class_exists('FreeAnswer')): class FreeAnswer extends Question
{
/**
* @package chamilo.exercise
*/
class FreeAnswer extends Question {
static $typePicture = 'open_answer.gif'; static $typePicture = 'open_answer.gif';
static $explanationLangVar = 'FreeAnswer'; static $explanationLangVar = 'FreeAnswer';
/** /**
* Constructor * Constructor
*/ */
function FreeAnswer() { function FreeAnswer()
{
parent::question(); parent::question();
$this->type = FREE_ANSWER; $this->type = FREE_ANSWER;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
@ -35,7 +27,8 @@ if (!class_exists('FreeAnswer')):
* function which redifines Question::createAnswersForm * function which redifines Question::createAnswersForm
* @param the formvalidator instance * @param the formvalidator instance
*/ */
function createAnswersForm($form) { function createAnswersForm($form)
{
$form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1')); $form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1'));
global $text, $class; global $text, $class;
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
@ -51,14 +44,16 @@ if (!class_exists('FreeAnswer')):
/** /**
* abstract function which creates the form to create / edit the answers of the question * abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance * @param FormValidator
*/ */
function processAnswersCreation($form) { function processAnswersCreation($form)
{
$this->weighting = $form->getSubmitValue('weighting'); $this->weighting = $form->getSubmitValue('weighting');
$this->save(); $this->save();
} }
function return_header($feedback_type = null, $counter = null, $score = null) { function return_header($feedback_type = null, $counter = null, $score = null)
{
if (!empty($score['comments']) || $score['score'] > 0) { if (!empty($score['comments']) || $score['score'] > 0) {
$score['revised'] = true; $score['revised'] = true;
} else { } else {
@ -69,7 +64,7 @@ if (!class_exists('FreeAnswer')):
<tr> <tr>
<th>' . get_lang("Answer") . '</th> <th>' . get_lang("Answer") . '</th>
</tr>'; </tr>';
return $header; return $header;
} }
} }
endif;

@ -1,18 +1,8 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/**
* File containing the HotSpot class.
* @package chamilo.exercise
* @author Eric Marguin
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
*/
/**
* Code
*/
if(!class_exists('HotSpot')):
/** /**
CLASS HotSpot * Class HotSpot
* *
* This class allows to instantiate an object of type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER), * This class allows to instantiate an object of type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER),
* extending the class question * extending the class question
@ -20,9 +10,8 @@ if(!class_exists('HotSpot')):
* @author Eric Marguin * @author Eric Marguin
* @package chamilo.exercise * @package chamilo.exercise
**/ **/
class HotSpot extends Question
class HotSpot extends Question { {
static $typePicture = 'hotspot.gif'; static $typePicture = 'hotspot.gif';
static $explanationLangVar = 'HotSpot'; static $explanationLangVar = 'HotSpot';
@ -85,9 +74,10 @@ class HotSpot extends Question {
} }
/** /**
* @package chamilo.exercise * Class HotSpotDelineation
*/ */
class HotSpotDelineation extends HotSpot { class HotSpotDelineation extends HotSpot
{
static $typePicture = 'hotspot_delineation.gif'; static $typePicture = 'hotspot_delineation.gif';
static $explanationLangVar = 'HotspotDelineation'; static $explanationLangVar = 'HotspotDelineation';
@ -115,4 +105,4 @@ class HotSpotDelineation extends HotSpot {
parent::processAnswersCreation ($form); parent::processAnswersCreation ($form);
} }
} }
endif;

@ -2,7 +2,6 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
*
* Class Matching * Class Matching
* Matching questions type class * Matching questions type class
* *

@ -1,7 +1,8 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
CLASS MultipleAnswer * Class MultipleAnswer
* *
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), * This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question * extending the class question

@ -1,10 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Code * Class MultipleAnswer
*/
/**
CLASS MultipleAnswer
* *
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), * This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question * extending the class question
@ -12,8 +9,8 @@
* @author Eric Marguin * @author Eric Marguin
* @package chamilo.exercise * @package chamilo.exercise
**/ **/
class MultipleAnswerCombination extends Question
class MultipleAnswerCombination extends Question { {
static $typePicture = 'mcmac.gif'; static $typePicture = 'mcmac.gif';
static $explanationLangVar = 'MultipleSelectCombination'; static $explanationLangVar = 'MultipleSelectCombination';
@ -21,7 +18,8 @@ class MultipleAnswerCombination extends Question {
/** /**
* Constructor * Constructor
*/ */
function MultipleAnswerCombination(){ function MultipleAnswerCombination()
{
parent::question(); parent::question();
$this -> type = MULTIPLE_ANSWER_COMBINATION; $this -> type = MULTIPLE_ANSWER_COMBINATION;
$this -> isContent = $this-> getIsContent(); $this -> isContent = $this-> getIsContent();
@ -29,10 +27,11 @@ class MultipleAnswerCombination extends Question {
/** /**
* function which redifines Question::createAnswersForm * function which redifines Question::createAnswersForm
* @param the formvalidator instance * @param $form FormValidator
* @param the answers number to display * @param the answers number to display
*/ */
function createAnswersForm ($form) { function createAnswersForm ($form)
{
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2; $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2;
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); $nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
$obj_ex = $_SESSION['objExercise']; $obj_ex = $_SESSION['objExercise'];
@ -93,7 +92,6 @@ class MultipleAnswerCombination extends Question {
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer['.$i.']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment['.$i.']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment['.$i.']');
$answer_number=$form->addElement('text', 'counter['.$i.']', null,'value="'.$i.'"'); $answer_number=$form->addElement('text', 'counter['.$i.']', null,'value="'.$i.'"');
$answer_number->freeze(); $answer_number->freeze();
@ -131,11 +129,10 @@ class MultipleAnswerCombination extends Question {
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'),'class="btn minus"'); $form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'),'class="btn minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"'); $form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"');
$form->addElement('style_submit_button', 'submitQuestion',$text, 'class="'.$class.'"'); $form->addElement('style_submit_button', 'submitQuestion',$text, 'class="'.$class.'"');
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
} }
} }
$renderer->setElementTemplate('{element}&nbsp;','lessAnswers'); $renderer->setElementTemplate('{element}&nbsp;','lessAnswers');
$renderer->setElementTemplate('{element}&nbsp;','submitQuestion'); $renderer->setElementTemplate('{element}&nbsp;','submitQuestion');
$renderer->setElementTemplate('{element}&nbsp;','moreAnswers'); $renderer->setElementTemplate('{element}&nbsp;','moreAnswers');
@ -157,8 +154,8 @@ class MultipleAnswerCombination extends Question {
* @param the formvalidator instance * @param the formvalidator instance
* @param the answers number to display * @param the answers number to display
*/ */
function processAnswersCreation($form) { function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0; $questionWeighting = $nbrGoodAnswers = 0;
$objAnswer = new Answer($this->id); $objAnswer = new Answer($this->id);
@ -197,7 +194,8 @@ class MultipleAnswerCombination extends Question {
$this -> save(); $this -> save();
} }
function return_header($feedback_type = null, $counter = null, $score = null) { function return_header($feedback_type = null, $counter = null, $score = null)
{
$header = parent::return_header($feedback_type, $counter, $score); $header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class .'"> $header .= '<table class="'.$this->question_table_class .'">
<tr> <tr>

@ -1,10 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Code * Class MultipleAnswer
*/
/**
CLASS MultipleAnswer
* *
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), * This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question * extending the class question

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Class MultipleAnswerTrueFalse * Class MultipleAnswerTrueFalse
* This class allows to instantiate an object of type MULTIPLE_ANSWER * This class allows to instantiate an object of type MULTIPLE_ANSWER

@ -1,24 +1,22 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Code * Class OralExpression
*/
/**
* File containing the FreeAnswer class.
* This class allows to instantiate an object of type FREE_ANSWER, * This class allows to instantiate an object of type FREE_ANSWER,
* extending the class question * extending the class question
* @author Eric Marguin * @author Eric Marguin
* @package chamilo.exercise * @package chamilo.exercise
*/ */
class OralExpression extends Question { class OralExpression extends Question
{
static $typePicture = 'audio_question.png'; static $typePicture = 'audio_question.png';
static $explanationLangVar = 'OralExpression'; static $explanationLangVar = 'OralExpression';
/** /**
* Constructor * Constructor
*/ */
function OralExpression(){ function OralExpression()
{
parent::question(); parent::question();
$this -> type = ORAL_EXPRESSION; $this -> type = ORAL_EXPRESSION;
$this -> isContent = $this-> getIsContent(); $this -> isContent = $this-> getIsContent();
@ -26,9 +24,10 @@ class OralExpression extends Question {
/** /**
* function which redifines Question::createAnswersForm * function which redifines Question::createAnswersForm
* @param the formvalidator instance * @param $form FormValidator
*/ */
function createAnswersForm ($form) { function createAnswersForm ($form)
{
$form -> addElement('text','weighting',get_lang('Weighting'), array('class' => 'span1')); $form -> addElement('text','weighting',get_lang('Weighting'), array('class' => 'span1'));
global $text, $class; global $text, $class;
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
@ -46,12 +45,14 @@ class OralExpression extends Question {
* abstract function which creates the form to create / edit the answers of the question * abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance * @param the formvalidator instance
*/ */
function processAnswersCreation($form) { function processAnswersCreation($form)
{
$this->weighting = $form -> getSubmitValue('weighting'); $this->weighting = $form -> getSubmitValue('weighting');
$this->save(); $this->save();
} }
function return_header($feedback_type = null, $counter = null, $score = null) { function return_header($feedback_type = null, $counter = null, $score = null)
{
$header = parent::return_header($feedback_type, $counter, $score); $header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class.'"> $header .= '<table class="'.$this->question_table_class.'">
<tr> <tr>
@ -63,6 +64,7 @@ class OralExpression extends Question {
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
</tr>'; </tr>';
return $header; return $header;
} }
} }

@ -1,15 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/**
* File containing the Question class.
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya <gugli100@gmail.com> lot of bug fixes
* Modified by hubert.borderiou@grenet.fr - add question categories
*/
/**
* Code
*/
// Question types // Question types
define('UNIQUE_ANSWER', 1); define('UNIQUE_ANSWER', 1);
@ -35,12 +25,14 @@ define('MCMA', 2);
define('FIB', 3); define('FIB', 3);
/** /**
QUESTION CLASS * Class Question
* *
* This class allows to instantiate an object of type Question * This class allows to instantiate an object of type Question
* *
* @author Olivier Brouckaert, original author * @author Olivier Brouckaert, original author
* @author Patrick Cool, LaTeX support * @author Patrick Cool, LaTeX support
* @author Julio Montoya <gugli100@gmail.com> lot of bug fixes
* @author hubert.borderiou@grenet.fr - add question categories
* @package chamilo.exercise * @package chamilo.exercise
*/ */
abstract class Question abstract class Question
@ -101,7 +93,8 @@ abstract class Question
$this->parent_id = 0; $this->parent_id = 0;
} }
public function getIsContent() { public function getIsContent()
{
$isContent = null; $isContent = null;
if (isset($_REQUEST['isContent'])) { if (isset($_REQUEST['isContent'])) {
$isContent = intval($_REQUEST['isContent']); $isContent = intval($_REQUEST['isContent']);
@ -117,7 +110,8 @@ abstract class Question
* *
* @return Question * @return Question
*/ */
static function read($id, $course_id = null) { static function read($id, $course_id = null)
{
$id = intval($id); $id = intval($id);
if (!empty($course_id)) { if (!empty($course_id)) {
@ -167,9 +161,11 @@ abstract class Question
$objQuestion->exerciseList[] = $obj->exercice_id; $objQuestion->exerciseList[] = $obj->exercice_id;
} }
} }
return $objQuestion; return $objQuestion;
} }
} }
// question not found // question not found
return false; return false;
} }
@ -180,7 +176,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @return - integer - question ID * @return - integer - question ID
*/ */
function selectId() { function selectId()
{
return $this->id; return $this->id;
} }
@ -190,7 +187,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @return string - question title * @return string - question title
*/ */
function selectTitle() { function selectTitle()
{
return $this->question; return $this->question;
} }
@ -200,7 +198,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @return string - question description * @return string - question description
*/ */
function selectDescription() { function selectDescription()
{
$this->description=text_filter($this->description); $this->description=text_filter($this->description);
return $this->description; return $this->description;
} }
@ -222,7 +221,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @return integer - question position * @return integer - question position
*/ */
function selectPosition() { function selectPosition()
{
return $this->position; return $this->position;
} }
@ -232,7 +232,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @return integer - answer type * @return integer - answer type
*/ */
function selectType() { function selectType()
{
return $this->type; return $this->type;
} }
@ -242,7 +243,8 @@ abstract class Question
* @author Nicolas Raynaud * @author Nicolas Raynaud
* @return integer - level of the question, 0 by default. * @return integer - level of the question, 0 by default.
*/ */
function selectLevel() { function selectLevel()
{
return $this->level; return $this->level;
} }
@ -252,11 +254,13 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @return string - picture name * @return string - picture name
*/ */
function selectPicture() { function selectPicture()
{
return $this->picture; return $this->picture;
} }
function selectPicturePath() { function selectPicturePath()
{
if (!empty($this->picture)) { if (!empty($this->picture)) {
return api_get_path(WEB_COURSE_PATH).$this->course['path'].'/document/images/'.$this->picture; return api_get_path(WEB_COURSE_PATH).$this->course['path'].'/document/images/'.$this->picture;
} }
@ -269,7 +273,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @return array - list of exercise ID which the question is in * @return array - list of exercise ID which the question is in
*/ */
function selectExerciseList() { function selectExerciseList()
{
return $this->exerciseList; return $this->exerciseList;
} }
@ -360,7 +365,8 @@ abstract class Question
foreach ($category_list as $category_id) { foreach ($category_list as $category_id) {
$category_id = intval($category_id); $category_id = intval($category_id);
$question_id = Database::escape_string($this->id); $question_id = Database::escape_string($this->id);
$sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY WHERE category_id = $category_id AND question_id = $question_id AND c_id=".api_get_course_int_id(); $sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY
WHERE category_id = $category_id AND question_id = $question_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql); $res = Database::query($sql);
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
if ($row['nb'] > 0) { if ($row['nb'] > 0) {
@ -369,7 +375,7 @@ abstract class Question
//$res = Database::query($sql); //$res = Database::query($sql);
} else { } else {
$sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY (c_id, question_id, category_id) VALUES (".api_get_course_int_id().", $question_id, $category_id)"; $sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY (c_id, question_id, category_id) VALUES (".api_get_course_int_id().", $question_id, $category_id)";
$res = Database::query($sql); Database::query($sql);
} }
} }
} }
@ -377,11 +383,12 @@ abstract class Question
/** /**
* @author Hubert Borderiou 12-10-2011 * @author Hubert Borderiou 12-10-2011
* @param int $in_positive * @param int $in_category
* in this version, a question can only have 1 category * in this version, a question can only have 1 category
* if category is 0, then question has no category then delete the category entry * if category is 0, then question has no category then delete the category entry
*/ */
function saveCategory($in_category) { function saveCategory($in_category)
{
if ($in_category <= 0) { if ($in_category <= 0) {
$this->deleteCategory(); $this->deleteCategory();
} else { } else {
@ -390,15 +397,16 @@ abstract class Question
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$category_id = Database::escape_string($in_category); $category_id = Database::escape_string($in_category);
$question_id = Database::escape_string($this->id); $question_id = Database::escape_string($this->id);
$sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); $sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY
WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql); $res = Database::query($sql);
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
if ($row['nb'] > 0){ if ($row['nb'] > 0){
$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id=$category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); $sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id=$category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql); Database::query($sql);
} else { } else {
$sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY VALUES (".api_get_course_int_id().", $question_id, $category_id)"; $sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY VALUES (".api_get_course_int_id().", $question_id, $category_id)";
$res = Database::query($sql); Database::query($sql);
} }
} }
} }
@ -409,10 +417,12 @@ abstract class Question
* @param : none * @param : none
* delte the category for question * delte the category for question
*/ */
function deleteCategory() { function deleteCategory()
{
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$question_id = Database::escape_string($this->id); $question_id = Database::escape_string($this->id);
$sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); $sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY
WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
Database::query($sql); Database::query($sql);
} }
@ -422,7 +432,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @param integer $position - question position * @param integer $position - question position
*/ */
function updatePosition($position) { function updatePosition($position)
{
$this->position=$position; $this->position=$position;
} }
@ -432,7 +443,8 @@ abstract class Question
* @author Nicolas Raynaud * @author Nicolas Raynaud
* @param integer $level - question level * @param integer $level - question level
*/ */
function updateLevel($level) { function updateLevel($level)
{
$this->level=$level; $this->level=$level;
} }
@ -443,7 +455,8 @@ abstract class Question
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @param integer $type - answer type * @param integer $type - answer type
*/ */
function updateType($type) { function updateType($type)
{
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$course_id = $this->course['real_id']; $course_id = $this->course['real_id'];
@ -471,7 +484,8 @@ abstract class Question
* @param string $PictureName - Name of the picture * @param string $PictureName - Name of the picture
* @return boolean - true if uploaded, otherwise false * @return boolean - true if uploaded, otherwise false
*/ */
function uploadPicture($Picture, $PictureName, $picturePath = null) { function uploadPicture($Picture, $PictureName, $picturePath = null)
{
if (empty($picturePath)) { if (empty($picturePath)) {
global $picturePath; global $picturePath;
} }
@ -498,6 +512,7 @@ abstract class Question
return api_item_property_update($this->course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id()); return api_item_property_update($this->course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
} }
} }
return false; return false;
} }
@ -509,7 +524,8 @@ abstract class Question
* @param integer $Max - Maximum size * @param integer $Max - Maximum size
* @return boolean - true if success, false if failed * @return boolean - true if success, false if failed
*/ */
function resizePicture($Dimension, $Max) { function resizePicture($Dimension, $Max)
{
global $picturePath; global $picturePath;
// if the question has an ID // if the question has an ID

@ -1,9 +1,9 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** @author hubert.borderiou **/
/** /**
* Class Testcategory * Class Testcategory
* @author hubert.borderiou
* @todo rename to ExerciseCategory * @todo rename to ExerciseCategory
*/ */
class Testcategory class Testcategory

@ -1,7 +1,8 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* UNIQUE_ANSWER class * Class UniqueAnswer
* *
* This class allows to instantiate an object of type UNIQUE_ANSWER * This class allows to instantiate an object of type UNIQUE_ANSWER
* (MULTIPLE CHOICE, UNIQUE ANSWER), * (MULTIPLE CHOICE, UNIQUE ANSWER),

@ -2,26 +2,14 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* File containing the UNIQUE_ANSWER class. * Class UniqueAnswerNoOption
* @package chamilo.exercise * Allows to instantiate an object of type UNIQUE_ANSWER (MULTIPLE CHOICE, UNIQUE ANSWER),
* @author Eric Marguin
*/
/**
* Code
*/
/**
CLASS UNIQUE_ANSWER
*
* This class allows to instantiate an object of type UNIQUE_ANSWER (MULTIPLE CHOICE, UNIQUE ANSWER),
* extending the class question * extending the class question
*
* @author Eric Marguin * @author Eric Marguin
* @author Julio Montoya * @author Julio Montoya
* @package chamilo.exercise * @package chamilo.exercise
**/ *
*/
class UniqueAnswerNoOption extends Question class UniqueAnswerNoOption extends Question
{ {
static $typePicture = 'mcuao.gif'; static $typePicture = 'mcuao.gif';
@ -30,7 +18,8 @@ class UniqueAnswerNoOption extends Question
/** /**
* Constructor * Constructor
*/ */
function UniqueAnswerNoOption(){ function UniqueAnswerNoOption()
{
//this is highly important //this is highly important
parent::question(); parent::question();
$this -> type = UNIQUE_ANSWER_NO_OPTION; $this -> type = UNIQUE_ANSWER_NO_OPTION;
@ -42,7 +31,8 @@ class UniqueAnswerNoOption extends Question
* @param the formvalidator instance * @param the formvalidator instance
* @param the answers number to display * @param the answers number to display
*/ */
function createAnswersForm ($form) { function createAnswersForm ($form)
{
// getting the exercise list // getting the exercise list
$obj_ex = $_SESSION['objExercise']; $obj_ex = $_SESSION['objExercise'];
@ -277,10 +267,7 @@ class UniqueAnswerNoOption extends Question
} }
$form->addElement('hidden', 'nb_answers'); $form->addElement('hidden', 'nb_answers');
$form->setConstants(array('nb_answers' => $nb_answers)); $form->setConstants(array('nb_answers' => $nb_answers));
} }
@ -289,8 +276,8 @@ class UniqueAnswerNoOption extends Question
* @param the formvalidator instance * @param the formvalidator instance
* @param the answers number to display * @param the answers number to display
*/ */
function processAnswersCreation($form) { function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0; $questionWeighting = $nbrGoodAnswers = 0;
$correct = $form -> getSubmitValue('correct'); $correct = $form -> getSubmitValue('correct');
$objAnswer = new Answer($this->id); $objAnswer = new Answer($this->id);
@ -307,9 +294,6 @@ class UniqueAnswerNoOption extends Question
$weighting = trim($form -> getSubmitValue('weighting['.$i.']')); $weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
$scenario = $form -> getSubmitValue('scenario'); $scenario = $form -> getSubmitValue('scenario');
//
//$list_destination = $form -> getSubmitValue('destination'.$i); //$list_destination = $form -> getSubmitValue('destination'.$i);
//$destination_str = $form -> getSubmitValue('destination'.$i); //$destination_str = $form -> getSubmitValue('destination'.$i);
@ -386,7 +370,8 @@ class UniqueAnswerNoOption extends Question
$this -> save(); $this -> save();
} }
function return_header($feedback_type = null, $counter = null, $score = null) { function return_header($feedback_type = null, $counter = null, $score = null)
{
$header = parent::return_header($feedback_type, $counter, $score); $header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class .'"> $header .= '<table class="'.$this->question_table_class .'">
<tr> <tr>

Loading…
Cancel
Save