From cd3fccff00a2999a2061e628936221022186b01f Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 8 Sep 2002 09:42:07 +0000 Subject: [PATCH] Choices now support up to 6 choices. Backward compatible to 2-choice format. --- lang/en/choice.php | 3 +-- mod/choice/lib.php | 41 ++++++++++++++++++++++------------ mod/choice/mod.html | 50 ++++++++++++++++++++++++++++++------------ mod/choice/report.php | 13 ++++++----- mod/choice/version.php | 6 ++++- mod/choice/view.html | 1 + mod/choice/view.php | 25 +++++++++++++++------ 7 files changed, 96 insertions(+), 43 deletions(-) diff --git a/lang/en/choice.php b/lang/en/choice.php index cf6cc88b78..8d1b039820 100644 --- a/lang/en/choice.php +++ b/lang/en/choice.php @@ -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"; diff --git a/mod/choice/lib.php b/mod/choice/lib.php index cad24204fc..be0179b938 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -1,18 +1,11 @@ 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; + } +} + ?> diff --git a/mod/choice/mod.html b/mod/choice/mod.html index 3898b500ea..9405973a3e 100644 --- a/mod/choice/mod.html +++ b/mod/choice/mod.html @@ -13,30 +13,52 @@

:

+ -

:

+

:

- "> + + -

:

+

:

- "> + + + + + + +

:

+ + + + + + +

:

+ + + + + + +

:

+ + + + + + +

:

+ + + diff --git a/mod/choice/report.php b/mod/choice/report.php index 1b83bc68ee..e74ad28fe6 100644 --- a/mod/choice/report.php +++ b/mod/choice/report.php @@ -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"); } @@ -43,21 +43,24 @@ 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)); diff --git a/mod/choice/version.php b/mod/choice/version.php index d916fed2b4..a7d554f05c 100644 --- a/mod/choice/version.php +++ b/mod/choice/version.php @@ -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; } diff --git a/mod/choice/view.html b/mod/choice/view.html index f43a9afdf1..b5feaba434 100644 --- a/mod/choice/view.html +++ b/mod/choice/view.html @@ -2,6 +2,7 @@

+ > answer1) ?> diff --git a/mod/choice/view.php b/mod/choice/view.php index 85ad5f91ca..a6e615b123 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -15,17 +15,13 @@ 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 @@ -76,7 +72,22 @@ print_simple_box( text_to_html($choice->text) , "center"); - require("view.html"); + echo "

"; + echo "

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

"; print_footer($course); -- 2.39.5