Skip to content

Commit 98932cd

Browse files
committed
Progress on fix #3
1 parent d7e591e commit 98932cd

10 files changed

Lines changed: 50 additions & 51 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Contributors: innershell
33
Tags: triage, form, forms, custom form, form builder, survey, survey builder, questionnaire, questionnaire builder, quiz, quiz builder, exam, exam builder, test, test builder, planner, planning, screening
44
Requires at least: 5.0
5-
Tested up to: 5.1.1
5+
Tested up to: 5.2.2
66
Requires PHP: 7.2
77
Stable tag: trunk
88
License: GPL2 or later
@@ -70,6 +70,9 @@ None yet.
7070
4. The submissions dashboard to capture feedback for machine learning.
7171

7272
# Changelog
73+
## 6.0 (Abort Algorithm)
74+
- Bug fixes.
75+
7376
## 5.1 (Show Answers on Questions Page)
7477
- Show/hide answers in the questions listing page (admin only).
7578
- Hyperlink from the answer to the next question to ask.

controllers/quizzes.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ static function display($quiz_id) {
130130
include(CHAINED_PATH."/views/display-quiz.html.php");
131131
}
132132

133-
// answer a question or complete the quiz
133+
/**************************************************************************
134+
* FUNCTION: Answer the question or complete the quiz.
135+
**************************************************************************/
134136
static function answer_question() {
135137
global $wpdb, $user_ID;
136138
$_quiz = new ChainedQuizQuiz();
@@ -165,32 +167,26 @@ static function answer_question() {
165167
break;
166168
}
167169

168-
169-
170-
/* if ($question->qtype == 'text') {
171-
$answer = @$_POST['answers'];
172-
$answer_text = @$_POST['answer_texts'];
173-
} elseif ($question->qtype == 'checkbox') {
174-
$answer = @$_POST['answers'];
175-
} else {
176-
$answer = @$_POST['answer'];
177-
} */
178-
179170
// Check to make sure answer is provided.
180171
if(empty($answer)) $answer = 0;
181172
$answer = esc_sql($answer);
182173

183174
// Convert multiple answers into an array. Text and checkbox answers will arrive as an array.
184-
/** Might be able to avoid this code if radio buttons are named as an array in the form input. */
185175
if(!is_array($answer)) $answer = array($answer);
186176
if (!is_array($answer_text)) $answer_text = array($answer_text);
187177

188178
// calculate points
189179
$points = $_question->calculate_points($question, $answer);
190-
echo $points."|CHAINEDQUIZ|";
180+
echo $points."|CHAINEDQUIZ|";
191181

192182
// figure out next question
193-
$next_question = $_question->next($question, $answer);
183+
$abort_enabled = $question->points_abort_min == null && $question->points_abort_max == null ? false : true;
184+
error_log("Abort Enabled = " . $abort_enabled . " and Points = " . $points);
185+
if ($abort_enabled && $points >= $question->points_abort_min && $points <= $question->points_abort_max) {
186+
$next_question = null; // Abort criteria met. Let's abort the Algorithm.
187+
} else {
188+
$next_question = $_question->next($question, $answer);
189+
}
194190

195191
// Store the answer
196192
if(!empty($_SESSION['chained_completion_id'])) {

models/basic.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static function install($update = false) {
3939
`qtype` VARCHAR(20) NOT NULL DEFAULT '',
4040
`soap_type` VARCHAR(1) DEFAULT '',
4141
`rank` INT UNSIGNED NOT NULL DEFAULT 0,
42+
`points_abort_min` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
43+
`points_abort_max` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
4244
`autocontinue` TINYINT UNSIGNED NOT NULL DEFAULT 0,
4345
`sort_order` INT UNSIGNED NOT NULL DEFAULT 0,
4446
`accept_comments` TINYINT UNSIGNED NOT NULL DEFAULT 0,
@@ -129,10 +131,13 @@ static function install($update = false) {
129131
}
130132

131133
$current_version = get_option('chained_version');
132-
error_log("Current 'chained_version' = ".$current_version);
133134

134135
/** PERFORM VERSION-SPECIFIC UPGRADES HERE **/
135-
if ($current_version < '2.2') {
136+
if ($current_version == '') {
137+
// If we did not perform this check, all the version checks below are valid (for some reason).
138+
return;
139+
}
140+
elseif ($current_version < '2.2') {
136141
update_option('chained_delete_data', 'no');
137142
} elseif ($current_version < '4.0') {
138143
update_option('chained_debug_mode', 'off');
@@ -141,11 +146,13 @@ static function install($update = false) {
141146
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN objective TEXT AFTER subjective;");
142147
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN assessment TEXT AFTER objective;");
143148
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN plan TEXT AFTER assessment;");
149+
} elseif ($current_version < '6.0') {
150+
$wpdb->query("ALTER TABLE ".CHAINED_QUESTIONS." ADD COLUMN points_abort_min DECIMAL(8,2) NOT NULL DEFAULT 0.00 AFTER rank;");
151+
$wpdb->query("ALTER TABLE ".CHAINED_QUESTIONS." ADD COLUMN points_abort_max DECIMAL(8,2) NOT NULL DEFAULT 0.00 AFTER points_abort_min;");
144152
}
145153

146154
// Set the current plugin version number.
147-
update_option('chained_version', '5.1');
148-
// exit;
155+
update_option('chained_version', '6.0');
149156
}
150157

151158
// main menu
@@ -176,7 +183,7 @@ static function scripts() {
176183
'chained-common',
177184
CHAINED_URL.'js/common.js',
178185
false,
179-
'5.1',
186+
'6.0',
180187
false
181188
);
182189
wp_enqueue_script("chained-common");

models/question.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ function add($vars) {
2323
$sort_order++;
2424

2525
$result = $wpdb->query($wpdb->prepare("INSERT INTO ".CHAINED_QUESTIONS." SET
26-
quiz_id=%d, question=%s, qtype=%s, soap_type=%s, rank=%d, title=%s, autocontinue=%d, sort_order=%d,
26+
quiz_id=%d, question=%s, qtype=%s, soap_type=%s, rank=%d, points_abort_min=%f, points_abort_max=%f, title=%s, autocontinue=%d, sort_order=%d,
2727
accept_comments=%d, accept_comments_label=%s",
28-
intval($vars['quiz_id']), $vars['question'], $vars['qtype'], $vars['soap_type'], intval(@$vars['rank']), $vars['title'],
29-
intval(@$vars['autocontinue']), $sort_order, $accept_comments, $accept_comments_label));
28+
intval($vars['quiz_id']), $vars['question'], $vars['qtype'], $vars['soap_type'], intval(@$vars['rank']), $vars['points_abort_min'], $vars['points_abort_max'],
29+
$vars['title'], intval(@$vars['autocontinue']), $sort_order, $accept_comments, $accept_comments_label));
3030

3131
if($result === false) throw new Exception(__('DB Error', 'chained'));
3232
return $wpdb->insert_id;
@@ -49,8 +49,8 @@ function save($vars, $id) {
4949
$accept_comments_label = sanitize_text_field($vars['accept_comments_label']);
5050

5151
$result = $wpdb->query($wpdb->prepare("UPDATE ".CHAINED_QUESTIONS." SET
52-
question=%s, qtype=%s, soap_type=%s, title=%s, autocontinue=%d, accept_comments=%d, accept_comments_label=%s WHERE id=%d",
53-
$vars['question'], $vars['qtype'], $vars['soap_type'], $vars['title'], intval(@$vars['autocontinue']),
52+
question=%s, qtype=%s, soap_type=%s, title=%s, points_abort_min=%f, points_abort_max=%f, autocontinue=%d, accept_comments=%d, accept_comments_label=%s WHERE id=%d",
53+
$vars['question'], $vars['qtype'], $vars['soap_type'], $vars['title'], $vars['points_abort_min'], $vars['points_abort_max'], intval(@$vars['autocontinue']),
5454
$accept_comments, $accept_comments_label, $id));
5555

5656

@@ -269,13 +269,7 @@ function next($question, $answer) {
269269
else {
270270
if(!empty($answer)) $answer_ids[] = $answer;
271271
}
272-
273-
// Remove any answers that are non numeric.
274-
/* SHOULD NOT BE NEEDED ANYMORE BECAUSE TEXT ANSWERS ARE NUMERIC TOO. */
275-
// $answer_ids = chained_int_array($answer_ids); /* THIS WAS A BUG BEFORE WITH CHECKBOXES */
276-
// if(empty($answer_ids)) $answer_ids = array(0);
277-
278-
272+
279273
/** Build a questions queue to follow-up until all questions have been asked.
280274
* 1. Find follow-up questions and sort by order to be asked.
281275
* 2. Ask the first follow-up question in the list.

models/quiz.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function finalize($quiz, $points) {
160160

161161
if ($email_content_method == 'attach') {
162162
// Write to file.
163-
$file = plugin_dir_path( __DIR__ ) . '/output_files/'.$completion_id.'.html';
163+
$file = plugin_dir_path( __DIR__ ) . 'output_files/'.$completion_id.'.html';
164164
$open = fopen( $file, "a" ); // Open the file for writing (a) only.
165165
$write = fputs( $open, $email_output );
166166
fclose( $open );
@@ -396,8 +396,9 @@ function answers_table($completion_id) {
396396
/**************************************************************************
397397
* FUNCTION: Builds a SOAP note using the user's answers and question config.
398398
**************************************************************************/
399-
function soap_note($completion_id, $result) {
400-
global $wpdb;
399+
function soap_note($completion_id, $_result) {
400+
global $wpdb;
401+
$result = $_result;
401402
$_question = new ChainedQuizQuestion();
402403
$debug_mode = get_option('chained_debug_mode');
403404
$output = '';

models/result.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function calculate($quiz, $points) {
7474
if(floatval($result->points_bottom) <= $points and $points <= floatval($result->points_top)) return $result;
7575
}
7676

77-
error_log("result.php:calculate() - Returning NULL.");
7877
return null; // in case of nothing found
7978

8079
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// These are the changes that need to be done when upgrading the plugin from 5.0 to 5.1.
1+
// These are the changes that need to be done when upgrading the plugin from 5.1 to 6.0.

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Contributors: innershell
33
Tags: triage, form, forms, custom form, form builder, survey, survey builder, questionnaire, questionnaire builder, quiz, quiz builder, exam, exam builder, test, test builder, planner, planning, screening
44
Requires at least: 5.0
5-
Tested up to: 5.1.1
5+
Tested up to: 5.2.2
66
Requires PHP: 7.2
77
Stable tag: trunk
88
License: GPL2 or later
@@ -63,6 +63,9 @@ None yet.
6363
1. The submissions dashboard to capture feedback for machine learning.
6464

6565
== Changelog ==
66+
= 6.0 (Abort Algorithm) =
67+
- Bug fixes.
68+
6669
= 5.1 (Show Answers on Questions Page) =
6770
- Show/hide answers in the questions listing page (admin only).
6871
- Hyperlink from the answer to the next question to ask.

views/question.html.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@
2727
<option value="text" <?php if(!empty($question->id) and $question->qtype == 'text') echo 'selected'?>><?php _e('Text Box (multiple lines of text)','chained')?></option>
2828
<option value="date" <?php if(!empty($question->id) and $question->qtype == 'date') echo 'selected'?>><?php _e('Date (calendar to pick date)','chained')?></option>
2929
</select>
30-
31-
<span id="chainedAutoContinue" style="display:<?php echo (empty($question->id) or $question->qtype == 'radio') ? 'inline' : 'none';?>"><input type="checkbox" name="autocontinue" value="1" <?php if(!empty($question->autocontinue)) echo 'checked'?>> <?php _e('Automatically continue to the next question when a choice is selected', 'chained')?></span> </p>
32-
30+
31+
<h3><?php _e('Question Behavior', 'chained')?></h3>
32+
<p><?php _e('Abort and Finish the Algorithm if the points sum up to this Question is in the following range.' , 'chained')?></p>
33+
<p><?php _e('Abort Min. Points:', 'chained')?> <input type="text" size="4" name="points_abort_min" value="<?php echo $question->points_abort_min?>">&nbsp;&nbsp;&nbsp;
34+
<?php _e('Abort Max. Points:', 'chained')?> <input type="text" size="4" name="points_abort_max" value="<?php echo $question->points_abort_max?>"></p>
35+
<span id="chainedAutoContinue" style="display:<?php echo (empty($question->id) or $question->qtype == 'radio') ? 'inline' : 'none';?>"><input type="checkbox" name="autocontinue" value="1" <?php if(!empty($question->autocontinue)) echo 'checked'?>> <?php _e('Automatically continue to the next Question when a choice is selected.', 'chained')?></span> </p>
3336
<p><input type="checkbox" name="accept_comments" value="1" <?php if(!empty($question->accept_comments)) echo 'checked'?>> <?php _e('Accept comments along with the answer.', 'chained');?> &nbsp;
3437
<?php _e('Label before the comments field:', 'chained');?> <input type="text" name="accept_comments_label" size="30" value="<?php echo empty($question->accept_comments_label) ? __('Your comments:', 'chained') : stripslashes(@$question->accept_comments_label);?>"></p>
3538

36-
<h3><?php _e('Answers and Settings', 'chained')?></h3>
39+
<h3><?php _e('Answers', 'chained')?></h3>
3740

3841

3942
<div id="answerRows">

views/sidebar.html.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<div id="chained-related" class="chained-sidebox">
22
<h3><?php _e('ABOUT', 'chained')?></h3>
3-
<p><?php _e('Version: 1.0 introduces the Triage Algorithm.', 'chained');?></p>
4-
<p><?php _e('Version: 2.0 introduces a Submissions Dashboard.', 'chained');?></p>
5-
<p><?php _e('Version: 2.1 fixed bugs.', 'chained');?></p>
6-
<p><?php _e('Version: 2.2 fixed bugs.', 'chained');?></p>
7-
<p><?php _e('Version: 3.0 introduces Billing Codes.', 'chained');?></p>
8-
<p><?php _e('Version: 4.0 introduces Algorithm Points.', 'chained');?></p>
9-
<p><?php _e('Version: 5.0 introduces Checkbox follow-up.', 'chained');?></p>
10-
<p><?php _e('Version: 5.1 improves Question management.', 'chained');?></p>
3+
<p><?php _e('Nothing related.', 'chained');?></p>
114
</div>
125

136

0 commit comments

Comments
 (0)