]> git.mjollnir.org Git - moodle.git/commitdiff
New feature: choices can now be published (like polls) with names
authormoodler <moodler>
Wed, 1 Jan 2003 06:34:13 +0000 (06:34 +0000)
committermoodler <moodler>
Wed, 1 Jan 2003 06:34:13 +0000 (06:34 +0000)
or without.

mod/choice/column.png [new file with mode: 0755]
mod/choice/db/mysql.php
mod/choice/db/mysql.sql
mod/choice/db/postgres7.php
mod/choice/db/postgres7.sql
mod/choice/index.php
mod/choice/lib.php
mod/choice/mod.html
mod/choice/version.php
mod/choice/view.php

diff --git a/mod/choice/column.png b/mod/choice/column.png
new file mode 100755 (executable)
index 0000000..4c935a9
Binary files /dev/null and b/mod/choice/column.png differ
index 28c490b6c32278df63254d6477a8092a350915ee..6c555ce2768839dd627956969ba99a997831c559 100644 (file)
@@ -17,6 +17,10 @@ function choice_upgrade($oldversion) {
     if ($oldversion < 2002122300) {
         execute_sql("ALTER TABLE `choice_answers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
     }
+    if ($oldversion < 2003010100) {
+        execute_sql(" ALTER TABLE `choice` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `text` ");
+        execute_sql(" ALTER TABLE `choice` ADD `publish` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `answer6` ");
+    }
     return true;
 }
 
index 8184886ee7ac927ef5cf46b2a128606794784ca5..74de9de72b2f5dfa58d5d61098f173d7aaa9d9d9 100755 (executable)
@@ -19,12 +19,14 @@ CREATE TABLE prefix_choice (
   course int(10) unsigned NOT NULL default '0',\r
   name varchar(255) NOT NULL default '',\r
   text text NOT NULL,\r
+  format tinyint(2) unsigned NOT NULL default '0',\r
   answer1 varchar(255) NOT NULL default 'Yes',\r
   answer2 varchar(255) NOT NULL default 'No',\r
   answer3 varchar(255) default NULL,\r
   answer4 varchar(255) default NULL,\r
   answer5 varchar(255) default NULL,\r
   answer6 varchar(255) default NULL,\r
+  publish tinyint(2) unsigned NOT NULL default '0',\r
   timemodified int(10) unsigned NOT NULL default '0',\r
   PRIMARY KEY  (id),\r
   UNIQUE KEY id (id)\r
index 830a3b20a802867a361a2abe28406658a2512012..ea4ef82dc13a57bae4c61eb1a74c3e3a484737d2 100644 (file)
@@ -4,6 +4,11 @@ function choice_upgrade($oldversion) {
 // This function does anything necessary to upgrade
 // older versions to match current functionality
 
+    if ($oldversion < 2003010100) {
+        execute_sql(" ALTER TABLE `choice` ADD `format` INTEGER DEFAULT '0' NOT NULL AFTER `text` ");
+        execute_sql(" ALTER TABLE `choice` ADD `publish` INTEGER DEFAULT '0' NOT NULL AFTER `answer6` ");
+    }
+
     return true;
 }
 
index b2c8476da73aeaa8792ad63d34905e8a87bf2185..f7ba955adca6c402a42b87d8ba90d0ea561477c1 100755 (executable)
@@ -19,12 +19,14 @@ CREATE TABLE prefix_choice (
   course integer NOT NULL default '0',
   name varchar(255) NOT NULL default '',
   text text NOT NULL default '',
+  format integer NOT NULL default '0',
   answer1 varchar(255) NOT NULL default 'Yes',
   answer2 varchar(255) NOT NULL default 'No',
   answer3 varchar(255) default NULL,
   answer4 varchar(255) default NULL,
   answer5 varchar(255) default NULL,
   answer6 varchar(255) default NULL,
+  publish integer NOT NULL default '0',
   timemodified integer NOT NULL default '0'
 );
 
index c28fe4709b8b04be48652341fc8b5421ae25e28a..35d0a3b9ea7606806f66ff4e23f8f935ad711530 100644 (file)
     }
 
     foreach ($choices as $choice) {
-        $answer = $answers[$choice->id];
-        $aa = choice_get_answer($choice, $answer->answer);
+        if (!empty($answers[$choice->id])) {
+            $answer = $answers[$choice->id];
+        } else {
+            $answer = "";
+        }
+        if (!empty($answer->answer)) {
+            $aa = choice_get_answer($choice, $answer->answer);
+        } else {
+            $aa = "";
+        }
 
         if ($course->format == "weeks" || $course->format == "topics") {
             $table->data[] = array ("$choice->section",
index eb8ce90e1fba2fc6465bbdf2c08671d7678d8a88..ea4a85761d1e592d3706d729deea00876d9a8ddc 100644 (file)
@@ -2,6 +2,19 @@
 
 $CHOICE_MAX_NUMBER = 6;
 
+$COLUMN_HEIGHT = 300;
+
+define("CHOICE_PUBLISH_NOT",       "0");
+define("CHOICE_PUBLISH_ANONYMOUS", "1");
+define("CHOICE_PUBLISH_NAMES",     "2");
+
+$CHOICE_PUBLISH = array (CHOICE_PUBLISH_NOT        => get_string("publishnot", "choice"),
+                         CHOICE_PUBLISH_ANONYMOUS  => get_string("publishanonymous", "choice"),
+                         CHOICE_PUBLISH_NAMES      => get_string("publishnames", "choice"));
+
+
+/// Standard functions /////////////////////////////////////////////////////////
+
 function choice_user_outline($course, $user, $mod, $choice) {
     if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $user->id)) {
         $result->info = "'".choice_get_answer($choice, $current->answer)."'";
index 240ff537592aedee6452006a3487c5c2c8885ca8..44fac6fc1bd1d418d119b4156582679db50a6098 100644 (file)
@@ -1,4 +1,45 @@
-<FORM NAME="form" METHOD="post" ACTION="<?=$ME ?>">
+<?PHP
+    if (empty($form->name)) {
+        $form->name = "";
+    }
+    if (empty($form->text)) {
+        $form->text = "";
+    }
+    if (empty($form->format)) {
+        $form->format = "";
+    }
+    if (empty($form->answer1)) {
+        $form->answer1 = "";
+    }
+    if (empty($form->answer2)) {
+        $form->answer2 = "";
+    }
+    if (empty($form->answer3)) {
+        $form->answer3 = "";
+    }
+    if (empty($form->answer4)) {
+        $form->answer4 = "";
+    }
+    if (empty($form->answer5)) {
+        $form->answer5 = "";
+    }
+    if (empty($form->answer6)) {
+        $form->answer6 = "";
+    }
+    if (empty($form->publish)) {
+        $form->publish = "";
+    }
+
+    if ($usehtmleditor = can_use_richtext_editor()) {
+        $defaultformat = FORMAT_HTML;
+        $onsubmit = "onsubmit=\"copyrichtext(document.form.description);\"";
+    } else {
+        $defaultformat = FORMAT_MOODLE;
+        $onsubmit = "";
+    }
+
+?>
+<form name="form" method="post" <?=$onsubmit ?> action="<?=$ME ?>">
 
 <table cellpadding=5>
 
     <font SIZE="1">
      <? helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br \>
      <? helpbutton("questions", get_string("helpquestions"), "moodle", true, true) ?><br \>
-     <? helpbutton("text", get_string("helptext"), "moodle", true, true) ?><br \>
+     <? if ($usehtmleditor) { ?>
+        <? helpbutton("richtext", get_string("helprichtext"), "moodle", true, true) ?>
+     <? } else { ?>
+        <? helpbutton("text", get_string("helptext"), "moodle", true, true) ?>
+     <? } ?><br \>
      </font>
     </td>
     <td>
-        <textarea name="text" rows=20 cols=40 wrap="virtual"><? p($form->text) ?></textarea>
+    <? 
+       print_textarea($usehtmleditor, 20, 60, 680, 400, "text", $form->text);
+    
+       echo "<P align=right>";
+       print_string("formattexttype");
+       echo ":&nbsp;";
+       if (!$form->format) {
+           $form->format = $defaultformat;
+       }
+       choose_from_menu(format_text_menu(), "format", $form->format, ""); 
+       helpbutton("textformat", get_string("formattexttype"));
+       echo "</P>";
+    ?>
     </td>
 </tr>
 
 <tr valign=top>
     <td align=right><P><B><? print_string("choice","choice","1") ?>:</B></P></TD>
     <td>
-        <input type="text" name="answer1" size=30 value="<? p($form->answer1) ?>">
+        <input type="text" name="answer1" size=60 value="<? p($form->answer1) ?>">
         <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
     </td>
 </tr>
@@ -33,7 +90,7 @@
 <tr valign=top>
     <td align=right><P><B><? print_string("choice","choice","2") ?>:</B></P></TD>
     <td>
-        <input type="text" name="answer2" size=30 value="<? p($form->answer2) ?>">
+        <input type="text" name="answer2" size=60 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) ?>">
+        <input type="text" name="answer3" size=60 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) ?>">
+        <input type="text" name="answer4" size=60 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) ?>">
+        <input type="text" name="answer5" size=60 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) ?>">
+        <input type="text" name="answer6" size=60 value="<? p($form->answer6) ?>">
         <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
     </td>
 </tr>
+<tr valign=top>
+    <td align=right><P><B><? print_string("publish","choice") ?>:</b></p></td>
+    <td>
+        <?
+        require("$CFG->dirroot/mod/choice/lib.php");
+        choose_from_menu($CHOICE_PUBLISH, "publish", "$form->publish", "");
+        ?>
+        <br \>
+    </td>
+</tr>
 
 </table>
 
 <input type="submit" name=cancel value="<? print_string("cancel") ?>">
 </CENTER>
 </FORM>
+
+<?PHP
+   if ($usehtmleditor) { 
+       print_richedit_javascript("form", "text", "yes");
+   }
+?>
index a8433671888ced7f345edd002eef1bdb847a43ad..53e00064b070f0dcd619440fde56bd25eaae87ce 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002122300;
+$module->version  = 2003010100;
 $module->cron     = 0;
 
 ?>
index 22f7190dadc5e41110c3085a7df9c1ed065ca718..8dd8a54d4d4fd7f3e716466e270391c5f4a724b3 100644 (file)
@@ -19,6 +19,9 @@
         error("Course module is incorrect");
     }
 
+    for ($i=1; $i <= $CHOICE_MAX_NUMBER; $i++) {
+        $answerchecked[$i] = "";
+    }
     if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $USER->id)) {
         $answerchecked[$current->answer] = "CHECKED";
     }
 
     print_simple_box( text_to_html($choice->text) , "center");
 
-    echo "<CENTER><P><FORM name=\"form\" method=\"post\" action=\"view.php\">";
-    echo "<TABLE CELLPADDING=20 CELLSPACING=20><TR>";
+    if (!$current or !$choice->publish) {  // They haven't made their choice yet
+        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>";
+        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\">";
+        if (!isguest()) {
+            echo "<INPUT type=submit value=\"".get_string("savemychoice","choice")."\">";
+        }
+        echo "</P></FORM></CENTER>";
 
-    echo "</TR></TABLE>";
-    echo "<INPUT type=hidden name=id value=\"$cm->id\">";
-    if (!isguest()) {
-        echo "<INPUT type=submit value=\"".get_string("savemychoice","choice")."\">";
-    }
-    echo "</P></FORM></CENTER>";
+    } else {  // Print results.
+
+        print_heading(get_string("responses", "choice"));
+
+        if (! $users = get_course_users($course->id, "u.firstname ASC")) {
+            error("No users found (very strange)");
+        }
 
+        if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) {
+            foreach ($allanswers as $aa) {
+                $answers[$aa->userid] = $aa;
+            }
+        } else {
+            $answers = array () ;
+        }
+
+        $timenow = time();
+
+        foreach ($choice->answer as $key => $answer) {  
+            $useranswer[$key] = array();
+        }
+        foreach ($users as $user) {
+            if (!empty($user->id) and !empty($answers[$user->id])) {
+                $answer = $answers[$user->id];
+                $useranswer[(int)$answer->answer][] = $user;
+            } else {
+                $answer = "";
+                $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);
+
+        switch ($choice->publish) {
+          case CHOICE_PUBLISH_NAMES:
+
+            $tablewidth = (int) (100.0 / count($useranswer));
+
+            echo "<TABLE CELLPADDING=5 CELLSPACING=10 ALIGN=CENTER>";
+            echo "<TR>";
+            foreach ($useranswer as $key => $answer) {
+                if ($key) {
+                    echo "<TH WIDTH=\"$tablewidth%\">";
+                } else {
+                    echo "<TH BGCOLOR=\"$THEME->body\" WIDTH=\"$tablewidth%\">";
+                }
+                echo choice_get_answer($choice, $key);
+                echo "</TH>";
+            }
+            echo "</TR><TR>";
+        
+            foreach ($useranswer as $key => $answer) {
+                if ($key) {
+                    echo "<TD WIDTH=\"$tablewidth%\" VALIGN=TOP NOWRAP BGCOLOR=\"$THEME->cellcontent\">";
+                } else {
+                    echo "<TD WIDTH=\"$tablewidth%\" VALIGN=TOP NOWRAP BGCOLOR=\"$THEME->body\">";
+                }
+    
+                echo "<TABLE WIDTH=100%>";
+                foreach ($answer as $user) {
+                    echo "<TR><TD WIDTH=10 NOWRAP>";
+                    print_user_picture($user->id, $course->id, $user->picture);
+                    echo "</TD><TD WIDTH=100% NOWRAP>";
+                    echo "<P>$user->firstname $user->lastname</P>";
+                    echo "</TD></TR>";
+                }
+                echo "</TABLE>";
+        
+                echo "</TD>";
+            }
+            echo "</TR></TABLE>";
+            break;
+
+
+          case CHOICE_PUBLISH_ANONYMOUS:
+            $tablewidth = (int) (100.0 / count($useranswer));
+
+            echo "<TABLE CELLPADDING=5 CELLSPACING=10 ALIGN=CENTER>";
+            echo "<TR>";
+            foreach ($useranswer as $key => $answer) {
+                if ($key) {
+                    echo "<TH WIDTH=\"$tablewidth%\">";
+                } else {
+                    echo "<TH BGCOLOR=\"$THEME->body\" WIDTH=\"$tablewidth%\">";
+                }
+                echo choice_get_answer($choice, $key);
+                echo "</TH>";
+            }
+            echo "</TR>";
+
+            $maxcolumn = 0;
+            foreach ($useranswer as $key => $answer) {
+                $column[$key] = count($answer);
+                if ($column[$key] > $maxcolumn) {
+                    $maxcolumn = $column[$key];
+                }
+            }
+
+            echo "<TR>";
+            foreach ($useranswer as $key => $answer) {
+                $height = $COLUMN_HEIGHT * ((float)$column[$key] / (float)$maxcolumn);
+                echo "<TD VALIGN=\"BOTTOM\" ALIGN=\"CENTER\">";
+                echo "<IMG SRC=\"column.png\" HEIGHT=\"$height\" width=\"49\"></TD>";
+            }
+            echo "</TR>";
+
+            echo "<TR>";
+            foreach ($useranswer as $key => $answer) {
+                echo "<TD ALIGN=\"CENTER\">".$column[$key]."</TD>";
+            }
+            echo "</TR></TABLE>";
+
+            break;
+        }
+    }
+    
     print_footer($course);