convert old dml syntax in the new one in feedback_get_recent_mod_activity()
authorAndreas Grabs <info@grabs-edv.de>
Fri, 2 Apr 2010 22:09:00 +0000 (22:09 +0000)
committerAndreas Grabs <info@grabs-edv.de>
Fri, 2 Apr 2010 22:09:00 +0000 (22:09 +0000)
mod/feedback/lib.php

index 1f1587a..3f1b0b0 100644 (file)
@@ -231,32 +231,35 @@ function feedback_get_recent_mod_activity(&$activities, &$index, $timemodified,
     $modinfo =& get_fast_modinfo($course);
 
     $cm = $modinfo->cms[$cmid];
+    
+    $sqlargs = array();
 
-    if ($userid) {
-        $userselect = "AND u.id = $userid";
-    } else {
-        $userselect = "";
-    }
+    $sql = " SELECT fk . * , fc . * , u.firstname, u.lastname, u.email, u.picture
+                                            FROM {feedback_completed} fc
+                                                JOIN {feedback} fk ON fk.id = fc.feedback
+                                                JOIN {user} u ON u.id = fc.userid ";
 
     if ($groupid) {
-        $groupselect = "AND gm.groupid = $groupid";
-        $groupjoin   = "JOIN {groups_members} gm ON  gm.userid=u.id";
-    } else {
-        $groupselect = "";
-        $groupjoin   = "";
+        $sql .= " JOIN {groups_members} gm ON  gm.userid=u.id ";
     }
+    
+    $sql .= " WHERE fc.timemodified > ? AND fk.id = ? ";
+    $sqlargs[] = $timemodified;
+    $sqlargs[] = $cm->instace;
 
-    if (!$feedbackitems = $DB->get_records_sql("SELECT fk . * , fc . * , u.firstname, u.lastname, u.email, u.picture
-                                            FROM {feedback_completed} fc
-                                                JOIN {feedback} fk ON fk.id = fc.feedback
-                                                JOIN {user} u ON u.id = fc.userid
-                                                $groupjoin
-                                            WHERE fc.timemodified > $timemodified AND fk.id = $cm->instance
-                                                $userselect $groupselect
-                                            ORDER BY fc.timemodified DESC")) {
-         return;
+    if ($userid) {
+        $sql .= " AND u.id = ? ";
+        $sqlargs[] = $userid;
     }
 
+    if ($groupid) {
+        $sql .= " AND gm.groupid = ? ";
+        $sqlargs[] = $groupid;
+    }
+    
+    if (!$feedbackitems = $DB->get_records_sql($sql, $sqlargs)) {
+        return;
+    }
 
     $cm_context      = get_context_instance(CONTEXT_MODULE, $cm->id);
     $accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);