Skip to content

Commit

Permalink
Merge branch 'hotfix/0.9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
garex committed Mar 1, 2015
2 parents a94a790 + 44987e2 commit 4b2b804
Show file tree
Hide file tree
Showing 37 changed files with 363 additions and 59 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,35 @@ script:
- vendor/bin/phpunit-php52
- cd $TRAVIS_BUILD_DIR/tests/mocha
- mocha-casperjs --grep=Plugin_activation --timeout=360000
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Answers1
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Answers2
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Multiple
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Page
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Questions
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Quick
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Results
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Scale_Aggregates
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Scores
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Shortcode
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Taxonomies
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Test
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Passings
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Respondents
- $TRAVIS_BUILD_DIR/tests/integration-environment/restart.sh
- mocha-casperjs --grep=Plugin_deactivation

after_failure:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
## Changelog ##


### 0.9.2 ###

Fix scale`s max calc when in question we have few answers with scores


### 0.9.1 ###

Allow respondent to select multiple answers per question on test page
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.9.1
**Stable tag:** 0.9.2
**License:** GPLv3
**License URI:** http://www.gnu.org/licenses/gpl-3.0.html

Expand Down
Binary file modified assets-wp-repo/screenshot-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets-wp-repo/screenshot-18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions db/sql/scale-max-right.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
SELECT
scale_id,
MIN(minimum_in_row) AS minimum_in_column,
SUM(maximum_in_row) AS maximum_in_column,
SUM(sum_in_row) AS sum_in_column
FROM (
SELECT
scale_id,
MIN(IF(score_value > 0, 0, score_value)) AS minimum_in_row,
MAX(IF(score_value > 0, score_value, 0)) AS maximum_in_row,
SUM(score_value) AS sum_in_row
FROM wp_t_scores AS s
JOIN wp_t_answers AS a ON s.answer_id = a.answer_id
WHERE TRUE
AND question_id IN (59,60,61)
AND scale_id IN (6)
GROUP BY scale_id, question_id, question_id
HAVING minimum_in_row < maximum_in_row
) AS groupped
GROUP BY scale_id
;

SELECT
scale_id,
question_id,
score_value
FROM wp_t_scores AS s
JOIN wp_t_answers AS a ON s.answer_id = a.answer_id
WHERE TRUE
AND question_id IN (59,60,61)
AND scale_id IN (6)
;

SELECT
scale_id,
SUM(IF(score_value > 0, 0, score_value)) AS total_negative,
SUM(IF(score_value > 0, score_value, 0)) AS total_positive
FROM wp_t_scores AS s
JOIN wp_t_answers AS a ON s.answer_id = a.answer_id
WHERE TRUE
AND question_id IN (59,60,61)
AND scale_id IN (6)
GROUP BY scale_id
HAVING total_negative < total_positive;
11 changes: 11 additions & 0 deletions src/Doer/AbstractDoer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ public function renderJsData()
$this->jsData = array();
}

/**
* Creates test with injected WP facade
* @param mixed $key
* @return WpTesting_Model_Test
*/
protected function createTest($key = null)
{
$test = new WpTesting_Model_Test($key);
return $test->setWp($this->wp);
}

/**
* Adds data to Wpt global object
* @param string $key
Expand Down
10 changes: 5 additions & 5 deletions src/Doer/TestEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function renderResultPageOptions($item)
*/
public function renderEditQuestions($item)
{
$test = new WpTesting_Model_Test($item);
$test = $this->createTest($item);
$this->output('Test/Editor/edit-questions', array(
'scales' => $test->buildScalesWithRange(),
'answers' => $test->buildGlobalAnswers(),
Expand All @@ -245,7 +245,7 @@ public function renderEditQuestions($item)
*/
public function renderAddQuestions($item)
{
$test = new WpTesting_Model_Test($item);
$test = $this->createTest($item);
$this->output('Test/Editor/add-questions', array(
'addNewCount' => WpTesting_Model_Question::ADD_NEW_COUNT,
'startFrom' => $test->buildQuestions()->count(),
Expand All @@ -257,7 +257,7 @@ public function renderAddQuestions($item)
*/
public function renderEditFormulas($item)
{
$test = new WpTesting_Model_Test($item);
$test = $this->createTest($item);
$this->output('Test/Editor/edit-formulas', array(
'results' => $test->buildResults(),
'variables' => $test->buildFormulaVariables(),
Expand All @@ -270,7 +270,7 @@ public function renderEditFormulas($item)
*/
public function saveTest($id, $item)
{
$test = new WpTesting_Model_Test($item);
$test = $this->createTest($item);
if (!$test->getId()) {
return;
}
Expand Down Expand Up @@ -342,7 +342,7 @@ private function isTestScreen($screen)
if (!$id) {
return false;
}
$test = new WpTesting_Model_Test($id);
$test = $this->createTest($id);
$isTest = ($test->getId()) ? true : false;
$test->reset();
return $isTest;
Expand Down
27 changes: 13 additions & 14 deletions src/Doer/TestPasser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function addContentFilter()
return $this;
}

$this->test = new WpTesting_Model_Test($object);
$this->test = $this->createTest($object);
$action = $this->getTestPassingAction();
$isDie = (self::ACTION_FILL_FORM != $action && !$this->test->isFinal());
if ($isDie) {
Expand All @@ -69,15 +69,15 @@ public function addContentFilter()
$this->wp->addFilter('body_class', array($this, 'addPassingActionCssClass'));
if (self::ACTION_PROCESS_FORM == $action) {
$passing = new WpTesting_Model_Passing();
$passing->populate($this->test)
$passing->setWp($this->wp)->populate($this->test)
->setIp($this->getClientIp())
->setDeviceUuid($this->extractUuid('device_uuid', $_COOKIE))
->setUserAgent($this->getUserAgent())
;

try {
$passing->store(true);
$link = $passing->getUrl($this->wp, $this->getCurrentUrl());
$link = $passing->getUrl($this->getCurrentUrl());
$this->wp->redirect($link, 302);
$this->wp->dieMessage(
$this->render('Test/Passer/redirect-message', array(
Expand Down Expand Up @@ -111,6 +111,7 @@ public function addContentFilter()
$this->wp->getQuery()->get('wpt_passing_slug'),
$this->wp->getSalt()
);
$this->passing->setWp($this->wp);
if (!$this->passing->getId()) {
throw new fNotFoundException();
}
Expand All @@ -130,10 +131,9 @@ public function addContentFilter()
$this->wp
->enqueuePluginScript('wpt_render_text_with_more', 'js/render-text-with-more.js', array('detect-javascript', 'jquery'), false, true)
;
if (1 == $this->wp->getCurrentPostMeta('wpt_result_page_show_scales_diagram')) {
$isSortByScore = (1 == $this->wp->getCurrentPostMeta('wpt_result_page_sort_scales_by_score'));
if ($this->test->isShowScalesDiagram()) {
$sorryBrowser = sprintf(__('Sorry but your browser %s is not compatible to display the chart', 'wp-testing'), $this->getUserAgent());
$scales = $this->toJson($this->passing->buildScalesWithRangeOnce($isSortByScore));
$scales = $this->toJson($this->passing->buildScalesWithRangeOnce());
$this
->addJsData('warningIncompatibleBrowser', $sorryBrowser)
->addJsData('scales', $scales)
Expand Down Expand Up @@ -200,30 +200,29 @@ public function renderTestContent($content)
'test' => $this->test,
'questions' => $this->test->buildQuestions(),
'isFinal' => $this->test->isFinal(),
'isMultipleAnswers' => (1 == $this->wp->getCurrentPostMeta('wpt_test_page_multiple_answers')),
'isMultipleAnswers' => $this->test->isMultipleAnswers(),
'submitButtonCaption' => current(array_filter(array(
$this->wp->getCurrentPostMeta('wpt_test_page_submit_button_caption'),
__('Get Test Results', 'wp-testing'),
))),
);
$this->addJsDataValues(array(
'isResetAnswersOnBack' => (1 == $this->wp->getCurrentPostMeta('wpt_test_page_reset_answers_on_back')),
'isShowProgressMeter' => (1 == $this->wp->getCurrentPostMeta('wpt_test_page_show_progress_meter')),
'isResetAnswersOnBack' => $this->test->isResetAnswersOnBack(),
'isShowProgressMeter' => $this->test->isShowProgressMeter(),
'titleSeparator' => $this->titleSeparator,
'percentsAnswered' => __('{percentage}% answered', 'wp-testing'),
));
} elseif (self::ACTION_GET_RESULTS == $action) {
$isSortByScore = (1 == $this->wp->getCurrentPostMeta('wpt_result_page_sort_scales_by_score'));
$params = array(
'content' => $content,
'renderer' => $this,
'test' => $this->test,
'passing' => $this->passing,
'scales' => $this->passing->buildScalesWithRangeOnce($isSortByScore),
'scales' => $this->passing->buildScalesWithRangeOnce(),
'results' => $this->passing->buildResults(),
'isShowScalesDiagram' => (1 == $this->wp->getCurrentPostMeta('wpt_result_page_show_scales_diagram')),
'isShowScales' => (1 == $this->wp->getCurrentPostMeta('wpt_result_page_show_scales')),
'isShowDescription' => (1 == $this->wp->getCurrentPostMeta('wpt_result_page_show_test_description')),
'isShowScalesDiagram' => $this->test->isShowScalesDiagram(),
'isShowScales' => $this->test->isShowScales(),
'isShowDescription' => $this->test->isShowTestDescription(),
);
}

Expand Down
27 changes: 27 additions & 0 deletions src/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,32 @@ abstract class WpTesting_Model_AbstractModel extends fActiveRecord
*/
protected $columnAliases = array();

/**
* @var WpTesting_WordPressFacade
*/
private $wp = null;

public function populate($recursive = false)
{
parent::populate($recursive);

return $this->stripValuesSlashes();
}

/**
* @param WpTesting_WordPressFacade $wp
* @throws InvalidArgumentException
* @return self
*/
public function setWp($wp)
{
if (!($wp instanceof WpTesting_WordPressFacade)) {
throw new InvalidArgumentException('Wordpress facade is not those who you think it is.');
}
$this->wp = $wp;
return $this;
}

/**
* Generates phpdoc for class
* @return string
Expand Down Expand Up @@ -118,6 +137,14 @@ protected function stringLength($string)
return strlen($string);
}

protected function getWp()
{
if (is_null($this->wp)) {
$this->setWp(new WpTesting_WordPressFacade('../../wp-testing.php'));
}
return $this->wp;
}

/**
* Strip slashes from values.
* It's an antipod of wp_magic_quotes.
Expand Down
28 changes: 28 additions & 0 deletions src/Model/AbstractTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,32 @@ public function getCssClass($index = null)
return $css;
}

/**
* @return number
*/
public function getSum()
{
return null;
}

/**
* @return number
*/
public function getMaximum()
{
return null;
}

public function getAggregatesTitle()
{
$parts = array();
if (!is_null($this->getSum())) {
$parts[] = sprintf('∑ %d', $this->getSum());
}
if ($this->getSum() != $this->getMaximum()) {
$parts[] = sprintf('max %d', $this->getMaximum());
}
return implode(', ', $parts);
}

}
2 changes: 1 addition & 1 deletion src/Model/Formula.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function createResult()
public function validateSource(WpTesting_Model_Formula $me, &$values, &$oldValues, &$relatedRecords, &$cache, &$validationMessages)
{
/* @var $test WpTesting_Model_Test */
$test = $me->createWpTesting_Model_Test();
$test = $me->createWpTesting_Model_Test()->setWp($this->getWp());
$varNames = array();
foreach ($test->buildFormulaVariables() as $var) {
$varNames[] = $var->getSource();
Expand Down
2 changes: 1 addition & 1 deletion src/Model/FormulaVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getTitle()
{
$model = $this->model;
if ($model instanceof WpTesting_Model_AbstractTerm) {
return sprintf(__('%1$s, ∑ %2$d', 'wp-testing'), $model->getTitle(), $model->getSum());
return $model->getTitle() . ', ' . $model->getAggregatesTitle();
}
return null;
}
Expand Down
Loading

0 comments on commit 4b2b804

Please sign in to comment.