From c2a4d0169bad30c864e76c958405ec42954a2ab7 Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 3 Mar 2008 05:12:22 +0000 Subject: [PATCH] Merged MDL-13753 to add percentages --- mod/choice/lib.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mod/choice/lib.php b/mod/choice/lib.php index 26e66cf50e..3280472d76 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -306,6 +306,13 @@ function choice_show_results($choice, $course, $cm, $users, $forcepublish='') { if (!$users) { print_heading(get_string("nousersyet")); } + + $totalresponsecount = 0; + foreach ($users as $optionid => $userlist) { + if ($choice->showunanswered || $optionid) { + $totalresponsecount += count($userlist); + } + } $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -493,20 +500,25 @@ function choice_show_results($choice, $course, $cm, $users, $forcepublish='') { if ($choice->showunanswered) { - echo ""; + echo ''; + if (!$choice->limitanswers) { + echo $column[0]; + echo '
('.format_float(((float)$column[0]/(float)$totalresponsecount)*100.0,1).'%)'; + } + echo ''; } $count = 1; foreach ($choice->option as $optionid => $optiontext) { echo ""; if ($choice->limitanswers) { echo get_string("taken", "choice").":"; - echo $column[$optionid]; - echo "
"; + echo $column[$optionid].'
'; echo get_string("limit", "choice").":"; $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } else { echo $column[$optionid]; + echo '
('.format_float(((float)$column[$optionid]/(float)$totalresponsecount)*100.0,1).'%)'; } echo ""; $count++; -- 2.39.5