Questtype ?textinput?: show count of correctly filled fields (implements #3)

This commit is contained in:
oliver 2015-04-08 16:24:01 +02:00
commit 2bab62026e
4 changed files with 17 additions and 5 deletions

View file

@ -124,9 +124,14 @@
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
// Get Character answers
if(!$solved || $this->request->getGetParam('show-answer') == 'true' || $this->request->getGetParam('status') == 'solved') {
foreach($fields as &$field) {
$correctAnswersCount = null;
if(!$solved || $this->request->getGetParam('show-answer') == 'true' || $this->request->getGetParam('status') == 'solved')
{
$correctAnswersCount = 0;
foreach($fields as &$field)
{
$field['answer'] = $this->Textinput->getCharacterSubmission($field['id'], $character['id']);
$correctAnswersCount += $this->isMatching($field['regex'], $field['answer']);
}
}
@ -134,6 +139,7 @@
// Pass data to view
$this->set('task', $task);
$this->set('fields', $fields);
$this->set('count', $correctAnswersCount);
}

View file

@ -9,5 +9,6 @@
<?php endforeach ?>
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
</p>
<p><?=sprintf(_('You filled %d of %d fields correctly'), $count, count($fields))?>.</p>
<input type="submit" name="submit" value="<?=_('solve')?>" />
</form>