Questtype ?textinput?: small simplifications

This commit is contained in:
coderkun 2014-05-19 12:04:44 +02:00
commit 8f6fdb3fa2
3 changed files with 18 additions and 17 deletions

View file

@ -76,26 +76,20 @@
$fields = $this->Textinput->getTextinputFields($quest['id']); $fields = $this->Textinput->getTextinputFields($quest['id']);
// Match regexs with user answers // Match regexs with user answers
$allSolved = true;
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;
{
$allSolved = false;
break;
} }
if(!$this->isMatching($field['regex'], $answers[$pos])) if(!$this->isMatching($field['regex'], $answers[$pos])) {
{ return false;
$allSolved = false;
break;
} }
} }
// Set status // All answers right
return $allSolved; return true;
} }

View file

@ -11,9 +11,13 @@
$posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8'); $posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8');
// Create input field // Create input field
$class = ($field['size'] != 'default') ? $field['size'] : null; $class = ($field['size'] != 'default') ? $field['size'] : '';
$value = (array_key_exists('answer', $field)) ? $field['answer'] : null; $value = (array_key_exists('answer', $field)) ? $field['answer'] : '';
$inputField = '<input type="text" name="answers[]" value="'.$value.'" class="'.$class.'" />'; $inputField = sprintf(
'<input type="text" name="answers[]" value="%s" class="%s" />',
$value,
$class
);
// Insert input field // Insert input field
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $inputField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8'); $text = mb_substr($text, 0, $posStart, 'UTF-8') . $inputField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');

View file

@ -10,8 +10,11 @@
$posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8'); $posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8');
// Create field for Character answer // Create field for Character answer
$answerField = '<span style="background-color:grey">'.$field['answer'].'</span>'; $answerField = sprintf(
$answerField .= ($field['right']) ? '✓' : '✕'; '<span style="background-color:grey">%s</span>%s',
$field['answer'],
($field['right']) ? '✓' : '✕'
);
// Insert input field // Insert input field
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $answerField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8'); $text = mb_substr($text, 0, $posStart, 'UTF-8') . $answerField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');