From: moodler Date: Mon, 3 Mar 2008 05:12:22 +0000 (+0000) Subject: Merged MDL-13753 to add percentages X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c2a4d0169bad30c864e76c958405ec42954a2ab7;p=moodle.git Merged MDL-13753 to add percentages --- 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++;