From 6d6c9389996e934f2c1c6a092f675d3d6ac4b5ac Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 1 Jan 2003 06:34:13 +0000 Subject: [PATCH] New feature: choices can now be published (like polls) with names or without. --- mod/choice/column.png | Bin 0 -> 400 bytes mod/choice/db/mysql.php | 4 + mod/choice/db/mysql.sql | 2 + mod/choice/db/postgres7.php | 5 ++ mod/choice/db/postgres7.sql | 2 + mod/choice/index.php | 12 ++- mod/choice/lib.php | 13 +++ mod/choice/mod.html | 91 ++++++++++++++++++--- mod/choice/version.php | 2 +- mod/choice/view.php | 154 ++++++++++++++++++++++++++++++++---- 10 files changed, 258 insertions(+), 27 deletions(-) create mode 100755 mod/choice/column.png diff --git a/mod/choice/column.png b/mod/choice/column.png new file mode 100755 index 0000000000000000000000000000000000000000..4c935a9dad2f445d68ff4b8dd13dbba2e17014da GIT binary patch literal 400 zcmeAS@N?(olHy`uVBq!ia0vp^hCpn@!2~3$vX(prQY`6?zK#qG>ra@ocD)4hB}-f* zN`mv#O3D+9QW+dm@{>{(JaZG%Q-e|yQz{EjrrIztFe-VvIEGZ*O8W8tzdf^-M1f!f uLsF7N4TC}h+v3>_Oc@5dI7c?~07C`8w8yULiCcj|%HZkh=d#Wzp$Py5WOTLw literal 0 HcmV?d00001 diff --git a/mod/choice/db/mysql.php b/mod/choice/db/mysql.php index 28c490b6c3..6c555ce276 100644 --- a/mod/choice/db/mysql.php +++ b/mod/choice/db/mysql.php @@ -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; } diff --git a/mod/choice/db/mysql.sql b/mod/choice/db/mysql.sql index 8184886ee7..74de9de72b 100755 --- a/mod/choice/db/mysql.sql +++ b/mod/choice/db/mysql.sql @@ -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) diff --git a/mod/choice/db/postgres7.php b/mod/choice/db/postgres7.php index 830a3b20a8..ea4ef82dc1 100644 --- a/mod/choice/db/postgres7.php +++ b/mod/choice/db/postgres7.php @@ -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; } diff --git a/mod/choice/db/postgres7.sql b/mod/choice/db/postgres7.sql index b2c8476da7..f7ba955adc 100755 --- a/mod/choice/db/postgres7.sql +++ b/mod/choice/db/postgres7.sql @@ -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' ); diff --git a/mod/choice/index.php b/mod/choice/index.php index c28fe4709b..35d0a3b9ea 100644 --- a/mod/choice/index.php +++ b/mod/choice/index.php @@ -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", diff --git a/mod/choice/lib.php b/mod/choice/lib.php index eb8ce90e1f..ea4a85761d 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -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)."'"; diff --git a/mod/choice/mod.html b/mod/choice/mod.html index 240ff53759..44fac6fc1b 100644 --- a/mod/choice/mod.html +++ b/mod/choice/mod.html @@ -1,4 +1,45 @@ -
+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 = ""; + } + +?> + action=""> @@ -14,18 +55,34 @@

-
+ + + + +
@@ -33,7 +90,7 @@ @@ -41,31 +98,41 @@ + + + +
- + text); + + echo "

"; + print_string("formattexttype"); + echo ": "; + if (!$form->format) { + $form->format = $defaultformat; + } + choose_from_menu(format_text_menu(), "format", $form->format, ""); + helpbutton("textformat", get_string("formattexttype")); + echo "

"; + ?>

:

- +

:

- +

:

- +

:

- +

:

- +

:

- +

:

+ dirroot/mod/choice/lib.php"); + choose_from_menu($CHOICE_PUBLISH, "publish", "$form->publish", ""); + ?> +
+
@@ -81,3 +148,9 @@ ">
+ + diff --git a/mod/choice/version.php b/mod/choice/version.php index a843367188..53e00064b0 100644 --- a/mod/choice/version.php +++ b/mod/choice/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2002122300; +$module->version = 2003010100; $module->cron = 0; ?> diff --git a/mod/choice/view.php b/mod/choice/view.php index 22f7190dad..8dd8a54d4d 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -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 "

"; - echo ""; + if (!$current or !$choice->publish) { // They haven't made their choice yet + echo "

"; + echo "

"; - foreach ($choice->answer as $key => $answer) { - if ($answer) { - echo ""; + foreach ($choice->answer as $key => $answer) { + if ($answer) { + echo ""; + } } - } + + echo "
"; - echo ""; - p($answer); - echo ""; + echo ""; + p($answer); + echo "
"; + echo "id\">"; + if (!isguest()) { + echo ""; + } + echo "

"; - echo ""; - echo "id\">"; - if (!isguest()) { - echo ""; - } - echo "

"; + } 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 ""; + echo ""; + foreach ($useranswer as $key => $answer) { + if ($key) { + echo ""; + } + echo ""; + + foreach ($useranswer as $key => $answer) { + if ($key) { + echo ""; + } + echo "
"; + } else { + echo "body\" WIDTH=\"$tablewidth%\">"; + } + echo choice_get_answer($choice, $key); + echo "
cellcontent\">"; + } else { + echo "body\">"; + } + + echo ""; + foreach ($answer as $user) { + echo ""; + } + echo "
"; + print_user_picture($user->id, $course->id, $user->picture); + echo ""; + echo "

$user->firstname $user->lastname

"; + echo "
"; + + echo "
"; + break; + + + case CHOICE_PUBLISH_ANONYMOUS: + $tablewidth = (int) (100.0 / count($useranswer)); + + echo ""; + echo ""; + foreach ($useranswer as $key => $answer) { + if ($key) { + echo ""; + } + echo ""; + + $maxcolumn = 0; + foreach ($useranswer as $key => $answer) { + $column[$key] = count($answer); + if ($column[$key] > $maxcolumn) { + $maxcolumn = $column[$key]; + } + } + + echo ""; + foreach ($useranswer as $key => $answer) { + $height = $COLUMN_HEIGHT * ((float)$column[$key] / (float)$maxcolumn); + echo ""; + } + echo ""; + + echo ""; + foreach ($useranswer as $key => $answer) { + echo ""; + } + echo "
"; + } else { + echo "body\" WIDTH=\"$tablewidth%\">"; + } + echo choice_get_answer($choice, $key); + echo "
"; + echo "
".$column[$key]."
"; + + break; + } + } + print_footer($course); -- 2.39.5