New feature: choices can now be published (like polls) with names

or without.
This commit is contained in:
moodler 2003-01-01 06:34:13 +00:00
parent 366287b705
commit 6d6c938999
10 changed files with 259 additions and 28 deletions

BIN
mod/choice/column.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

View 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;
}

View File

@ -19,12 +19,14 @@ CREATE TABLE prefix_choice (
course int(10) unsigned NOT NULL default '0',
name varchar(255) NOT NULL default '',
text text NOT NULL,
format tinyint(2) unsigned 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 tinyint(2) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)

View 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;
}

View File

@ -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'
);

View File

@ -52,8 +52,16 @@
}
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",

View 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)."'";

View 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>
@ -14,18 +55,34 @@
<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>
@ -41,31 +98,41 @@
<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>
@ -81,3 +148,9 @@
<input type="submit" name=cancel value="<? print_string("cancel") ?>">
</CENTER>
</FORM>
<?PHP
if ($usehtmleditor) {
print_richedit_javascript("form", "text", "yes");
}
?>

View File

@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2002122300;
$module->version = 2003010100;
$module->cron = 0;
?>

View 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";
}
@ -71,25 +74,146 @@
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>";
} 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;
}
}
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>";
print_footer($course);