Skip to content

Commit 16d5302

Browse files
committed
Merge branch 'build4-issue#3' Fixed #3
2 parents d7e591e + fd5dafc commit 16d5302

10 files changed

Lines changed: 79 additions & 63 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: 12 additions & 17 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);
190180
echo $points."|CHAINEDQUIZ|";
181+
$total_points = $points + floatval($_POST['points']); // Points for the whole algorithm.
191182

192183
// figure out next question
193-
$next_question = $_question->next($question, $answer);
184+
if ($question->abort_enabled && $total_points >= $question->points_abort_min && $total_points <= $question->points_abort_max) {
185+
// Abort criteria met. Let's abort the Algorithm and finish it.
186+
$next_question = null;
187+
} else {
188+
$next_question = $_question->next($question, $answer);
189+
}
194190

195191
// Store the answer
196192
if(!empty($_SESSION['chained_completion_id'])) {
@@ -229,9 +225,8 @@ static function answer_question() {
229225
include(CHAINED_PATH."/views/display-quiz.html.php");
230226
}
231227
else {
232-
// add to points
233-
$points += floatval($_POST['points']);
234-
echo $_quiz->finalize($quiz, $points); // if none, submit the quiz
228+
// if none, submit the quiz
229+
echo $_quiz->finalize($quiz, $total_points);
235230
}
236231
}
237232
}

models/basic.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ 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+
`abort_enabled` TINYINT UNSIGNED NOT NULL DEFAULT 0,
43+
`points_abort_min` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
44+
`points_abort_max` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
4245
`autocontinue` TINYINT UNSIGNED NOT NULL DEFAULT 0,
4346
`sort_order` INT UNSIGNED NOT NULL DEFAULT 0,
4447
`accept_comments` TINYINT UNSIGNED NOT NULL DEFAULT 0,
@@ -129,10 +132,13 @@ static function install($update = false) {
129132
}
130133

131134
$current_version = get_option('chained_version');
132-
error_log("Current 'chained_version' = ".$current_version);
133135

134136
/** PERFORM VERSION-SPECIFIC UPGRADES HERE **/
135-
if ($current_version < '2.2') {
137+
if ($current_version == '') {
138+
// If we did not perform this check, all the version checks below are valid (for some reason).
139+
return;
140+
}
141+
elseif ($current_version < '2.2') {
136142
update_option('chained_delete_data', 'no');
137143
} elseif ($current_version < '4.0') {
138144
update_option('chained_debug_mode', 'off');
@@ -141,11 +147,14 @@ static function install($update = false) {
141147
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN objective TEXT AFTER subjective;");
142148
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN assessment TEXT AFTER objective;");
143149
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN plan TEXT AFTER assessment;");
150+
} elseif ($current_version < '6.0') {
151+
$wpdb->query("ALTER TABLE ".CHAINED_QUESTIONS." ADD COLUMN abort_enabled TINYINT NOT NULL DEFAULT 0 AFTER rank;");
152+
$wpdb->query("ALTER TABLE ".CHAINED_QUESTIONS." ADD COLUMN points_abort_min DECIMAL(8,2) NOT NULL DEFAULT '0.00' AFTER abort_enabled;");
153+
$wpdb->query("ALTER TABLE ".CHAINED_QUESTIONS." ADD COLUMN points_abort_max DECIMAL(8,2) NOT NULL DEFAULT '0.00' AFTER points_abort_min;");
144154
}
145155

146156
// Set the current plugin version number.
147-
update_option('chained_version', '5.1');
148-
// exit;
157+
update_option('chained_version', '6.0');
149158
}
150159

151160
// main menu
@@ -176,7 +185,7 @@ static function scripts() {
176185
'chained-common',
177186
CHAINED_URL.'js/common.js',
178187
false,
179-
'5.1',
188+
'6.0',
180189
false
181190
);
182191
wp_enqueue_script("chained-common");

models/question.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ 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,
27-
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));
26+
quiz_id=%d, question=%s, qtype=%s, soap_type=%s, rank=%d,
27+
abort_enabled=%d, points_abort_min=%f, points_abort_max=%f,
28+
title=%s, autocontinue=%d, sort_order=%d, accept_comments=%d, accept_comments_label=%s",
29+
intval($vars['quiz_id']), $vars['question'], $vars['qtype'], $vars['soap_type'], intval(@$vars['rank']),
30+
$vars['abort_enabled'], $vars['points_abort_min'], $vars['points_abort_max'],
31+
$vars['title'], intval(@$vars['autocontinue']), $sort_order, $accept_comments, $accept_comments_label));
3032

3133
if($result === false) throw new Exception(__('DB Error', 'chained'));
3234
return $wpdb->insert_id;
@@ -49,9 +51,12 @@ function save($vars, $id) {
4951
$accept_comments_label = sanitize_text_field($vars['accept_comments_label']);
5052

5153
$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']),
54-
$accept_comments, $accept_comments_label, $id));
54+
question=%s, qtype=%s, soap_type=%s, title=%s,
55+
abort_enabled=%d, points_abort_min=%f, points_abort_max=%f,
56+
autocontinue=%d, accept_comments=%d, accept_comments_label=%s WHERE id=%d",
57+
$vars['question'], $vars['qtype'], $vars['soap_type'], $vars['title'],
58+
$vars['abort_enabled'], $vars['points_abort_min'], $vars['points_abort_max'],
59+
intval(@$vars['autocontinue']), $accept_comments, $accept_comments_label, $id));
5560

5661

5762
if($result === false) throw new Exception(__('DB Error', 'chained'));
@@ -269,13 +274,7 @@ function next($question, $answer) {
269274
else {
270275
if(!empty($answer)) $answer_ids[] = $answer;
271276
}
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-
277+
279278
/** Build a questions queue to follow-up until all questions have been asked.
280279
* 1. Find follow-up questions and sort by order to be asked.
281280
* 2. Ask the first follow-up question in the list.
@@ -319,7 +318,6 @@ function next($question, $answer) {
319318
// Now sort queue to figure out what's the next question and put the remaining questions into the session queue.
320319
asort($goto); // Sort the array values from smallest to largest sort_order.
321320
$goto = array_flip($goto); // [goto, sort_order] > [sort_order, goto].
322-
error_log("Queue=[" . implode(",", $goto) . "]"); // Convert the array into CSV.
323321
$key = array_shift($goto); // Pop the first goto value.
324322
$_SESSION['chained_goto_queue'] = array_flip($goto); // [sort_order, goto] > [goto, sort_order].
325323

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: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
</p>
1010

1111
<form method="post" onsubmit="return chainedQuizValidate(this);">
12-
<p><label><?php _e('Question Title', 'chained')?></label> <input type="text" name="title" size="40" value="<?php echo @$question->title?>"></p>
13-
<p><label><?php _e('Question Contents', 'chained')?></label> <?php echo wp_editor(stripslashes(@$question->question), 'question', array('textarea_rows' => 3))?></p>
12+
<p><label><?php _e('Question Title:', 'chained')?></label> <input type="text" name="title" size="40" value="<?php echo @$question->title?>"></p>
13+
<p><label><?php _e('Question Contents:', 'chained')?></label> <?php echo wp_editor(stripslashes(@$question->question), 'question', array('textarea_rows' => 3))?></p>
1414

15+
<!-- SOAP NOTE TYPE -->
1516
<h3><?php _e('SOAP Note Type', 'chained')?></h3>
1617
<input type="radio" name="soap_type" value="n" <?php if(!empty($question->id) and $question->soap_type == 'n') echo 'checked'?>>None<br>
1718
<input type="radio" name="soap_type" value="s" <?php if(!empty($question->id) and $question->soap_type == 's') echo 'checked'?>>Subjective<br>
1819
<input type="radio" name="soap_type" value="o" <?php if(!empty($question->id) and $question->soap_type == 'o') echo 'checked'?>>Objective<br>
1920

21+
<!-- QUESTION TYPE -->
2022
<h3><?php _e('Question Type', 'chained')?></h3>
21-
2223
<p><label><select name="qtype" onchange="this.value == 'radio' ? jQuery('#chainedAutoContinue').show() : jQuery('#chainedAutoContinue').hide();">
2324
<option value="none" <?php if(!empty($question->id) and $question->qtype == 'none') echo 'selected'?>><?php _e('None (no answer required)','chained')?></option>
2425
<option value="radio" <?php if(!empty($question->id) and $question->qtype == 'radio') echo 'selected'?>><?php _e('Radio Buttons (choose one answer)','chained')?></option>
@@ -27,15 +28,29 @@
2728
<option value="text" <?php if(!empty($question->id) and $question->qtype == 'text') echo 'selected'?>><?php _e('Text Box (multiple lines of text)','chained')?></option>
2829
<option value="date" <?php if(!empty($question->id) and $question->qtype == 'date') echo 'selected'?>><?php _e('Date (calendar to pick date)','chained')?></option>
2930
</select>
31+
32+
<!-- QUESTION BEHAVIOUR -->
33+
<h3><?php _e('Question Behavior', 'chained')?></h3>
34+
<!-- Abort -->
35+
<h4><?php _e('Abort', 'chained')?></h4>
36+
<p><?php _e('Stops and finishes the Algorithm if points (so far) are within the Abort Min/Max. range.', 'chained');?></p>
37+
<p><input type="checkbox" name="abort_enabled" value="1" <?php if(!empty($question->abort_enabled)) echo 'checked'?>> <?php _e('Enable abort?', 'chained');?></p>
38+
<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;
39+
<?php _e('Abort Max. Points:', 'chained')?> <input type="text" size="4" name="points_abort_max" value="<?php echo $question->points_abort_max?>"></p>
40+
<!-- Autocontinue -->
41+
<span id="chainedAutoContinue" style="display:<?php echo (empty($question->id) or $question->qtype == 'radio') ? 'inline' : 'none';?>">
42+
<h4><?php _e('Autocontinue', 'chained')?></h4>
43+
<p><?php _e('Automatically continue to the next Question when a choice is selected.', 'chained')?></p>
44+
<p><input type="checkbox" name="autocontinue" value="1" <?php if(!empty($question->autocontinue)) echo 'checked'?>> <?php _e('Autocontinue?', 'chained')?></p>
45+
</span>
46+
<!-- Comments -->
47+
<h4><?php _e('Comments', 'chained')?></h4>
48+
<p><?php _e('Displays a field to enter additional comments with the answer.', 'chained');?></p>
49+
<p><input type="checkbox" name="accept_comments" value="1" <?php if(!empty($question->accept_comments)) echo 'checked'?>> <?php _e('Accept comments? ', 'chained');?></p>
50+
<p><?php _e('Comment Field Label:', '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>
3051

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-
33-
<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;
34-
<?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>
35-
36-
<h3><?php _e('Answers and Settings', 'chained')?></h3>
37-
38-
52+
<!-- POSSIBLE ANSWERS -->
53+
<h3><?php _e('Answers', 'chained')?></h3>
3954
<div id="answerRows">
4055
<?php if(!empty($choices) and sizeof($choices)):
4156
foreach($choices as $choice):

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)