Skip to content

Commit

Permalink
Merge branch 'release/0.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
garex committed Mar 29, 2015
2 parents dac0fca + ea02a72 commit b0728d3
Show file tree
Hide file tree
Showing 40 changed files with 952 additions and 63 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
## Changelog ##


### 0.10 ###

Save respondent in results and add addons base

* Save respondent from logged in user
* Add external addons base
* Test minimum score error


### 0.9.5 ###

Update locales, minor fixes and cleanup download file
Expand Down
4 changes: 2 additions & 2 deletions 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.5
**Stable tag:** 0.10
**License:** GPLv3
**License URI:** http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -29,7 +29,7 @@ Tests are treated for WordPress like posts — they appear on home page and insi

To minimize author's time we have **Quick Fill** for questions and scores. You can **quick fill questions from text** and they will fill appropriate fields. Same way you can **Quick Fill Scores** in many questions some answer+scale combination.

Respondent will get **results** on it's own individual passing page, which will allow share it. **Passings** are saved in DB with respondent's ip and device unique identifier. They are shown at "Respondents' results" table under "Tests" menu. It allow to see if someone will have many passings from same computer/smartphone/another device, which scales/results respondent have for concrete passing and ability to open it from there.
Respondent will get **results** on it's own individual passing page, which will allow share it. **Passings** are saved in DB with respondent's ip and device unique identifier. They are shown at "Respondents' results" table under "Tests" menu. It allow to see if someone will have many passings from same computer/smartphone/another device, which scales/results respondent have for concrete passing and ability to open it from there. If respondent was a logged in user — then you will see it in "Username" column with a link to profile.

**Test** page can be customized: reset answers on "Back" button, use your own caption for "Get Test Result" button. allow multiple answers per question and show percentage of answered questions.
**Results** page also can be customized: when you need to show/hide scales or test description on it; when you want to show scales chart or sort scales by scores sum.
Expand Down
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-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@
"source": {
"url": "https://github.com/garex/flourish-classes",
"type": "git",
"reference": "3ef6840d6259f9cf990f70d070de2ae5bed4a652"
"reference": "4b2fa7e450e6d19ed19eb07c3983f0035debbe1e"
},
"dist": {
"url": "https://github.com/garex/flourish-classes/archive/3ef6840d6259f9cf990f70d070de2ae5bed4a652.zip",
"url": "https://github.com/garex/flourish-classes/archive/4b2fa7e450e6d19ed19eb07c3983f0035debbe1e.zip",
"type": "zip"
}
}
Expand Down
6 changes: 6 additions & 0 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ ul.categorychecklist.ui-sortable li.wpt-sortable.wpt-sortable-container {
ul.categorychecklist.ui-sortable li.sortable-placeholder {
background: none;
}

.wp-list-table.passings .column-user img {
float: left;
margin-top: 1px;
margin-right: 10px;
}
60 changes: 60 additions & 0 deletions db/migrations/wp_testing/20150324041508_AddSectionsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_BaseMigration.php';

class AddSectionsTable extends BaseMigration
{

public function up()
{
$this->drop_table(WPT_DB_PREFIX . 'sections');
$table = $this->create_table(WPT_DB_PREFIX . 'sections', array(
'id' => false,
'options' => 'ENGINE=' . $this->get_wp_table_engine(),
));
$table->column('section_id', 'biginteger', array(
'unsigned' => true,
'null' => false,
'primary_key' => true,
'auto_increment' => true,
));
$table->column('test_id', 'biginteger', array(
'unsigned' => true,
'null' => false,
));
$table->column('question_id', 'biginteger', array(
'unsigned' => true,
'null' => false,
));
$table->column('section_title', 'text', array(
'null' => false,
));
$table->finish();

$global_prefix = WP_DB_PREFIX;
$plugin_prefix = WPT_DB_PREFIX;
$this->execute("
ALTER TABLE {$plugin_prefix}sections
ADD CONSTRAINT fk_section_test
FOREIGN KEY (test_id)
REFERENCES {$global_prefix}posts (ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
ADD INDEX fk_section_test (test_id),
ADD CONSTRAINT fk_section_question
FOREIGN KEY (question_id)
REFERENCES {$plugin_prefix}questions (question_id)
ON DELETE CASCADE
ON UPDATE CASCADE,
ADD INDEX fk_section_question (question_id),
ADD UNIQUE INDEX uq_section_test_question (test_id, question_id)
");
}

public function down()
{
$this->drop_table(WPT_DB_PREFIX . 'sections');
}
}
5 changes: 5 additions & 0 deletions db/sql/test-test-scales.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DELETE FROM wp_posts WHERE 'test 1' = post_title;

SELECT * FROM wp_posts ORDER BY ID DESC;

SELECT * FROM wp_term_relationships;
Binary file modified db/sql/wp-testing.mwb
Binary file not shown.
11 changes: 11 additions & 0 deletions src/Addon/IAddon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

interface WpTesting_Addon_IAddon extends WpTesting_Component_IRootable
{

/**
* @return WpTesting_Addon_IAddon
*/
public function setWp(WpTesting_Addon_IWordPressFacade $wp);

}
12 changes: 12 additions & 0 deletions src/Addon/IFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

interface WpTesting_Addon_IFacade
{

/**
* @param WpTesting_Addon_IAddon $addon
* @return WpTesting_Addon_IFacade
*/
public function registerAddon($addon);

}
65 changes: 65 additions & 0 deletions src/Addon/IWordPressFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

interface WpTesting_Addon_IWordPressFacade
{

/**
* Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
* @var integer
*/
const PRIORITY_DEFAULT = 10;

/**
* Hooks a function on to a specific action.
*
* @since 1.2.0
* @link http://codex.wordpress.org/Function_Reference/add_action
*
* @param string $tag The name of the action to which the $function is hooked.
* @param callback $function The name of the function you wish to be called.
* @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
* @param int $functionArgsCount optional. The number of arguments the function accept (default 1).
* @return WpTesting_Addon_IWordPressFacade
*/
public function addAction($tag, $function, $priority = self::PRIORITY_DEFAULT, $functionArgsCount = 1);

/**
* Add a meta box to an edit form.
*
* @since 2.5.0
*
* @param string $id String for use in the 'id' attribute of tags.
* @param string $title Title of the meta box.
* @param callable $function Function that fills the box with the desired content.
* The function should echo its output.
* @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post
* type, 'link', or 'comment'). Default is the current screen.
* @param string $context Optional. The context within the screen where the boxes
* should display. Available contexts vary from screen to
* screen. Post edit screen contexts include 'normal', 'side',
* and 'advanced'. Comments screen contexts include 'normal'
* and 'side'. Menus meta boxes (accordion sections) all use
* the 'side' context. Global default is 'advanced'.
* @param string $priority Optional. The priority within the context where the boxes
* should show ('high', 'low'). Default 'default'.
* @param array $functionArgs Optional. Data that should be set as the $args property
* of the box array (which is the second parameter passed
* to your callback). Default null.
* @return WpTesting_Addon_IWordPressFacade
*/
public function addMetaBox($id, $title, $function, $screen = null, $context = 'advanced', $priority = 'default', $functionArgs = null);

/**
* Hooks a function or method to a specific filter action.
*
* @since 0.71
*
* @param string $tag The name of the action to which the $function is hooked.
* @param callback $function The name of the function you wish to be called.
* @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
* @param int $functionArgsCount optional. The number of arguments the function accept (default 1).
* @return WpTesting_WordPressFacade
*/
public function addFilter($tag, $function, $priority = self::PRIORITY_DEFAULT, $functionArgsCount = 1);

}
16 changes: 16 additions & 0 deletions src/Component/IRootable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

interface WpTesting_Component_IRootable
{

/**
* @return string Class name placed in root
*/
public function getClass();

/**
* @return string Absolute path without ending slash
*/
public function getRoot();

}
49 changes: 49 additions & 0 deletions src/Component/Loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

class WpTesting_Component_Loader
{

/**
* Prefix => Dirname
* @var array
*/
private $prefixToPath = array();

private $requiredPrefix = '';

public function __construct($requiredPrefix)
{
$this->requiredPrefix = $requiredPrefix;
spl_autoload_register(array($this, 'autoload'));
}

public function autoload($class)
{
if (empty($this->prefixToPath) || false === strpos($class, $this->requiredPrefix)) {
return;
}
$prefix = $this->getPrefix($class);
if (!isset($this->prefixToPath[$prefix])) {
return;
}
$path = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
$path = str_replace($prefix, $this->prefixToPath[$prefix], $path);
require_once $path;
}

/**
* @param WpTesting_Component_IRootable $rootable
* @return WpTesting_Component_Loader
*/
public function addPrefixPath($rootable)
{
$this->prefixToPath[$this->getPrefix($rootable->getClass())] = $rootable->getRoot();
return $this;
}

private function getPrefix($class)
{
return substr($class, 0, strpos($class, '_'));
}

}
13 changes: 10 additions & 3 deletions src/Doer/AbstractDoer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ abstract class WpTesting_Doer_AbstractDoer

public function __construct(WpTesting_WordPressFacade $wp)
{
$this->wp = $wp;
$this->registerScripts();
$this->wp = $wp;
$this->templateRoot = dirname(dirname($this->getClassFile())) . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR;
}

protected function getClassFile()
{
return __FILE__;
}

public function renderJsData()
Expand Down Expand Up @@ -69,6 +74,7 @@ protected function addJsDataValues($values) {

/**
* Register common used scripts for future dependencies
* @return self
*/
protected function registerScripts()
{
Expand All @@ -84,12 +90,13 @@ protected function registerScripts()
->registerPluginScript('raphael-line-diagram', 'js/vendor/dmitrybaranovskiy/g.line.js', array('raphael-diagrams'), '0.51')
->registerPluginScript('raphael-scale', 'js/vendor/zevanrosser/scale.raphael.js', array('raphael'), '0.8')
;
return $this;
}

protected function output($__template, $__params = array())
{
if (substr($__template, -4) != '.php') {
$__template = dirname(dirname(__FILE__)) . '/Template/' . $__template . '.php';
$__template = $this->templateRoot . $__template . '.php';
}
extract($__params, EXTR_SKIP);
include $__template;
Expand Down
11 changes: 4 additions & 7 deletions src/Doer/TestEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public function customizeUi($screen)
if (!$this->isTestScreen($screen)) {
return $this;
}
$this->wp
$this->wp->doAction('wp_testing_editor_customize_ui_before');
$this->registerScripts()->wp
->enqueuePluginStyle('wpt_admin', 'css/admin.css')
->enqueuePluginScript('wpt_test_edit_fix_styles', 'js/test-edit-fix-styles.js', array('jquery'), false, true)
->enqueuePluginScript('field_selection', 'js/vendor/kof/field-selection.js', array(), false, true)
Expand Down Expand Up @@ -47,6 +48,7 @@ public function customizeUi($screen)
} else {
$this->wp->addFilter('wp_get_object_terms', array($this, 'filterForceSortObjectTerms'), 10, 4);
}
$this->wp->doAction('wp_testing_editor_customize_ui_after');
return $this;
}

Expand Down Expand Up @@ -298,13 +300,8 @@ public function saveTest($id, $item)
$this->wp->updatePostMeta($test->getId(), $metaOptionKey, $metaOptionValue);
}

$_POST = $test->adaptForPopulate($_POST);
$test->populateQuestions(true);
$test->populateFormulas();

try {
$test->store(true);
$test->syncQuestionsAnswers();
$test->storeAll();
} catch (fValidationException $e) {
$title = __('Test data not saved', 'wp-testing');
$this->wp->dieMessage(
Expand Down
7 changes: 6 additions & 1 deletion src/Doer/TestPasser.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ public function addContentFilter()
return $this;
}

$this->wp->addFilter('body_class', array($this, 'addPassingActionCssClass'));
$this->registerScripts()->wp->addFilter('body_class', array($this, 'addPassingActionCssClass'));
if (self::ACTION_PROCESS_FORM == $action) {
$passing = new WpTesting_Model_Passing();
$passing->setWp($this->wp)->populate($this->test)
->setIp($this->getClientIp())
->setDeviceUuid($this->extractUuid('device_uuid', $_COOKIE))
->setUserAgent($this->getUserAgent())
->setRespondentId($this->wp->getCurrentUserId())
;

try {
Expand Down Expand Up @@ -193,6 +194,9 @@ public function renderTestContent($content)
$template = $this->wp->locateTemplate('entry-content-wpt-test-' . $action . '.php');
$template = ($template) ? $template : 'Test/Passer/' . $action;

$this->wp->doAction('wp_testing_passer_render_content', $this->test);
$this->wp->doAction('wp_testing_passer_render_content_' . $action, $this->test);

if (self::ACTION_FILL_FORM == $action) {
$params = array(
'answerIdName' => fOrm::tablize('WpTesting_Model_Answer') . '::answer_id',
Expand All @@ -205,6 +209,7 @@ public function renderTestContent($content)
$this->wp->getCurrentPostMeta('wpt_test_page_submit_button_caption'),
__('Get Test Results', 'wp-testing'),
))),
'wp' => $this->wp,
);
$this->addJsDataValues(array(
'isResetAnswersOnBack' => $this->test->isResetAnswersOnBack(),
Expand Down
Loading

0 comments on commit b0728d3

Please sign in to comment.