Index: report.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/choice/report.php,v retrieving revision 1.60.2.1 diff -u -r1.60.2.1 report.php --- report.php 12 Oct 2007 16:09:45 -0000 1.60.2.1 +++ report.php 1 Mar 2008 10:27:09 -0000 @@ -50,51 +50,57 @@ } else { $groupmode = groups_get_activity_groupmode($cm); groups_get_activity_group($cm, true); - } - $users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC'); + + $allresponses = get_records("choice_answers", "choiceid", $choice->id); //get all responses for this choice. + + foreach ($allresponses as $usr) { + if (has_capability('mod/choice:choose', $context, $usr->userid, false)) { //if this user is allowed to select a choice. + $users[$usr->userid] = get_record_sql('SELECT id, picture, firstname, lastname, idnumber FROM '. $CFG->prefix .'user WHERE id= '.$usr->userid); + } + } - if (!empty($CFG->enablegroupings) && !empty($cm->groupingid) && !empty($users)) { - $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); - foreach($users as $key => $user) { - if (!isset($groupingusers[$user->id])) { - unset($users[$key]); + if (!empty($CFG->enablegroupings) && !empty($cm->groupingid) && !empty($users)) { + $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); + foreach($users as $key => $user) { + if (!isset($groupingusers[$user->id])) { + unset($users[$key]); + } } } - } - if (!$users) { - print_heading(get_string("nousersyet")); - } + if (!$users) { + print_heading(get_string("nousersyet")); + } - if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) { - foreach ($allresponses as $aa) { - $answers[$aa->userid] = $aa; + if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) { + foreach ($allresponses as $aa) { + $answers[$aa->userid] = $aa; + } + } else { + $answers = array () ; } - } else { - $answers = array () ; - } - $timenow = time(); + $timenow = time(); - foreach ($choice->option as $optionid => $text) { - $useranswer[$optionid] = array(); - } - foreach ($users as $user) { - if (!empty($user->id) and !empty($answers[$user->id])) { - $answer = $answers[$user->id]; - $useranswer[(int)$answer->optionid][] = $user; - } else { - $useranswer[0][] = $user; + foreach ($choice->option as $optionid => $text) { + $useranswer[$optionid] = array(); } - } - foreach ($choice->option as $optionid => $text) { - if (!$choice->option[$optionid]) { - unset($useranswer[$optionid]); // Throw away any data that doesn't apply + foreach ($users as $user) { + if (!empty($user->id) and !empty($answers[$user->id])) { + $answer = $answers[$user->id]; + $useranswer[(int)$answer->optionid][] = $user; + } else { + $useranswer[0][] = $user; + } + } + foreach ($choice->option as $optionid => $text) { + if (!$choice->option[$optionid]) { + unset($useranswer[$optionid]); // Throw away any data that doesn't apply + } } + ksort($useranswer); } - ksort($useranswer); - if ($download == "ods" && has_capability('mod/choice:downloadresponses', $context)) { require_once("$CFG->libdir/odslib.class.php");