Questtype ?Textinput?: add support for field sizes (Issue #252) and general improvements
This commit is contained in:
parent
6cb12a0b7a
commit
b7a7299b45
4 changed files with 88 additions and 58 deletions
|
|
@ -34,15 +34,15 @@
|
|||
*/
|
||||
public function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get regexs
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
// Get fields
|
||||
$fields = $this->Textinput->getTextinputFields($quest['id']);
|
||||
|
||||
// Save answers
|
||||
foreach($regexs as &$regex)
|
||||
foreach($fields as &$field)
|
||||
{
|
||||
$pos = intval($regex['number']) - 1;
|
||||
$pos = intval($field['number']) - 1;
|
||||
$answer = (array_key_exists($pos, $answers)) ? $answers[$pos] : '';
|
||||
$this->Textinput->setCharacterSubmission($regex['id'], $character['id'], $answer);
|
||||
$this->Textinput->setCharacterSubmission($field['id'], $character['id'], $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,19 +73,20 @@
|
|||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get right answers
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
$fields = $this->Textinput->getTextinputFields($quest['id']);
|
||||
|
||||
// Match regexs with user answers
|
||||
$allSolved = true;
|
||||
foreach($regexs as $i => &$regex)
|
||||
foreach($fields as &$field)
|
||||
{
|
||||
if(!array_key_exists($i, $answers))
|
||||
$pos = intval($field['number']) - 1;
|
||||
|
||||
if(!array_key_exists($pos, $answers))
|
||||
{
|
||||
$allSolved = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!$this->isMatching($regex['regex'], $answers[$i]))
|
||||
if(!$this->isMatching($field['regex'], $answers[$pos]))
|
||||
{
|
||||
$allSolved = false;
|
||||
break;
|
||||
|
|
@ -115,26 +116,23 @@
|
|||
// Get Task
|
||||
$task = $this->Textinput->getTextinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', ' '.$task['text'].' ', -1, PREG_SPLIT_NO_EMPTY);
|
||||
// Get fields
|
||||
$fields = $this->Textinput->getTextinputFields($quest['id']);
|
||||
|
||||
// Has Character already solved Quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
||||
|
||||
// Get Character answers
|
||||
$regexs = null;
|
||||
if(!$solved || $this->request->getGetParam('show-answer') == 'true' || $this->request->getGetParam('status') == 'solved')
|
||||
{
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
foreach($regexs as &$regex) {
|
||||
$regex['answer'] = $this->Textinput->getCharacterSubmission($regex['id'], $character['id']);
|
||||
if(!$solved || $this->request->getGetParam('show-answer') == 'true' || $this->request->getGetParam('status') == 'solved') {
|
||||
foreach($fields as &$field) {
|
||||
$field['answer'] = $this->Textinput->getCharacterSubmission($field['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('regexs', $regexs);
|
||||
$this->set('task', $task);
|
||||
$this->set('fields', $fields);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -154,19 +152,22 @@
|
|||
$task = $this->Textinput->getTextinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', $task['text'], -1, PREG_SPLIT_NO_EMPTY);
|
||||
$textParts = preg_split('/(\$\$)/', ' '.$task['text'].' ');
|
||||
|
||||
// Get fields
|
||||
$fields = $this->Textinput->getTextinputFields($quest['id']);
|
||||
|
||||
// Get Character answers
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
foreach($regexs as &$regex) {
|
||||
$regex['answer'] = $this->Textinput->getCharacterSubmission($regex['id'], $character['id']);
|
||||
$regex['right'] = $this->isMatching($regex['regex'], $regex['answer']);
|
||||
foreach($fields as &$field)
|
||||
{
|
||||
$field['answer'] = $this->Textinput->getCharacterSubmission($field['id'], $character['id']);
|
||||
$field['right'] = $this->isMatching($field['regex'], $field['answer']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('regexs', $regexs);
|
||||
$this->set('task', $task);
|
||||
$this->set('fields', $fields);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue