diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php
index f655b5739c..0bdda2df01 100644
--- a/main/exercice/answer.class.php
+++ b/main/exercice/answer.class.php
@@ -106,7 +106,7 @@ class Answer
}
/**
- * Reads answer informations from the data base
+ * Reads answer from the data base
*
* @author - Olivier Brouckaert
*/
diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php
index a96a5df88b..7300c650d4 100644
--- a/main/exercice/exercise.class.php
+++ b/main/exercice/exercise.class.php
@@ -1650,7 +1650,8 @@ class Exercise
);
if (api_get_setting('enable_quiz_scenario') == 'true') {
- //Can't convert a question from one feedback to another if there is more than 1 question already added
+ /* Can't convert a question from one feedback to another if there
+ is more than 1 question already added */
if ($this->selectNbrQuestions() == 0) {
$radios_feedback[] = $form->createElement(
'radio',
@@ -1706,7 +1707,6 @@ class Exercise
'2',
array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()')
);
- //$radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ExamModeWithFinalScoreShowOnlyFinalScoreWithCategoriesIfAvailable'), '3', array('id'=>'result_disabled_3','onclick' => 'check_results_disabled()'));
$form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
} else {
@@ -1903,12 +1903,6 @@ class Exercise
array('id' => 'randomQuestions')
);
- // Random answers.
- $radios_random_answers = array(
- $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1'),
- $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0')
- );
- $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), '');
$form->addElement('html', '');
@@ -1921,16 +1915,6 @@ class Exercise
$form->addElement('html', '');
- // Random by category.
- /*
- $form->addElement('html', '
');
- $radiocat = array(
- $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesShuffled'), '1'),
- $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesSorted'), '2'),
- $form->createElement('radio', 'randomByCat', null, get_lang('No'), '0')
- );
- $form->addGroup($radiocat, null, get_lang('RandomQuestionByCategory'), '');
- $form->addElement('html', '
');*/
// Category name.
$radio_display_cat_name = array(
@@ -1939,8 +1923,14 @@ class Exercise
);
$form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), '');
- // Hide question title
+ // Random answers.
+ $radios_random_answers = array(
+ $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1'),
+ $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0')
+ );
+ $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), '');
+ // Hide question title.
$group = array(
$form->createElement('radio', 'hide_question_title', null, get_lang('Yes'), '1'),
$form->createElement('radio', 'hide_question_title', null, get_lang('No'), '0')
@@ -6368,7 +6358,7 @@ class Exercise
// Shows the question + possible answers
$showTitle = $this->getHideQuestionTitle() == 1 ? false : true;
- echo ExerciseLib::showQuestion($question_obj, false, $origin, $i, $showTitle, false, $user_choice, false, null, false, $this->getModelType(), $this->categoryMinusOne);
+ echo $this->showQuestion($question_obj, false, $origin, $i, $showTitle, false, $user_choice, false, null, false, $this->getModelType(), $this->categoryMinusOne);
// Button save and continue
switch ($this->type) {
@@ -6756,7 +6746,901 @@ class Exercise
$categoriesInExercise = Database::store_result($result, 'ASSOC');
}
return $categoriesInExercise;
+ }
+
+ /**
+ * Shows a question
+ * @param Question $objQuestionTmp
+ * @param bool $only_questions if true only show the questions, no exercise title
+ * @param bool $origin origin i.e = learnpath
+ * @param string $current_item current item from the list of questions
+ * @param bool $show_title
+ * @param bool $freeze
+ * @param array $user_choice
+ * @param bool $show_comment
+ * @param null $exercise_feedback
+ * @param bool $show_answers
+ * @param null $modelType
+ * @param bool $categoryMinusOne
+ * @return bool|null|string
+ */
+ public function showQuestion(
+ Question $objQuestionTmp,
+ $only_questions = false,
+ $origin = false,
+ $current_item = '',
+ $show_title = true,
+ $freeze = false,
+ $user_choice = array(),
+ $show_comment = false,
+ $exercise_feedback = null,
+ $show_answers = false,
+ $modelType = null,
+ $categoryMinusOne = true
+ ) {
+ // Text direction for the current language
+ //$is_ltr_text_direction = api_get_text_direction() != 'rtl';
+ // Change false to true in the following line to enable answer hinting
+ $debug_mark_answer = $show_answers; //api_is_allowed_to_edit() && false;
+ // Reads question information
+ if (!$objQuestionTmp) {
+ // Question not found
+ return false;
+ }
+
+ $html = null;
+
+ $questionId = $objQuestionTmp->id;
+
+ if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
+ $show_comment = false;
+ }
+
+ $answerType = $objQuestionTmp->selectType();
+ $pictureName = $objQuestionTmp->selectPicture();
+
+ $s = null;
+ $form = new FormValidator('question');
+ $renderer = $form->defaultRenderer();
+ $form_template = '{content}';
+ $renderer->setFormTemplate($form_template);
+
+ if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
+ // Question is not a hotspot
+ if (!$only_questions) {
+ $questionDescription = $objQuestionTmp->selectDescription();
+ if ($show_title) {
+ $categoryName = Testcategory::getCategoryNamesForQuestion($objQuestionTmp->id, null, true, $categoryMinusOne);
+ $html .= $categoryName;
+ $html .= Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class' => 'question_title'));
+ if (!empty($questionDescription)) {
+ $html .= Display::div($questionDescription, array('class' => 'question_description'));
+ }
+ } else {
+ $html .= '';
+ }
+ }
+
+ if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
+ return null;
+ }
+
+ $html .= '';
+ // construction of the Answer object (also gets all answers details)
+ $objAnswerTmp = new Answer($questionId, null, $this);
+
+ $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
+ $course_id = api_get_course_int_id();
+ $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
+
+ // For "matching" type here, we need something a little bit special
+ // because the match between the suggestions and the answers cannot be
+ // done easily (suggestions and answers are in the same table), so we
+ // have to go through answers first (elems with "correct" value to 0).
+ $select_items = array();
+ //This will contain the number of answers on the left side. We call them
+ // suggestions here, for the sake of comprehensions, while the ones
+ // on the right side are called answers
+ $num_suggestions = 0;
+
+ if ($answerType == MATCHING || $answerType == DRAGGABLE) {
+ if ($answerType == DRAGGABLE) {
+ $s .= '