]> git.mjollnir.org Git - moodle.git/commitdiff
Added display default feedback in lesson settings
authormark-nielsen <mark-nielsen>
Mon, 18 Sep 2006 01:31:35 +0000 (01:31 +0000)
committermark-nielsen <mark-nielsen>
Mon, 18 Sep 2006 01:31:35 +0000 (01:31 +0000)
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
mod/lesson/backuplib.php
mod/lesson/db/install.xml
mod/lesson/db/mysql.php
mod/lesson/db/mysql.sql
mod/lesson/db/postgres7.php
mod/lesson/db/postgres7.sql
mod/lesson/locallib.php
mod/lesson/mod.html
mod/lesson/restorelib.php
mod/lesson/version.php

index f05d9e875ca31577b99aa8f4d4902ab4b11aec87..f51c6a40b1d13cb289596244ae3de1c75ae4b298 100644 (file)
@@ -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;
                     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;
         
                 }
             }
             $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;
         
                 }
                 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 {
                     }
                 }
                 $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;
             $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;
                 }
                 $correctanswer = true;
             } else {
-                $response = get_string("thatsthewronganswer", "lesson");
                 $t = 0;
                 foreach ($answers as $answer) {
                     if ($answer->response == NULL && $answer->answer != NULL) {
                     break;
                 }
             }
-            if ($correctanswer) {
-                if (!$response) {
-                    $response = get_string("thatsthecorrectanswer", "lesson");
-                }
-            } else {
-                if (!$response) {
-                    $response = get_string("thatsthewronganswer", "lesson");
-                }
-            }           
             break;
 
         case LESSON_BRANCHTABLE:
                 }
             }
         }
-        // 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) {
             }
         }
 
+        // 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) {
         }
     }
 
-    // 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])) {
         }
     }
     
+    if ($nodefaultresponse) {
+        // Don't display feedback
+        redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&amp;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
index 7804debbb876f341376044a3fc740207b78a861c..bd5498b0856b9bd5c6519215d4f3d4ece68c876f 100644 (file)
@@ -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));
             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));
index 468a58e8c427c8b468a9855b9a51aed37b415a23..f19a3573b2fbad4cbf06333b268d3a56537c396d 100644 (file)
@@ -19,8 +19,9 @@
         <FIELD NAME="maxanswers" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="4" SEQUENCE="false" ENUM="false" PREVIOUS="usemaxgrade" NEXT="maxattempts"/>
         <FIELD NAME="maxattempts" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="5" SEQUENCE="false" ENUM="false" PREVIOUS="maxanswers" NEXT="review"/>
         <FIELD NAME="review" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="maxattempts" NEXT="nextpagedefault"/>
-        <FIELD NAME="nextpagedefault" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="review" NEXT="minquestions"/>
-        <FIELD NAME="minquestions" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="nextpagedefault" NEXT="maxpages"/>
+        <FIELD NAME="nextpagedefault" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="review" NEXT="feedback"/>
+        <FIELD NAME="feedback" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="nextpagedefault" NEXT="minquestions"/>
+        <FIELD NAME="minquestions" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="feedback" NEXT="maxpages"/>
         <FIELD NAME="maxpages" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="minquestions" NEXT="timed"/>
         <FIELD NAME="timed" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="maxpages" NEXT="maxtime"/>
         <FIELD NAME="maxtime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timed" NEXT="retake"/>
         <FIELD NAME="maxanswers" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="4" SEQUENCE="false" ENUM="false" PREVIOUS="usemaxgrade" NEXT="maxattempts"/>
         <FIELD NAME="maxattempts" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="5" SEQUENCE="false" ENUM="false" PREVIOUS="maxanswers" NEXT="review"/>
         <FIELD NAME="review" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="maxattempts" NEXT="nextpagedefault"/>
-        <FIELD NAME="nextpagedefault" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="review" NEXT="minquestions"/>
-        <FIELD NAME="minquestions" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="nextpagedefault" NEXT="maxpages"/>
+        <FIELD NAME="nextpagedefault" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="review" NEXT="feedback"/>
+        <FIELD NAME="feedback" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="nextpagedefault" NEXT="minquestions"/>
+        <FIELD NAME="minquestions" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="feedback" NEXT="maxpages"/>
         <FIELD NAME="maxpages" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="minquestions" NEXT="timed"/>
         <FIELD NAME="timed" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="maxpages" NEXT="maxtime"/>
         <FIELD NAME="maxtime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timed" NEXT="retake"/>
index bbdd616faf70701a697670199a8427b9b451d3cc..ad4dff5cccad78ce063bc5c0fc65798dc407564f 100644 (file)
@@ -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;
 }
 
index ebfd4b2f2f0c5fa6286937ed2dab77e02aa920df..81b026c450f885bc871f8dd41bdad9590d059b2a 100644 (file)
@@ -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',
index 2a37294c1ac4618146d04a49c5ac59cf64891d1e..09f3b0880e35d7e9a976909799f28bce30527413 100644 (file)
@@ -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;
 }
index 3b3f9aeede910dd05a6a93a464d5366e316ac17c..8e2963aa77b5caa8677697229990b2365cdf402d 100644 (file)
@@ -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',
index eb6ae9875bd2d56ffa629dc96cbc001df143297e..b28c7288ae7eb811f3d796bb6c2ef56c1326b187 100644 (file)
@@ -401,11 +401,11 @@ function lesson_print_submit_link($name, $form, $align = 'center', $class='stand
     if (empty($title)) {
         $title = $name;
     }
-    
+
     $output = "<div align=\"$align\" class=\"lessonbutton $class\">\n";
     $output .= "<script type=\"text/javascript\" charset=\"utf-8\">
                 <!--
-                    document.write('<a href=\"javascript: document.$form.submit();\" title=\"$title\"$id>$name</a>');
+                    document.write('<a href=\"javascript: document.$form.submit();\" title=\"".addslashes($title)."\"$id>".addslashes($name)."</a>');
                 // -->
                 </script>
                 <noscript>
index d778c3f025e002e4e49bd8e34db3848a26a6256f..38ea6dc81c5bea461966c9a854611a7fcccf3113 100644 (file)
@@ -31,6 +31,9 @@ if ($form->mode == "add") {
     if (!isset($form->nextpagedefault)) {
         $form->nextpagedefault = 0;
     }
+    if (!isset($form->feedback)) {
+        $form->feedback = 1;
+    }
     if (!isset($form->minquestions)) {
         $form->minquestions = 0;
     }
@@ -320,6 +323,18 @@ if ($form->mode == "add") {
     </td>
 </tr>
 
+<tr>
+    <td align="right"><strong><?php print_string('displaydefaultfeedback', 'lesson'); ?>:</strong></td>
+    <td>
+    <?php
+        $options = array();
+        $options[0] = get_string('no'); $options[1] = get_string('yes');
+        choose_from_menu($options, 'feedback', $form->feedback, '');
+        helpbutton('feedback', get_string('displaydefaultfeedback', 'lesson'), 'lesson');
+    ?>
+    </td>
+</tr>
+
 <tr valign="top">
     <td align="right"><b><?php  print_string("minimumnumberofquestions", "lesson") ?>:</b></td>
     <td>
index 6ed6137de70d36d3203c25927d5c7b5923f0a7db..c96b5308e90c440fab7225cdd57dfcbe38836416 100644 (file)
@@ -73,6 +73,7 @@
             $lesson->maxattempts = backup_todb($info['MOD']['#']['MAXATTEMPTS']['0']['#']);
             $lesson->review = backup_todb($info['MOD']['#']['REVIEW']['0']['#']);
             $lesson->nextpagedefault = backup_todb($info['MOD']['#']['NEXTPAGEDEFAULT']['0']['#']);
+            $lesson->feedback = backup_todb($info['MOD']['#']['FEEDBACK']['0']['#']);
             $lesson->minquestions = backup_todb($info['MOD']['#']['MINQUESTIONS']['0']['#']);
             $lesson->maxpages = backup_todb($info['MOD']['#']['MAXPAGES']['0']['#']);
             $lesson->timed = backup_todb($info['MOD']['#']['TIMED']['0']['#']);
                 $default->maxattempts = backup_todb($default_info['#']['MAXATTEMPTS']['0']['#']);
                 $default->review = backup_todb($default_info['#']['REVIEW']['0']['#']);
                 $default->nextpagedefault = backup_todb($default_info['#']['NEXTPAGEDEFAULT']['0']['#']);
+                $default->feedback = backup_todb($default_info['#']['FEEDBACK']['0']['#']);
                 $default->minquestions = backup_todb($default_info['#']['MINQUESTIONS']['0']['#']);
                 $default->maxpages = backup_todb($default_info['#']['MAXPAGES']['0']['#']);
                 $default->timed = backup_todb($default_info['#']['TIMED']['0']['#']);
index d6c9c34cdb23aaaeb0e2022f023dfbc98aa87a79..1d6a3ab3d08aeaf06a520fa3e3fa7947c49e1e61 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2006091201;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2006091202;  // The current module version (Date: YYYYMMDDXX)
 $module->requires = 2006080900;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)