]> git.mjollnir.org Git - moodle.git/commitdiff
Choices now support up to 6 choices. Backward compatible to 2-choice format.
authormartin <martin>
Sun, 8 Sep 2002 09:42:07 +0000 (09:42 +0000)
committermartin <martin>
Sun, 8 Sep 2002 09:42:07 +0000 (09:42 +0000)
lang/en/choice.php
mod/choice/lib.php
mod/choice/mod.html
mod/choice/report.php
mod/choice/version.php
mod/choice/view.html
mod/choice/view.php

index cf6cc88b78a2aae24d12d76b9d0f4d33c1157361..8d1b039820532302651d1c72f4812318c29632d7 100644 (file)
@@ -6,8 +6,7 @@ $string[modulenameplural] = "Choices";
 #------------------------------------------------------------
 
 $string[answered] = "Answered";
-$string[choice1] = "First choice";
-$string[choice2] = "Second choice";
+$string[choice] = "Choice \$a";
 $string[choicename] = "Choice name";
 $string[choicetext] = "Choice text";
 $string[notanswered] = "Not answered yet";
index cad24204fc599427b864e789dec110a13fec7d88..be0179b9384e3fb44ec117e16f9dbf5156e59ef8 100644 (file)
@@ -1,18 +1,11 @@
 <?PHP // $Id$
 
-function choice_user_summary($course, $user, $mod, $choice) {
-    global $CFG;
-}
-
+$CHOICE_MAX_NUMBER = 6;
 
 function choice_user_outline($course, $user, $mod, $choice) {
     if ($current = get_record_sql("SELECT * FROM choice_answers
                                    WHERE choice='$choice->id' AND user='$user->id'")) {
-        if ($current->answer == "1") {
-            $result->info = "'$choice->answer1'";
-        } else if ($current->answer == "2") {
-            $result->info = "'$choice->answer2'";
-        }
+        $result->info = "'".choice_get_answer($choice, $current->answer)."'";
         $result->time = $current->timemodified;
         return $result;
     }
@@ -23,11 +16,7 @@ function choice_user_outline($course, $user, $mod, $choice) {
 function choice_user_complete($course, $user, $mod, $choice) {
     if ($current = get_record_sql("SELECT * FROM choice_answers
                                    WHERE choice='$choice->id' AND user='$user->id'")) {
-        if ($current->answer == "1") {
-            $result->info = "'$choice->answer1'";
-        } else if ($current->answer == "2") {
-            $result->info = "'$choice->answer2'";
-        }
+        $result->info = "'".choice_get_answer($choice, $current->answer)."'";
         $result->time = $current->timemodified;
         echo get_string("answered", "choice").": $result->info , last updated ".userdate($result->time);
     } else {
@@ -90,11 +79,35 @@ function choice_get_answer($choice, $code) {
             return "$choice->answer1";
         case 2:
             return "$choice->answer2";
+        case 3:
+            return "$choice->answer3";
+        case 4:
+            return "$choice->answer4";
+        case 5:
+            return "$choice->answer5";
+        case 6:
+            return "$choice->answer6";
         default:
             return get_string("notanswered", "choice");
     }
 }
 
+function choice_get_choice($choiceid) {
+// Gets a full choice record
+
+    if ($choice = get_record("choice", "id", $choiceid)) {
+        $choice->answer[1] = $choice->answer1;
+        $choice->answer[2] = $choice->answer2;
+        $choice->answer[3] = $choice->answer3;
+        $choice->answer[4] = $choice->answer4;
+        $choice->answer[5] = $choice->answer5;
+        $choice->answer[6] = $choice->answer6;
+        return $choice;
+    } else {
+        return false;
+    }
+}
+
 
 ?>
 
index 3898b500ea86fc761d61dd37281374602a8539ab..9405973a3e28b327d363b74182e6ad7d67cd92c9 100644 (file)
     <td align=right><P><B><? print_string("choicetext","choice") ?>:</B></P></TD>
     <td>
         <textarea name="text" rows=15 cols=30 wrap="virtual"><? p($form->text) ?></textarea>
+        <? helpbutton("text", get_string("helptext")); ?>
     </td>
 </tr>
 
 <tr valign=top>
-    <td align=right><P><B><? print_string("choice1","choice") ?>:</B></P></TD>
+    <td align=right><P><B><? print_string("choice","choice","1") ?>:</B></P></TD>
     <td>
-        <input type="text" name="answer1" size=30 value="<? 
-        if ($form->answer1) {
-            p($form->answer1);
-        } else {
-            print_string("yes");
-        } ?>">
+        <input type="text" name="answer1" size=30 value="<? p($form->answer1) ?>">
+        <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
     </td>
 </tr>
 
 <tr valign=top>
-    <td align=right><P><B><? print_string("choice2","choice") ?>:</B></P></TD>
+    <td align=right><P><B><? print_string("choice","choice","2") ?>:</B></P></TD>
     <td>
-        <input type="text" name="answer2" size=30 value="<? 
-        if ($form->answer2) {
-            p($form->answer2);
-        } else {
-            print_string("no");
-        } ?>">
+        <input type="text" name="answer2" size=30 value="<? p($form->answer2) ?>">
+        <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+    </td>
+</tr>
+
+<tr valign=top>
+    <td align=right><P><B><? print_string("choice","choice","3") ?>:</B></P></TD>
+    <td>
+        <input type="text" name="answer3" size=30 value="<? p($form->answer3) ?>">
+        <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+    </td>
+</tr>
+<tr valign=top>
+    <td align=right><P><B><? print_string("choice","choice","4") ?>:</B></P></TD>
+    <td>
+        <input type="text" name="answer4" size=30 value="<? p($form->answer4) ?>">
+        <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+    </td>
+</tr>
+<tr valign=top>
+    <td align=right><P><B><? print_string("choice","choice","5") ?>:</B></P></TD>
+    <td>
+        <input type="text" name="answer5" size=30 value="<? p($form->answer5) ?>">
+        <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+    </td>
+</tr>
+<tr valign=top>
+    <td align=right><P><B><? print_string("choice","choice","6") ?>:</B></P></TD>
+    <td>
+        <input type="text" name="answer6" size=30 value="<? p($form->answer6) ?>">
+        <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
     </td>
 </tr>
 
index 1b83bc68ee2360e27becefc36e0c5645d4b24611..e74ad28fe6b6d691082bdb1bbac1566d8359a3eb 100644 (file)
@@ -19,7 +19,7 @@
         error("Only teachers can look at this page");
     }
 
-    if (! $choice = get_record("choice", "id", $cm->instance)) {
+    if (!$choice = choice_get_choice($cm->instance)) {
         error("Course module is incorrect");
     }
 
         foreach ($allanswers as $aa) {
             $answers[$aa->user] = $aa;
         }
-        
     } else {
         $answers = array () ;
     }
 
     $timenow = time();
 
-    for ($i=0; $i<=2; $i++) {    // number of choices (presently hardcoded)
-        $useranswer[$i] = array();
+    foreach ($choice->answer as $key => $answer) {  
+        $useranswer[$key] = array();
     }
-
     foreach ($users as $user) {
         $answer = $answers[$user->id];
         $useranswer[(int)$answer->answer][] = $user;
     }
+    foreach ($choice->answer as $key => $answer) {  
+        if (!$choice->answer[$key]) {
+            unset($useranswer[$key]);     // Throw away any data that doesn't apply
+        }
+    }
     ksort($useranswer);
 
     $tablewidth = (int) (100.0 / count($useranswer));
index d916fed2b45eda669d23cd7bb8bda63893b697b1..a7d554f05c2e1e399e27b2ccba44991f37640054 100644 (file)
@@ -5,13 +5,17 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002082000;
+$module->version  = 2002090800;
 $module->cron     = 0;
 
 function choice_upgrade($oldversion) {
 // This function does anything necessary to upgrade
 // older versions to match current functionality
 
+    if ($oldversion < 2002090800) {
+        execute_sql(" ALTER TABLE `choice` CHANGE `answer1` `answer1` VARCHAR( 255 )");
+        execute_sql(" ALTER TABLE `choice` CHANGE `answer2` `answer2` VARCHAR( 255 )");
+    }
     return true;
 }
 
index f43a9afdf16fa914cf45bde601e0f61edcaf8162..b5feaba43475a51e4d90e220d844b5c18b41eb22 100644 (file)
@@ -2,6 +2,7 @@
 <P>
 <FORM name="form" method="post" action="view.php">
 <TABLE WIDTH=70% CELLPADDING=20 CELLSPACING=20><TR>
+<? foreach (
 <TD ALIGN=CENTER NOWRAP WIDTH=50%>
 <INPUT type="radio" name=answer value="1" <?=$answer1checked ?> >
   <? p($choice->answer1) ?>
index 85ad5f91ca948075b5242c92f6611b7f4e8b1241..a6e615b1231162b88737d40c1a4e53825a98e83d 100644 (file)
 
     require_login($course->id);
 
-    if (! $choice = get_record("choice", "id", $cm->instance)) {
+    if (!$choice = choice_get_choice($cm->instance)) {
         error("Course module is incorrect");
     }
 
     if ($current = get_record_sql("SELECT * FROM choice_answers
                                      WHERE choice='$choice->id' AND user='$USER->id'")) {
-        if ($current->answer == "1") {
-            $answer1checked = "CHECKED";
-        } else if ($current->answer == "2") {
-            $answer2checked = "CHECKED";
-        }
+        $answerchecked[$current->answer] = "CHECKED";
     }
 
     if (match_referer() && isset($HTTP_POST_VARS)) {    // form submitted
 
     print_simple_box( text_to_html($choice->text) , "center");
 
-    require("view.html");
+    echo "<CENTER><P><FORM name=\"form\" method=\"post\" action=\"view.php\">";
+    echo "<TABLE CELLPADDING=20 CELLSPACING=20><TR>";
+
+    foreach ($choice->answer as $key => $answer) {
+        if ($answer) {
+            echo "<TD ALIGN=CENTER>";
+            echo "<INPUT type=radio name=answer value=\"$key\" ".$answerchecked[$key].">";
+            p($answer);
+            echo "</TD>";
+        }
+    }
+
+    echo "</TR></TABLE>";
+    echo "<INPUT type=hidden name=id value=\"$cm->id\">";
+    echo "<INPUT type=submit value=\"".get_string("savemychoice","choice")."\">";
+    echo "</P></FORM></CENTER>";
 
     print_footer($course);