Use default form builder and improve hidden display for READING_COMPREHENSION question type - refs #1896

pull/2487/head
Yannick Warnier 9 years ago
parent 8ea95b442a
commit f4f45552bc
  1. 75
      main/exercise/ReadingComprehension.php
  2. 32
      main/inc/lib/exercise.lib.php
  3. 8
      main/template/default/exercise/reading_comprehension.tpl

@ -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 = '</span>';
$tagStart = $tagEnd.'<span class="text-highlight">';
$tagStart = $tagEnd.'<span class="text-highlight blur">';
$turns = ceil(
count($words) / $this->expectedWordsPerRefresh

@ -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 = '<div class="thumbnail">' . $answer . '</div>';
}
$answer_input .= '<label class="radio">';
$answer_input .= '<label class="radio '.$hidingClass.'">';
$answer_input .= Display::input(
'radio',
'choice[' . $questionId . ']',

@ -9,7 +9,7 @@
color: #FFF;
text-align: justify;
}
.text-highlight {
.text-highlight.blur {
color:#eee; /* Old browsers don't go transparent. */
text-shadow:
0 0 3px #ddd, /* Many shadows blur out the area around the text */
@ -26,6 +26,9 @@
color: #bbb;
text-shadow: none;
}
.radio.hide-reading-answers, .question_title.hide-reading-answers {
display: none;
}
</style>
<script>
@ -39,7 +42,8 @@
if (index >= total) {
window.clearInterval(timeOuId);
$('.radio').removeClass('hide-reading-answers');
$('.question_title').removeClass('hide-reading-answers');
return;
}

Loading…
Cancel
Save