]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13478 performance fixes.
authordanmarsden <danmarsden>
Fri, 29 Feb 2008 11:53:38 +0000 (11:53 +0000)
committerdanmarsden <danmarsden>
Fri, 29 Feb 2008 11:53:38 +0000 (11:53 +0000)
mod/choice/lib.php

index 4d66f1063d7f261631ae23b8c310f690b12039dc..bd0b244153961122e2aa154cec1a106b53a95562 100644 (file)
@@ -304,15 +304,16 @@ function choice_show_reportlink($choice, $courseid, $cm, $groupmode) {
     }
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-    $availableusers = get_users_by_capability($context, 'mod/choice:choose', 'u.id', '','','',$currentgroup, '', true, true);
-
     $responsecount = 0;
 
-    if(!empty($availableusers)){
-        // flatten the users to get a list of userids
-        $userids = implode( ', ', array_keys($availableusers));
-        $responsecount = count_records_select('choice_answers', "choiceid = {$choice->id} AND userid IN ( $userids );");
-    }
+    $allresponses = get_records("choice_answers", "choiceid", $choice->id); //get all responses for this choice. 
+    $responsecount = 0; 
+    foreach ($allresponses as $usr) { 
+        if (has_capability('mod/choice:choose', $context, $usr->userid, false)) { //if this user is allowed to select a choice. 
+            $responsecount++; 
+        } 
+    } 
+
 
     echo '<div class="reportlink">';
     echo "<a href=\"report.php?id=$cm->id\">".get_string("viewallresponses", "choice", $responsecount)."</a>";