Questtype ?textinput?: store number of correct answers between redirects (fixes #90)
This commit is contained in:
parent
989a0019c3
commit
f5a8e51cbd
4 changed files with 35 additions and 18 deletions
Binary file not shown.
|
|
@ -2,7 +2,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: The Legend of Z\n"
|
"Project-Id-Version: The Legend of Z\n"
|
||||||
"POT-Creation-Date: 2015-04-19 14:15+0100\n"
|
"POT-Creation-Date: 2015-04-19 14:15+0100\n"
|
||||||
"PO-Revision-Date: 2015-04-19 14:16+0100\n"
|
"PO-Revision-Date: 2015-04-20 21:06+0100\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"Language: de_DE\n"
|
"Language: de_DE\n"
|
||||||
|
|
@ -342,7 +342,7 @@ msgstr "Felder"
|
||||||
#: questtypes/textinput/html/quest.tpl:13
|
#: questtypes/textinput/html/quest.tpl:13
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "You filled %d of %d fields correctly"
|
msgid "You filled %d of %d fields correctly"
|
||||||
msgstr "Du hast %d von %d Feldern korrekt ausgefüllt"
|
msgstr "Du hast %d von %d Felder korrekt ausgefüllt"
|
||||||
|
|
||||||
#: views/ajax/quests/index.tpl:9 views/html/quests/create.tpl:79
|
#: views/ajax/quests/index.tpl:9 views/html/quests/create.tpl:79
|
||||||
#: views/html/quests/edit.tpl:82 views/html/quests/index.tpl:27
|
#: views/html/quests/edit.tpl:82 views/html/quests/index.tpl:27
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,15 @@
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $components = array('validation');
|
public $components = array('validation', 'questtypedata');
|
||||||
|
/**
|
||||||
|
* Count of correct answers
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
const KEY_QUESTTYPEDATA_N_CORRECT_ANSWRES = 'nCorrectAnswers';
|
||||||
|
|
||||||
|
private $nCorrectAnswers = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,22 +89,31 @@
|
||||||
{
|
{
|
||||||
// Get right answers
|
// Get right answers
|
||||||
$fields = $this->Textinput->getTextinputFields($quest['id']);
|
$fields = $this->Textinput->getTextinputFields($quest['id']);
|
||||||
|
|
||||||
// Match regexs with user answers
|
// Match regexs with user answers
|
||||||
|
$nCorrectAnswers = 0;
|
||||||
foreach($fields as &$field)
|
foreach($fields as &$field)
|
||||||
{
|
{
|
||||||
$pos = intval($field['number']) - 1;
|
$pos = intval($field['number']) - 1;
|
||||||
if(!array_key_exists($pos, $answers)) {
|
if(!array_key_exists($pos, $answers)) {
|
||||||
return false;
|
continue;
|
||||||
}
|
}
|
||||||
if(!$this->isMatching($field['regex'], $answers[$pos])) {
|
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
|
// All answers right
|
||||||
return true;
|
return ($nCorrectAnswers == count($fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -124,26 +141,26 @@
|
||||||
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
||||||
|
|
||||||
// Get Character answers
|
// Get Character answers
|
||||||
$correctAnswersCount = null;
|
|
||||||
if(!$solved || $this->request->getGetParam('show-answer') == 'true' || $this->request->getGetParam('status') == 'solved')
|
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']);
|
$field['answer'] = $this->Textinput->getCharacterSubmission($field['id'], $character['id']);
|
||||||
$correctAnswersCount += $this->isMatching($field['regex'], $field['answer']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show count
|
// Get count of last correct answers
|
||||||
$showcount = (count($this->request->getGetParams()) > 1);
|
$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
|
// Pass data to view
|
||||||
$this->set('task', $task);
|
$this->set('task', $task);
|
||||||
$this->set('fields', $fields);
|
$this->set('fields', $fields);
|
||||||
$this->set('count', $correctAnswersCount);
|
$this->set('nCorrectAnswers', $nCorrectAnswers);
|
||||||
$this->set('showcount', $showcount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||||
</p>
|
</p>
|
||||||
<?php if($showcount) : ?>
|
<?php if(!is_null($nCorrectAnswers)) : ?>
|
||||||
<p><?=sprintf(_('You filled %d of %d fields correctly'), $count, count($fields))?>.</p>
|
<p><?=sprintf(_('You filled %d of %d fields correctly'), $nCorrectAnswers, count($fields))?>.</p>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue