From f4f45552bc40fde6a05cc569801ea93bc7bd80fd Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Sat, 29 Apr 2017 02:25:35 -0500 Subject: [PATCH] Use default form builder and improve hidden display for READING_COMPREHENSION question type - refs #1896 --- main/exercise/ReadingComprehension.php | 75 +------------------ main/inc/lib/exercise.lib.php | 32 ++++++-- .../exercise/reading_comprehension.tpl | 8 +- 3 files changed, 33 insertions(+), 82 deletions(-) diff --git a/main/exercise/ReadingComprehension.php b/main/exercise/ReadingComprehension.php index 1e6ac6f3b7..d82f5def75 100755 --- a/main/exercise/ReadingComprehension.php +++ b/main/exercise/ReadingComprehension.php @@ -26,8 +26,8 @@ class ReadingComprehension extends UniqueAnswer 1 => 50, 2 => 100, 3 => 175, - 4 => 250, - 5 => 400 + 4 => 300, + 5 => 600 ]; /** * The number of words in the question description (which serves as the @@ -56,75 +56,6 @@ class ReadingComprehension extends UniqueAnswer $this->isContent = $this->getIsContent(); } - public function createAnswersForm($form) - { - $form->addTextarea('text', get_lang('Text'), ['rows' => '15']); - - parent::createAnswersForm($form); - } - - public function processAnswersCreation($form) - { - $text = $form->exportValue('text'); - - $objAnswer = new Answer($this->id); - $objAnswer->createAnswer($text, false, null, 0, 0); - - $questionWeighting = $nbrGoodAnswers = 0; - $correct = $form->getSubmitValue('correct'); - $nb_answers = $form->getSubmitValue('nb_answers'); - - for ($i = 1; $i <= $nb_answers; $i++) { - $answer = trim($form->getSubmitValue('answer[' . $i . ']')); - $comment = trim($form->getSubmitValue('comment[' . $i . ']')); - $weighting = trim($form->getSubmitValue('weighting[' . $i . ']')); - $scenario = $form->getSubmitValue('scenario'); - - $try = $scenario['try' . $i]; - $lp = $scenario['lp' . $i]; - $destination = $scenario['destination' . $i]; - $url = trim($scenario['url' . $i]); - - $goodAnswer = $correct == $i ? true : false; - - if ($goodAnswer) { - $nbrGoodAnswers++; - $weighting = abs($weighting); - - if ($weighting > 0) { - $questionWeighting += $weighting; - } - } - - if (empty($try)) { - $try = 0; - } - - if (empty($lp)) { - $lp = 0; - } - - if (empty($destination)) { - $destination = 0; - } - - if ($url == '') { - $url = 0; - } - - //1@@1;2;@@2;4;4;@@http://www.chamilo.org - $dest = $try . '@@' . $lp . '@@' . $destination . '@@' . $url; - $objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest); - } - - // saves the answers into the data base - $objAnswer->save(); - - // sets the total weighting of the question - $this->updateWeighting($questionWeighting); - $this->save(); - } - private function displayReading($wordsCount, $turns, $text) { $view = new Template('', false, false, false, true, false, false); @@ -154,7 +85,7 @@ class ReadingComprehension extends UniqueAnswer $indexes = array_keys($words); $tagEnd = ''; - $tagStart = $tagEnd.''; + $tagStart = $tagEnd.''; $turns = ceil( count($words) / $this->expectedWordsPerRefresh diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 6076b6057c..21536bb64f 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -65,10 +65,21 @@ class ExerciseLib $questionDescription = $objQuestionTmp->selectDescription(); if ($show_title) { TestCategory::displayCategoryAndTitle($objQuestionTmp->id); - - echo $objQuestionTmp->getTitleToDisplay($current_item); + $titleToDisplay = null; + if ($answerType == READING_COMPREHENSION) { + // In READING_COMPREHENSION, the title of the question + // contains the question itself, which can only be + // shown at the end of the given time, so hide for now + $titleToDisplay = Display::div( + $current_item.'. '.get_lang('ReadingComprehension'), + ['class' => 'question_title'] + ); + } else { + $titleToDisplay = $objQuestionTmp->getTitleToDisplay($current_item); + } + echo $titleToDisplay; } - if (!empty($questionDescription)) { + if (!empty($questionDescription) && $answerType != READING_COMPREHENSION) { echo Display::div( $questionDescription, array('class' => 'question_description') @@ -271,16 +282,21 @@ class ExerciseLib } } + $hidingClass = ''; if ($answerType == READING_COMPREHENSION) { $objQuestionTmp->processText( - $objAnswerTmp->selectAnswer(1) + $objQuestionTmp->selectDescription() + ); + $hidingClass = 'hide-reading-answers'; + } + if ($answerType == READING_COMPREHENSION) { + $s .= Display::div( + $objQuestionTmp->selectTitle(), + ['class' => 'question_title '.$hidingClass] ); } for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { - if ($answerType == READING_COMPREHENSION && $answerId === 1) { - $answerId++; - } $answer = $objAnswerTmp->selectAnswer($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId); @@ -348,7 +364,7 @@ class ExerciseLib $answer = '
' . $answer . '
'; } - $answer_input .= '