]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13158 choice/index.php only return values for choices in the current course....
authorskodak <skodak>
Tue, 26 Feb 2008 23:19:58 +0000 (23:19 +0000)
committerskodak <skodak>
Tue, 26 Feb 2008 23:19:58 +0000 (23:19 +0000)
mod/choice/index.php

index f60fda7b4d40c3275979f81b3afb51bf68a8a0ea..2b5cdead0b7014d75537d71a1ccc2190756bccb1 100644 (file)
         notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id=$course->id");
     }
 
-    if ( !empty($USER->id) and $allanswers = get_records("choice_answers", "userid", $USER->id)) { // TODO: limit to choices from this course only
+    $sql = "SELECT cha.*
+              FROM {$CFG->prefix}choice ch, {$CFG->prefix}choice_answers cha
+             WHERE cha.choiceid = ch.id AND
+                   ch.course = $course->id AND cha.userid = $USER->id";
+
+    $answers = array () ;
+    if (isloggedin() and !isguestuser() and $allanswers = get_records_sql($sql)) {
         foreach ($allanswers as $aa) {
             $answers[$aa->choiceid] = $aa;
         }
-
-    } else {
-        $answers = array () ;
+        unset($allanswers);
     }