Index: lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/choice/lib.php,v retrieving revision 1.59.2.7 diff -c -r1.59.2.7 lib.php *** lib.php 11 Dec 2007 18:49:44 -0000 1.59.2.7 --- lib.php 13 Dec 2007 23:23:19 -0000 *************** *** 129,149 **** // ->full - whether this option is full or not. 0=not full, 1=full $cdisplay = array(); $aid = 0; foreach ($choice->option as $optionid => $text) { if (isset($text)) { //make sure there are no dud entries in the db with blank text values. $countanswers = (get_records("choice_answers", "optionid", $optionid)); $countans = 0; - $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!empty($countanswers)) { foreach ($countanswers as $ca) { //only return enrolled users. if (has_capability('mod/choice:choose', $context, $ca->userid, false)) { ! $countans = $countans+1; } } ! } ! if ($countanswers) { ! $countanswers = count($countanswers); } else { $countanswers = 0; } --- 129,157 ---- // ->full - whether this option is full or not. 0=not full, 1=full $cdisplay = array(); + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $groupmode = groups_get_activity_groupmode($cm); + $currentgroup = 0; + if ($groupmode > 0) { + $currentgroup = get_current_group($cm->course); + } + $aid = 0; foreach ($choice->option as $optionid => $text) { if (isset($text)) { //make sure there are no dud entries in the db with blank text values. $countanswers = (get_records("choice_answers", "optionid", $optionid)); $countans = 0; if (!empty($countanswers)) { foreach ($countanswers as $ca) { //only return enrolled users. if (has_capability('mod/choice:choose', $context, $ca->userid, false)) { ! if ($groupmode==SEPARATEGROUPS && $currentgroup && !groups_is_member($currentgroup, $ca->userid)) { ! // MDL-11850 (do not count choices from other separate groups) ! } else { ! $countans = $countans+1; ! } } } ! $countanswers = $countans; } else { $countanswers = 0; } *************** *** 240,253 **** $current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $userid); $context = get_context_instance(CONTEXT_MODULE, $cm->id); $countanswers = get_records("choice_answers", "optionid", $formanswer); if ($countanswers) { $countans = 0; foreach ($countanswers as $ca) { //only return enrolled users. if (has_capability('mod/choice:choose', $context, $ca->userid, false)) { ! $countans = $countans+1; } } - $countanswers = $countans; } else { $countanswers = 0; --- 248,269 ---- $current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $userid); $context = get_context_instance(CONTEXT_MODULE, $cm->id); $countanswers = get_records("choice_answers", "optionid", $formanswer); + $currentgroup = 0; + $groupmode = groups_get_activity_groupmode($cm); + if ($groupmode > 0) { + $currentgroup = get_current_group($courseid); + } if ($countanswers) { $countans = 0; foreach ($countanswers as $ca) { //only return enrolled users. if (has_capability('mod/choice:choose', $context, $ca->userid, false)) { ! if ($groupmode==SEPARATEGROUPS && $currentgroup && !groups_is_member($currentgroup, $ca->userid)) { ! // MDL-11850 (do not count choices from other separate groups) ! } else { ! $countans = $countans+1; ! } } } $countanswers = $countans; } else { $countanswers = 0; *************** *** 283,301 **** } ! function choice_show_reportlink($choice, $courseid, $cmid, $groupmode) { //TODO: rewrite with SQL ! $currentgroup = get_current_group($courseid); if ($allanswers = get_records("choice_answers", "choiceid", $choice->id)) { $responsecount = 0; foreach ($allanswers as $aa) { - $context = get_context_instance(CONTEXT_MODULE, $cmid); if (has_capability('mod/choice:choose', $context, $aa->userid, false)) { //check to make sure user is enrolled/has this capability. ! if ($groupmode and $currentgroup) { if (groups_is_member($currentgroup, $aa->userid)) { $responsecount++; } } else { $responsecount++; } } --- 299,321 ---- } ! function choice_show_reportlink($choice, $courseid, $cmid, $groupmode, $currentgroup) { //TODO: rewrite with SQL ! $context = get_context_instance(CONTEXT_MODULE, $cmid); if ($allanswers = get_records("choice_answers", "choiceid", $choice->id)) { $responsecount = 0; foreach ($allanswers as $aa) { if (has_capability('mod/choice:choose', $context, $aa->userid, false)) { //check to make sure user is enrolled/has this capability. ! if ($groupmode == NOGROUPS) { ! // no groups are used - count all responses ! $responsecount++; ! } elseif ($currentgroup) { ! // groups are used and one of them is selected if (groups_is_member($currentgroup, $aa->userid)) { $responsecount++; } } else { + // groups are used but none of them is selected ("All participants") $responsecount++; } } *************** *** 327,333 **** $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, '', false, true); if (!empty($CFG->enablegroupings) && !empty($cm->groupingid) && !empty($users)) { $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); --- 347,353 ---- $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); // see MDL-12331 if (!empty($CFG->enablegroupings) && !empty($cm->groupingid) && !empty($users)) { $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); Index: view.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/choice/view.php,v retrieving revision 1.102.2.2 diff -c -r1.102.2.2 view.php *** view.php 22 Oct 2007 21:26:16 -0000 1.102.2.2 --- view.php 13 Dec 2007 23:23:19 -0000 *************** *** 66,76 **** /// Check to see if groups are being used in this choice $groupmode = groups_get_activity_groupmode($cm); ! groups_get_activity_group($cm, true); groups_print_activity_menu($cm, 'view.php?id='.$id); if (has_capability('mod/choice:readresponses', $context)) { ! choice_show_reportlink($choice, $course->id, $cm->id, $groupmode); } echo '
'; --- 66,76 ---- /// Check to see if groups are being used in this choice $groupmode = groups_get_activity_groupmode($cm); ! $currentgroup = groups_get_activity_group($cm, true); groups_print_activity_menu($cm, 'view.php?id='.$id); if (has_capability('mod/choice:readresponses', $context)) { ! choice_show_reportlink($choice, $course->id, $cm->id, $groupmode, $currentgroup); } echo '';