]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12890 - differing values for number of choice responses link to what is
authorpoltawski <poltawski>
Thu, 10 Jan 2008 14:08:19 +0000 (14:08 +0000)
committerpoltawski <poltawski>
Thu, 10 Jan 2008 14:08:19 +0000 (14:08 +0000)
displayed
merged from MOODLE_19_STABLE

mod/choice/lib.php
mod/choice/view.php

index 24e9f1fa70fdc9b691dbdb1548cf1ee64ae6c015..09d7ad5a3513f9ee512eb3737612a94ee5811103 100644 (file)
@@ -283,28 +283,27 @@ function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $
 }
 
 
-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++;
-                }
-            }
-        }
+function choice_show_reportlink($choice, $courseid, $cm, $groupmode) {
+
+    if ($groupmode > 0) {
+        $currentgroup = groups_get_activity_group($cm);
     } else {
-        $responsecount = 0;
+        $currentgroup = 0;
     }
+
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    $availableusers = get_users_by_capability($context, 'mod/choice:choose', 'u.id', '','','',$currentgroup, '', false, 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 );");
+    }
+
     echo '<div class="reportlink">';
-    echo "<a href=\"report.php?id=$cmid\">".get_string("viewallresponses", "choice", $responsecount)."</a>";
+    echo "<a href=\"report.php?id=$cm->id\">".get_string("viewallresponses", "choice", $responsecount)."</a>";
     echo '</div>';
 }
 
index f2da1b3382aaf83d0fee78fd2aff9f47d1abb4d2..bafd2773eb2c4ec0d48aff1cc1c61480aa7c51ae 100644 (file)
@@ -70,7 +70,7 @@ if ($action == 'delchoice') {
     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);
+        choice_show_reportlink($choice, $course->id, $cm, $groupmode);
     }
 
     echo '<div class="clearer"></div>';