Report works

This commit is contained in:
moodler
2005-03-30 18:17:58 +00:00
parent 375ed3ddc6
commit bfe97ca600
+112 -39
View File
@@ -5,6 +5,8 @@
require_variable($id); // course module
$format = optional_param('format', CHOICE_PUBLISH_NAMES, PARAM_INT);
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
@@ -41,9 +43,9 @@
}
if ($currentgroup) {
$users = get_group_users($currentgroup, "u.firstname ASC");
$users = get_group_users($currentgroup, "u.firstname ASC", '', 'u.id, u.picture, u.firstname, u.lastname');
} else {
$users = get_course_users($course->id, "u.firstname ASC");
$users = get_course_users($course->id, "u.firstname ASC", '', 'u.id, u.picture, u.firstname, u.lastname');
}
if (!$users) {
@@ -52,7 +54,7 @@
exit;
}
if ( $allresponses = get_records("choice_responses", "choice", $choice->id)) {
if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) {
foreach ($allresponses as $aa) {
$answers[$aa->userid] = $aa;
}
@@ -62,55 +64,126 @@
$timenow = time();
foreach ($choice->answer as $key => $answer) {
$useranswer[$key] = array();
foreach ($choice->option as $optionid => $text) {
$useranswer[$optionid] = array();
}
foreach ($users as $user) {
if (!empty($answers[$user->id])) {
if (!empty($user->id) and !empty($answers[$user->id])) {
$answer = $answers[$user->id];
$useranswer[(int)$answer->optionid][] = $user;
} else {
$answer->answerid = 0;
$useranswer[0][] = $user;
}
$useranswer[(int)$answer->answerid][] = $user;
}
foreach ($choice->answer as $key => $answer) {
if (!$choice->answer[$key]) {
unset($useranswer[$key]); // Throw away any data that doesn't apply
foreach ($choice->option as $optionid => $text) {
if (!$choice->option[$optionid]) {
unset($useranswer[$optionid]); // Throw away any data that doesn't apply
}
}
ksort($useranswer);
$tablewidth = (int) (100.0 / count($useranswer));
switch ($format) {
case CHOICE_PUBLISH_NAMES:
echo "<table cellpadding=\"5\" cellspacing=\"10\" align=\"center\">";
echo "<tr>";
foreach ($useranswer as $key => $answer) {
echo "<th class=\"col$key\" width=\"$tablewidth%\">";
echo format_string(choice_get_answer($choice, $key));
echo "</th>";
$tablewidth = (int) (100.0 / count($useranswer));
echo "<table cellpadding=\"5\" cellspacing=\"10\" align=\"center\">";
echo "<tr>";
foreach ($useranswer as $optionid => $userlist) {
if ($optionid) {
echo "<th class=\"col$optionid\" width=\"$tablewidth%\">";
} else if ($choice->showunanswered) {
echo "<th class=\"col$optionid\" width=\"$tablewidth%\">";
} else {
continue;
}
echo format_string(choice_get_option_text($choice, $optionid));
echo "</th>";
}
echo "</tr><tr>";
foreach ($useranswer as $optionid => $userlist) {
if ($optionid) {
echo "<td class=\"col$optionid\" width=\"$tablewidth%\" valign=\"top\" nowrap=\"nowrap\">";
} else if ($choice->showunanswered) {
echo "<td class=\"col$optionid\" width=\"$tablewidth%\" valign=\"top\" nowrap=\"nowrap\">";
} else {
continue;
}
echo "<table width=\"100%\">";
foreach ($userlist as $user) {
echo "<tr><td width=\"10\" nowrap=\"nowrap\">";
print_user_picture($user->id, $course->id, $user->picture);
echo "</td><td width=\"100%\" nowrap=\"nowrap\">";
echo "<p>".fullname($user, true)."</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 $optionid => $userlist) {
if ($optionid) {
echo "<th width=\"$tablewidth%\">";
} else if ($choice->showunanswered) {
echo "<th width=\"$tablewidth%\">";
} else {
continue;
}
echo choice_get_option_text($choice, $optionid);
echo "</th>";
}
echo "</tr>";
$maxcolumn = 0;
foreach ($useranswer as $optionid => $userlist) {
if (!$optionid and !$choice->showunanswered) {
continue;
}
$column[$optionid] = count($userlist);
if ($column[$optionid] > $maxcolumn) {
$maxcolumn = $column[$optionid];
}
}
echo "<tr>";
foreach ($useranswer as $optionid => $userlist) {
if (!$optionid and !$choice->showunanswered) {
continue;
}
$height = 0;
if ($maxcolumn) {
$height = $COLUMN_HEIGHT * ((float)$column[$optionid] / (float)$maxcolumn);
}
echo "<td valign=\"bottom\" align=\"center\">";
echo "<img src=\"column.png\" height=\"$height\" width=\"49\" alt=\"\" />";
echo "</td>";
}
echo "</tr>";
echo "<tr>";
foreach ($useranswer as $optionid => $userlist) {
if (!$optionid and !$choice->showunanswered) {
continue;
}
echo "<td align=\"center\">".$column[$optionid]."</td>";
}
echo "</tr></table>";
break;
}
echo "</tr><tr>";
foreach ($useranswer as $key => $answer) {
echo "<td class=\"col$key\" width=\"$tablewidth%\" valign=\"top\" nowrap=\"nowrap\">";
echo "<table width=\"100%\">";
foreach ($answer as $user) {
echo "<tr><td width=\"10\" nowrap=\"nowrap\">";
print_user_picture($user->id, $course->id, $user->picture);
echo "</td><td width=\"100%\" nowrap=\"nowrap\">";
echo "<p>".fullname($user, true)."</p>";
echo "</td></tr>";
}
echo "<tr><td colspan=\"2\">&nbsp;</td></tr>"; /// need to have at least one row within table tags
echo "</table>";
echo "</td>";
}
echo "</tr></table>";
print_footer($course);
print_footer($course);
?>