From ad1da597486c28a0c9c8d11f4948a382ca012604 Mon Sep 17 00:00:00 2001 From: coderkun Date: Tue, 11 Mar 2014 00:49:26 +0100 Subject: [PATCH] save answers for Questtype ?Textinput? --- .../textinput/TextinputQuesttypeController.inc | 12 ++++++++++++ questtypes/textinput/html/index.tpl | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/questtypes/textinput/TextinputQuesttypeController.inc b/questtypes/textinput/TextinputQuesttypeController.inc index e41facfd..ad4073ce 100644 --- a/questtypes/textinput/TextinputQuesttypeController.inc +++ b/questtypes/textinput/TextinputQuesttypeController.inc @@ -31,10 +31,17 @@ */ public function index($questId) { + // Answers + if(!array_key_exists('answers', $_SESSION)) { + $_SESSION['answers'] = array(); + } + $answers = array_key_exists($questId, $_SESSION['answers']) ? $_SESSION['answers'][$questId] : array(); + // Check for submission if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit'))) { // Get right answers + $answers = array(); $regexs = $this->Textinput->getTextinputRegexs($questId); // Match regexs with user answers @@ -42,12 +49,16 @@ for($i=0; $irequest->getPostParam('answer-'.strval($i+1)); + $answers[] = $answer; $score = preg_match($regexs[$i]['regex'], $answer); if($score === 0 || $score === false) { $allSolved = false; } } + // Store answers in session + $_SESSION['answers'][$questId] = $answers; + // Set status if($allSolved) { $this->setQuestSolved(); @@ -67,6 +78,7 @@ // Pass data to view $this->set('text', $textParts); + $this->set('answers', $answers); } } diff --git a/questtypes/textinput/html/index.tpl b/questtypes/textinput/html/index.tpl index b3701630..714d828d 100644 --- a/questtypes/textinput/html/index.tpl +++ b/questtypes/textinput/html/index.tpl @@ -1,7 +1,7 @@
0) : ?> - +