From 62bb11d83794e2ae30ff705a62974c1147533ba5 Mon Sep 17 00:00:00 2001 From: mark-nielsen Date: Mon, 18 Sep 2006 01:31:35 +0000 Subject: [PATCH] Added display default feedback in lesson settings Led to reducing some redundant code in action/continue.php Also, a bug fix in locallib.php for function lesson_print_submit_link (needed to add slashes or else js would break) --- mod/lesson/action/continue.php | 76 +++++++++++++++------------------- mod/lesson/backuplib.php | 2 + mod/lesson/db/install.xml | 10 +++-- mod/lesson/db/mysql.php | 5 +++ mod/lesson/db/mysql.sql | 2 + mod/lesson/db/postgres7.php | 5 +++ mod/lesson/db/postgres7.sql | 2 + mod/lesson/locallib.php | 4 +- mod/lesson/mod.html | 15 +++++++ mod/lesson/restorelib.php | 2 + mod/lesson/version.php | 2 +- 11 files changed, 75 insertions(+), 50 deletions(-) diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index f05d9e875ca..f51c6a40b1d 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -65,7 +65,6 @@ error("Continue: No answers found"); } $correctanswer = false; - $response = get_string('defaultessayresponse', 'lesson'); foreach ($answers as $answer) { $answerid = $answer->id; $newpageid = $answer->jumpto; @@ -181,13 +180,6 @@ break; // quit answer analysis immediately after a match has been found } } - if (!isset($response)) { //if no feedback message provided, use default message - if ($correctanswer) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } else { - $response = get_string("thatsthewronganswer", "lesson"); - } - } $studentanswer = $useranswer; break; @@ -211,13 +203,7 @@ } } $newpageid = $answer->jumpto; - if (!$response = trim($answer->response)) { - if ($correctanswer) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } else { - $response = get_string("thatsthewronganswer", "lesson"); - } - } + $response = trim($answer->response); $studentanswer = $answer->answer; break; @@ -318,14 +304,10 @@ } if ((count($useranswers) == $ncorrect) and ($nhits == $ncorrect)) { $correctanswer = true; - if (!$response = $correctresponse) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } + $response = $correctresponse; $newpageid = $correctpageid; } else { - if (!$response = $wrongresponse) { - $response = get_string("thatsthewronganswer", "lesson"); - } + $response = $wrongresponse; $newpageid = $wrongpageid; } } else { @@ -349,13 +331,7 @@ } } $newpageid = $answer->jumpto; - if (!$response = trim($answer->response)) { - if ($correctanswer) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } else { - $response = get_string("thatsthewronganswer", "lesson"); - } - } + $response = trim($answer->response); $studentanswer = $answer->answer; } break; @@ -409,7 +385,6 @@ $userresponse = implode(",", $userresponse); if ($ncorrect == count($answers)-2) { // dont count correct/wrong responses in the total. - $response = get_string("thatsthecorrectanswer", "lesson"); foreach ($answers as $answer) { if ($answer->response == NULL && $answer->answer != NULL) { $response = $answer->answer; @@ -424,7 +399,6 @@ } $correctanswer = true; } else { - $response = get_string("thatsthewronganswer", "lesson"); $t = 0; foreach ($answers as $answer) { if ($answer->response == NULL && $answer->answer != NULL) { @@ -483,15 +457,6 @@ break; } } - if ($correctanswer) { - if (!$response) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } - } else { - if (!$response) { - $response = get_string("thatsthewronganswer", "lesson"); - } - } break; case LESSON_BRANCHTABLE: @@ -600,7 +565,7 @@ } } } - // convert jumpto page into a proper page id + // TODO: merge this code with the jump code below. Convert jumpto page into a proper page id if ($newpageid == 0) { $newpageid = $pageid; } elseif ($newpageid == LESSON_NEXTPAGE) { @@ -653,17 +618,37 @@ } } + // Determine default feedback if necessary + $nodefaultresponse = false; // Flag for redirecting when default feedback is turned off + if (empty($response)) { + if (!$lesson->feedback and !$noanswer and !($lesson->review and !$correctanswer and !$isessayquestion)) { + // These conditions have been met: + // 1. The lesson manager has not supplied feedback to the student + // 2. Not displaying default feedback + // 3. The user did provide an answer + // 4. We are not reviewing with an incorrect answer (and not reviewing an essay question) + + $nodefaultresponse = true; // This will cause a redirect below + } else if ($isessayquestion) { + $response = get_string('defaultessayresponse', 'lesson'); + } else if ($correctanswer) { + $response = get_string('thatsthecorrectanswer', 'lesson'); + } else { + $response = get_string('thatsthewronganswer', 'lesson'); + } + } + // display response (if there is one - there should be!) // display: lesson title, page title, question text, student's answer(s) before feedback message if ($noanswer) { - $feedback = get_string("noanswer", "lesson"); + $feedback = get_string('noanswer', 'lesson'); } else if ($response) { //optionally display question page title //if ($title = get_field("lesson_pages", "title", "id", $pageid)) { // print_heading($title); //} - if ($lesson->review && !$correctanswer && !$isessayquestion) { + if ($lesson->review and !$correctanswer and !$isessayquestion) { $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); $qattempts = count_records("lesson_attempts", "userid", $USER->id, "retry", $nretakes, "pageid", $pageid); if ($qattempts == 1) { @@ -689,7 +674,7 @@ } } - // this is where some jump numbers are interpreted + // TODO: merge with the jump code above. This is where some jump numbers are interpreted if($outoftime) { $newpageid = LESSON_EOL; // ran out of time for the test, so go to eol } elseif (isset($USER->modattempts[$lesson->id])) { @@ -756,6 +741,11 @@ } } + if ($nodefaultresponse) { + // Don't display feedback + redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&pageid=$newpageid"); + } + /// Set Messages // This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index 7804debbb87..bd5498b0856 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -83,6 +83,7 @@ fwrite ($bf,full_tag("MAXATTEMPTS",4,false,$lesson->maxattempts)); fwrite ($bf,full_tag("REVIEW",4,false,$lesson->review)); fwrite ($bf,full_tag("NEXTPAGEDEFAULT",4,false,$lesson->nextpagedefault)); + fwrite ($bf,full_tag("FEEDBACK",4,false,$lesson->feedback)); fwrite ($bf,full_tag("MINQUESTIONS",4,false,$lesson->minquestions)); fwrite ($bf,full_tag("MAXPAGES",4,false,$lesson->maxpages)); fwrite ($bf,full_tag("TIMED",4,false,$lesson->timed)); @@ -405,6 +406,7 @@ fwrite ($bf,full_tag("MAXATTEMPTS",5,false,$default->maxattempts)); fwrite ($bf,full_tag("REVIEW",5,false,$default->review)); fwrite ($bf,full_tag("NEXTPAGEDEFAULT",5,false,$default->nextpagedefault)); + fwrite ($bf,full_tag("FEEDBACK",5,false,$default->feedback)); fwrite ($bf,full_tag("MINQUESTIONS",5,false,$default->minquestions)); fwrite ($bf,full_tag("MAXPAGES",5,false,$default->maxpages)); fwrite ($bf,full_tag("TIMED",5,false,$default->timed)); diff --git a/mod/lesson/db/install.xml b/mod/lesson/db/install.xml index 468a58e8c42..f19a3573b2f 100644 --- a/mod/lesson/db/install.xml +++ b/mod/lesson/db/install.xml @@ -19,8 +19,9 @@ - - + + + @@ -145,8 +146,9 @@ - - + + + diff --git a/mod/lesson/db/mysql.php b/mod/lesson/db/mysql.php index bbdd616faf7..ad4dff5ccca 100644 --- a/mod/lesson/db/mysql.php +++ b/mod/lesson/db/mysql.php @@ -231,6 +231,11 @@ function lesson_upgrade($oldversion) { table_column('lesson_default', '', 'mediawidth', 'int', '10', 'unsigned', '650', 'not null', 'retake'); } + if ($oldversion < 2006091202) { + table_column('lesson', '', 'feedback', 'int', '3', 'unsigned', '1', 'not null', 'nextpagedefault'); + table_column('lesson_default', '', 'feedback', 'int', '3', 'unsigned', '1', 'not null', 'nextpagedefault'); + } + return true; } diff --git a/mod/lesson/db/mysql.sql b/mod/lesson/db/mysql.sql index ebfd4b2f2f0..81b026c450f 100644 --- a/mod/lesson/db/mysql.sql +++ b/mod/lesson/db/mysql.sql @@ -22,6 +22,7 @@ CREATE TABLE `prefix_lesson` ( `maxattempts` int(3) unsigned NOT NULL default '5', `review` TINYINT(3) UNSIGNED NOT NULL default '0', `nextpagedefault` int(3) unsigned NOT NULL default '0', + `feedback` int(3) unsigned NOT NULL default '1', `minquestions` int(3) unsigned NOT NULL default '0', `maxpages` int(3) unsigned NOT NULL default '0', `timed` TINYINT(3) UNSIGNED NOT NULL default '0', @@ -131,6 +132,7 @@ CREATE TABLE `prefix_lesson_default` `maxattempts` int(3) unsigned NOT NULL default '5', `review` tinyint(3) unsigned NOT NULL default '0', `nextpagedefault` int(3) unsigned NOT NULL default '0', + `feedback` int(3) unsigned NOT NULL default '1', `minquestions` tinyint(3) unsigned NOT NULL default '0', `maxpages` int(3) unsigned NOT NULL default '0', `timed` int(3) unsigned NOT NULL default '0', diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index 2a37294c1ac..09f3b0880e3 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -352,6 +352,11 @@ function lesson_upgrade($oldversion) { modify_database('', 'ALTER TABLE prefix_lesson_high_scores ALTER COLUMN userid SET DEFAULT 0'); } + + if ($oldversion < 2006091202) { + table_column('lesson', '', 'feedback', 'int', '3', 'unsigned', '1', 'not null', 'nextpagedefault'); + table_column('lesson_default', '', 'feedback', 'int', '3', 'unsigned', '1', 'not null', 'nextpagedefault'); + } return true; } diff --git a/mod/lesson/db/postgres7.sql b/mod/lesson/db/postgres7.sql index 3b3f9aeede9..8e2963aa77b 100644 --- a/mod/lesson/db/postgres7.sql +++ b/mod/lesson/db/postgres7.sql @@ -16,6 +16,7 @@ CREATE TABLE prefix_lesson ( maxattempts INT NOT NULL default '5', review INT NOT NULL DEFAULT '0', nextpagedefault INT NOT NULL default '0', + feedback INT NOT NULL default '1', minquestions INT NOT NULL default '0', maxpages INT NOT NULL default '0', timed INT NOT NULL DEFAULT '0', @@ -119,6 +120,7 @@ CREATE TABLE prefix_lesson_default maxattempts INT NOT NULL default '5', review INT NOT NULL default '0', nextpagedefault INT NOT NULL default '0', + feedback INT NOT NULL default '1', minquestions INT NOT NULL default '0', maxpages INT NOT NULL default '0', timed INT NOT NULL default '0', diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index eb6ae9875bd..b28c7288ae7 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -401,11 +401,11 @@ function lesson_print_submit_link($name, $form, $align = 'center', $class='stand if (empty($title)) { $title = $name; } - + $output = "
\n"; $output .= "