Skip to content

Commit fd5dafc

Browse files
committed
Fixed #3
1 parent 98932cd commit fd5dafc

4 files changed

Lines changed: 44 additions & 27 deletions

File tree

controllers/quizzes.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ static function answer_question() {
177177

178178
// calculate points
179179
$points = $_question->calculate_points($question, $answer);
180-
echo $points."|CHAINEDQUIZ|";
180+
echo $points."|CHAINEDQUIZ|";
181+
$total_points = $points + floatval($_POST['points']); // Points for the whole algorithm.
181182

182183
// figure out next question
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.
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;
187187
} else {
188188
$next_question = $_question->next($question, $answer);
189189
}
@@ -225,9 +225,8 @@ static function answer_question() {
225225
include(CHAINED_PATH."/views/display-quiz.html.php");
226226
}
227227
else {
228-
// add to points
229-
$points += floatval($_POST['points']);
230-
echo $_quiz->finalize($quiz, $points); // if none, submit the quiz
228+
// if none, submit the quiz
229+
echo $_quiz->finalize($quiz, $total_points);
231230
}
232231
}
233232
}

models/basic.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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,
4243
`points_abort_min` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
4344
`points_abort_max` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
4445
`autocontinue` TINYINT UNSIGNED NOT NULL DEFAULT 0,
@@ -147,8 +148,9 @@ static function install($update = false) {
147148
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN assessment TEXT AFTER objective;");
148149
$wpdb->query("ALTER TABLE ".CHAINED_RESULTS." ADD COLUMN plan TEXT AFTER assessment;");
149150
} 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;");
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;");
152154
}
153155

154156
// Set the current plugin version number.

models/question.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ 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, points_abort_min=%f, points_abort_max=%f, 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['points_abort_min'], $vars['points_abort_max'],
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'],
2931
$vars['title'], intval(@$vars['autocontinue']), $sort_order, $accept_comments, $accept_comments_label));
3032

3133
if($result === false) throw new Exception(__('DB Error', 'chained'));
@@ -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, 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']),
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'));
@@ -313,7 +318,6 @@ function next($question, $answer) {
313318
// Now sort queue to figure out what's the next question and put the remaining questions into the session queue.
314319
asort($goto); // Sort the array values from smallest to largest sort_order.
315320
$goto = array_flip($goto); // [goto, sort_order] > [sort_order, goto].
316-
error_log("Queue=[" . implode(",", $goto) . "]"); // Convert the array into CSV.
317321
$key = array_shift($goto); // Pop the first goto value.
318322
$_SESSION['chained_goto_queue'] = array_flip($goto); // [sort_order, goto] > [goto, sort_order].
319323

views/question.html.php

Lines changed: 22 additions & 10 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>
@@ -28,17 +29,28 @@
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>
3031

32+
<!-- QUESTION BEHAVIOUR -->
3133
<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>
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>
3338
<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;
3439
<?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>
36-
<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;
37-
<?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>
38-
39-
<h3><?php _e('Answers', 'chained')?></h3>
40-
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>
4151

52+
<!-- POSSIBLE ANSWERS -->
53+
<h3><?php _e('Answers', 'chained')?></h3>
4254
<div id="answerRows">
4355
<?php if(!empty($choices) and sizeof($choices)):
4456
foreach($choices as $choice):

0 commit comments

Comments
 (0)