From db3bee1aab6743a443feb377735e3e197b306c38 Mon Sep 17 00:00:00 2001
From: oliver
Date: Mon, 20 Apr 2015 21:14:20 +0200
Subject: [PATCH] Questtype ?textinput?: store number of correct answers
between redirects (fixes #90)
---
locale/de_DE/LC_MESSAGES/The Legend of Z.mo | Bin 25931 -> 25930 bytes
locale/de_DE/LC_MESSAGES/The Legend of Z.po | 4 +-
.../TextinputQuesttypeController.inc | 45 ++++++++++++------
questtypes/textinput/html/quest.tpl | 4 +-
4 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/locale/de_DE/LC_MESSAGES/The Legend of Z.mo b/locale/de_DE/LC_MESSAGES/The Legend of Z.mo
index 2f802ca9b240c043c37c77d5b775d9306eeb3d96..0c8ddb6842a847821fb3b2181ce6a1a7a6e9d5af 100644
GIT binary patch
delta 336
zcmX?oit*Gb#tnbO>U9_x7-lCiFo-iSFq}wYV31^BV0e(kz+l9{!0;=Hfx(M`fk8JJ
zB3_Zqz`)PIz%VJ9fq{jAfniZH0|O@m1HisKopoj`SvLgi#$>o7`Pc27<^M0
z7^D~&7$TwKB`FXGRHiU62rw`(G^a2y2r@7*Oo56oOJQJ8VPIg`kix*g#=yXEHHCqJ
zhk=3N4%GaYDf$qDKcz4*NHZ`n{7YeA;ALQ7kV<7>;A3E5&`5U9|y7-lCiFo-iSFq}+cV31^BV0f6sz+l9{!0Textinput->getTextinputFields($quest['id']);
-
+
// Match regexs with user answers
+ $nCorrectAnswers = 0;
foreach($fields as &$field)
{
$pos = intval($field['number']) - 1;
if(!array_key_exists($pos, $answers)) {
- return false;
+ continue;
}
if(!$this->isMatching($field['regex'], $answers[$pos])) {
- return false;
+ continue;
}
+ $nCorrectAnswers++;
}
+
+ // Save count of correct answers
+ $this->Questtypedata->set(
+ $quest['id'],
+ self::KEY_QUESTTYPEDATA_N_CORRECT_ANSWRES,
+ $nCorrectAnswers
+ );
// All answers right
- return true;
+ return ($nCorrectAnswers == count($fields));
}
@@ -124,26 +141,26 @@
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
// Get Character answers
- $correctAnswersCount = null;
if(!$solved || $this->request->getGetParam('show-answer') == 'true' || $this->request->getGetParam('status') == 'solved')
{
- $correctAnswersCount = 0;
- foreach($fields as &$field)
- {
+ foreach($fields as &$field) {
$field['answer'] = $this->Textinput->getCharacterSubmission($field['id'], $character['id']);
- $correctAnswersCount += $this->isMatching($field['regex'], $field['answer']);
}
}
- // Show count
- $showcount = (count($this->request->getGetParams()) > 1);
+ // Get count of last correct answers
+ $nCorrectAnswers = $this->Questtypedata->get($quest['id'], self::KEY_QUESTTYPEDATA_N_CORRECT_ANSWRES);
+ $this->Questtypedata->set(
+ $quest['id'],
+ self::KEY_QUESTTYPEDATA_N_CORRECT_ANSWRES,
+ null
+ );
// Pass data to view
$this->set('task', $task);
$this->set('fields', $fields);
- $this->set('count', $correctAnswersCount);
- $this->set('showcount', $showcount);
+ $this->set('nCorrectAnswers', $nCorrectAnswers);
}
diff --git a/questtypes/textinput/html/quest.tpl b/questtypes/textinput/html/quest.tpl
index 4cbcc7f9..55cee466 100644
--- a/questtypes/textinput/html/quest.tpl
+++ b/questtypes/textinput/html/quest.tpl
@@ -9,8 +9,8 @@
=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
-
- =sprintf(_('You filled %d of %d fields correctly'), $count, count($fields))?>.
+
+ =sprintf(_('You filled %d of %d fields correctly'), $nCorrectAnswers, count($fields))?>.