Skip to content

Commit

Permalink
Merge branch 'hotfix/0.11.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
garex committed Apr 17, 2015
2 parents b9346d0 + 95b51db commit 76df1a7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
## Changelog ##


### 0.11.1 ###
Improve steps generating (for sections addon)

Upgrade notice:

* You should upgrade to this version only if you have sections addon


### 0.11 ###
Add one-per-page questions and fix annoing database collation issue

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Tags:** psychological, testing, test, quiz
**Requires at least:** 3.2
**Tested up to:** 4.1.1
**Stable tag:** 0.11
**Stable tag:** 0.11.1
**License:** GPLv3
**License URI:** http://www.gnu.org/licenses/gpl-3.0.html

Expand Down
53 changes: 42 additions & 11 deletions src/Component/StepStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ abstract class WpTesting_Component_StepStrategy

public function __construct(WpTesting_Model_Test $test = null, fRecordSet $answeredQuestions = null)
{
$this->test = $test;
is_null($test) || $this->setTest($test);
$this->answeredQuestions = $answeredQuestions;
$emptyQuestions = fRecordSet::buildFromArray('WpTesting_Model_Question', array());
}

/**
Expand All @@ -53,30 +52,31 @@ public function __construct(WpTesting_Model_Test $test = null, fRecordSet $answe
*/
public function fillFrom(WpTesting_Component_StepStrategy $another)
{
$this->test = $another->test;
$this->setTest($another->test);
$this->answeredQuestions = $another->answeredQuestions;

if (is_null($this->test)) {
throw new InvalidArgumentException('Empty test provided!');
}
if (is_null($this->answeredQuestions)) {
throw new InvalidArgumentException('Empty answered questions provided!');
}

return $this;
}

/**
* @return WpTesting_Model_Test
*/
public function getTest()
{
return $this->test;
}

/**
* @return WpTesting_Model_Step
*/
public function getCurrentStep()
{
if (!is_null($this->currentStep)) {
return $this->currentStep;
}
$this->fillSteps()->setupTotalsAndNumbers();
if (is_null($this->currentStep)) {
$this->currentStep = new WpTesting_Model_Step('', $emptyQuestions, 1, true, true);
$this->getSteps();
}
return $this->currentStep;
}
Expand Down Expand Up @@ -106,6 +106,17 @@ public function getAnsweredQuestionsCount()
return $this->answeredQuestions->count();
}

/**
* @param WpTesting_Model_Test $test
* @throws InvalidArgumentException
* @return WpTesting_Component_StepStrategy
*/
protected function setTest(WpTesting_Model_Test $test)
{
$this->test = $test;
return $this;
}

/**
* @param WpTesting_Model_Step $step
* @param string $isCurrent
Expand All @@ -131,6 +142,26 @@ protected function enableStepsCounter()
*/
abstract protected function fillSteps();

/**
* @return WpTesting_Model_Step[]
*/
protected function getSteps()
{
if (is_null($this->currentStep)) {
$this->fillSteps();
if (!count($this->steps)) {
$emptyQuestions = fRecordSet::buildFromArray('WpTesting_Model_Question', array());
$this->addStep(new WpTesting_Model_Step('', $emptyQuestions));
}
if (is_null($this->currentStep)) {
$this->currentStep = reset($this->steps);
}
$this->setupTotalsAndNumbers();
}

return $this->steps;
}

/**
* @return self
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Component/StepStrategy/AllInOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class WpTesting_Component_StepStrategy_AllInOne extends WpTesting_Component_StepStrategy
{

public function fillSteps()
protected function fillSteps()
{
return $this->addStep(
new WpTesting_Model_Step('', $this->test->buildQuestions())
Expand Down
2 changes: 1 addition & 1 deletion src/Component/StepStrategy/OneToOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class WpTesting_Component_StepStrategy_OneToOne extends WpTesting_Component_StepStrategy
{

public function fillSteps()
protected function fillSteps()
{
$questions = $this->test->buildQuestions();
$total = $questions->count();
Expand Down
5 changes: 4 additions & 1 deletion src/Model/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct($key = null)
*/
public function buildQuestions()
{
return $this->buildWpTesting_Model_Questions();
return $this->me()->buildWpTesting_Model_Questions();
}

/**
Expand Down Expand Up @@ -644,6 +644,9 @@ public function toWpPost()
public function setParent(WpTesting_Model_Test $parent)
{
$this->parent = $parent;
if (is_null($this->wp)) {
$this->wp = $parent->wp;
}
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion wp-testing.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Wp-testing
* Plugin URI: http://wordpress.org/extend/plugins/wp-testing/
* Description: Helps to create psychological tests.
* Version: 0.11
* Version: 0.11.1
* Author: Alexander Ustimenko
* Author URI: http://ustimen.co
* License: GPL3
Expand Down

0 comments on commit 76df1a7

Please sign in to comment.