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']);
// Match regexs with user answers
$allSolved = true;
foreach($fields as &$field)
{
$pos = intval($field['number']) - 1;
if(!array_key_exists($pos, $answers))
{
$allSolved = false;
break;
if(!array_key_exists($pos, $answers)) {
return false;
}
if(!$this->isMatching($field['regex'], $answers[$pos]))
{
$allSolved = false;
break;
if(!$this->isMatching($field['regex'], $answers[$pos])) {
return false;
}
}
// Set status
return $allSolved;
// All answers right
return true;
}

View file

@ -11,9 +11,13 @@
$posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8');
// Create input field
$class = ($field['size'] != 'default') ? $field['size'] : null;
$value = (array_key_exists('answer', $field)) ? $field['answer'] : null;
$inputField = '<input type="text" name="answers[]" value="'.$value.'" class="'.$class.'" />';
$class = ($field['size'] != 'default') ? $field['size'] : '';
$value = (array_key_exists('answer', $field)) ? $field['answer'] : '';
$inputField = sprintf(
'<input type="text" name="answers[]" value="%s" class="%s" />',
$value,
$class
);
// Insert input field
$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');
// Create field for Character answer
$answerField = '<span style="background-color:grey">'.$field['answer'].'</span>';
$answerField .= ($field['right']) ? '✓' : '✕';
$answerField = sprintf(
'<span style="background-color:grey">%s</span>%s',
$field['answer'],
($field['right']) ? '✓' : '✕'
);
// Insert input field
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $answerField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');