Index: lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/choice/lib.php,v retrieving revision 1.59.2.11 diff -u -r1.59.2.11 lib.php --- lib.php 18 Jan 2008 00:31:37 -0000 1.59.2.11 +++ lib.php 17 Feb 2008 23:56:28 -0000 @@ -338,10 +338,18 @@ $currentgroup = 0; } - $users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', true, true); - - $allusersnothidden = get_users_by_capability($context, 'mod/choice:choose', 'u.id', 'u.firstname ASC', '', '', $currentgroup, '', true, false); ///MDL-12331 ugly hack to prevent hidden users from being displayed in the unanswered column. needs fixing! - + $allresponses = get_records("choice_answers", "choiceid", $choice->id); + + if ($choice->showunanswered) { + $users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', true, true); + $allusersnothidden = get_users_by_capability($context, 'mod/choice:choose', 'u.id', 'u.firstname ASC', '', '', $currentgroup, '', true, false); ///MDL-12331 ugly hack to prevent hidden users from being displayed in the unanswered column. needs fixing! + } else { + 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) { @@ -356,7 +364,7 @@ } $answers = array () ; - if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) { + if (!empty($allresponses)) { foreach ($allresponses as $aa) { //TODO: rewrite with SQL if ($groupmode and $currentgroup) { @@ -436,9 +444,8 @@ // MDL-7861 echo ""; foreach ($userlist as $user) { - if ($optionid!=0 or has_capability('mod/choice:choose', $context, $user->id, false) AND //only get enrolled users that have access - !($optionid==0 AND has_capability('moodle/site:doanything', $context, $user->id, false)) AND //remove doanything users - !($optionid==0 AND isset($allusersnothidden[$user->id]))) { //MDL-12331 ugly hack part 2 + if (!($optionid==0 AND has_capability('moodle/site:doanything', $context, $user->id, false)) AND //remove doanything users + !($optionid==0 AND isset($allusersnothidden[$user->id]))) { //MDL-12331 ugly hack part 2 $columncount[$optionid] += 1; echo ""; @@ -531,9 +538,8 @@ } $column[$optionid] = 0; foreach ($userlist as $user) { - if ($optionid!=0 or has_capability('mod/choice:choose', $context, $user->id, false) AND //only get enrolled users that have access - !($optionid==0 AND has_capability('moodle/site:doanything', $context, $user->id, false)) AND //remove doanything users - !($optionid==0 AND isset($allusersnothidden[$user->id]))) { //MDL-12331 ugly hack part 2 + if (!($optionid==0 AND has_capability('moodle/site:doanything', $context, $user->id, false)) AND //remove doanything users + !($optionid==0 AND isset($allusersnothidden[$user->id]))) { //MDL-12331 ugly hack part 2 $column[$optionid]++; }