diff --git a/CHANGELOG.md b/CHANGELOG.md index 88948e4d..992a8303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Changelog ## +### 0.11.2 ### +Fix many answers on many steps + +* Was stuck on 2nd step + + ### 0.11.1 ### Improve steps generating (for sections addon) diff --git a/README.md b/README.md index 3f47bbf9..cf397ea3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ **Tags:** psychological, testing, test, quiz **Requires at least:** 3.2 **Tested up to:** 4.1.1 -**Stable tag:** 0.11.1 +**Stable tag:** 0.11.2 **License:** GPLv3 **License URI:** http://www.gnu.org/licenses/gpl-3.0.html diff --git a/src/Component/StepStrategy.php b/src/Component/StepStrategy.php index 599e7aa4..bf0d2ff7 100644 --- a/src/Component/StepStrategy.php +++ b/src/Component/StepStrategy.php @@ -39,10 +39,10 @@ abstract class WpTesting_Component_StepStrategy */ private $isShowStepsCounter = false; - public function __construct(WpTesting_Model_Test $test = null, fRecordSet $answeredQuestions = null) + public function __construct(WpTesting_Model_Test $test = null, fRecordSet $answeredAnswers = null) { is_null($test) || $this->setTest($test); - $this->answeredQuestions = $answeredQuestions; + $this->answeredQuestions = $this->extractQuestionsFromAnswers($answeredAnswers); } /** @@ -174,4 +174,16 @@ private function setupTotalsAndNumbers() return $this; } + /** + * @param fRecordSet $answers + * @return fRecordSet + */ + private function extractQuestionsFromAnswers(fRecordSet $answers) + { + $questions = array(); + foreach ($answers as $answer) { /* @var $answer WpTesting_Model_Answer */ + $questions[$answer->getQuestionId()] = $answer->createQuestion(); + } + return fRecordSet::buildFromArray('WpTesting_Model_Question', $questions); + } } \ No newline at end of file diff --git a/src/Doer/TestPasser/FillForm.php b/src/Doer/TestPasser/FillForm.php index 7b3a8592..9a80f894 100644 --- a/src/Doer/TestPasser/FillForm.php +++ b/src/Doer/TestPasser/FillForm.php @@ -62,10 +62,16 @@ public function renderContent($content, $template) if (!$step->isLast()) { $submitButtonCaption = __('Next', 'wp-testing'); } + $answerIdName = fOrm::tablize('WpTesting_Model_Answer') . '::answer_id'; + $answerIndex = 0; + if (isset($_POST[$answerIdName]) && is_array($_POST[$answerIdName])) { + $answerIndex = max(array_keys($_POST[$answerIdName])) + 1; + } $params = array( 'wp' => $this->wp, 'hiddens' => $this->generateHiddens($step), - 'answerIdName' => fOrm::tablize('WpTesting_Model_Answer') . '::answer_id', + 'answerIdName' => $answerIdName, + 'answerIndex' => $answerIndex, 'content' => $content, 'test' => $this->test, 'questions' => $step->getQuestions(), diff --git a/src/Model/Answer.php b/src/Model/Answer.php index b6417a33..eb1be932 100644 --- a/src/Model/Answer.php +++ b/src/Model/Answer.php @@ -92,6 +92,14 @@ public function createGlobalAnswer() return $this->createWpTesting_Model_GlobalAnswer(); } + /** + * @return WpTesting_Model_Question + */ + public function createQuestion() + { + return $this->createWpTesting_Model_Question(); + } + /** * Abbreviration of title * diff --git a/src/Template/Test/Passer/fill-form.php b/src/Template/Test/Passer/fill-form.php index 48b6c6c2..95abd5f8 100644 --- a/src/Template/Test/Passer/fill-form.php +++ b/src/Template/Test/Passer/fill-form.php @@ -2,6 +2,7 @@ // Can be overriden in your theme as entry-content-wpt-test-fill-form.php /* @var $answerIdName string */ +/* @var $answerIndex integer */ /* @var $isShowContent boolean */ /* @var $content string */ /* @var $subTitle string */ @@ -26,7 +27,6 @@
doAction('wp_testing_template_fill_form_questions_before') ?> $question): /* @var $question WpTesting_Model_Question */ ?> - doAction('wp_testing_template_fill_form_question_before', $question, $q) ?>