Merge branch 'MDL-61951-master' of git://github.com/sarjona/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 11 May 2018 11:21:58 +0000 (13:21 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 11 May 2018 11:21:58 +0000 (13:21 +0200)
1  2 
grade/grading/classes/privacy/provider.php

@@@ -93,9 -93,9 +93,9 @@@ class provider implement
                    FROM {context} c
                    JOIN {grading_areas} a ON a.contextid = c.id
                    JOIN {grading_definitions} d ON d.areaid = a.id
 -             LEFT JOIN {grading_instances} i ON i.definitionid = d.id
 +             LEFT JOIN {grading_instances} i ON i.definitionid = d.id AND i.raterid = :raterid
                   WHERE c.contextlevel = :contextlevel
 -                   AND (d.usercreated = :usercreated OR d.usermodified = :usermodified OR i.raterid = :raterid)";
 +                   AND (d.usercreated = :usercreated OR d.usermodified = :usermodified OR i.id IS NOT NULL)";
          $params = [
              'usercreated' => $userid,
              'usermodified' => $userid,
          ];
  
          if (!empty($userid)) {
 -            $join .= ' LEFT JOIN {grading_instances} i ON i.definitionid = d.id';
 +            $join .= ' LEFT JOIN {grading_instances} i ON i.definitionid = d.id AND i.raterid = :raterid';
              $select .= ' AND (usercreated = :usercreated
 -                OR usermodified = :usermodified OR i.raterid = :raterid)';
 +                OR usermodified = :usermodified OR i.id IS NOT NULL)';
              $params['usercreated'] = $userid;
              $params['usermodified'] = $userid;
              $params['raterid'] = $userid;
          }
  
-         $sql = "SELECT DISTINCT d.id,
-                                 d.method,
-                                 d.name,
-                                 d.description,
-                                 d.timecopied,
-                                 d.timecreated,
-                                 d.usercreated,
-                                 d.timemodified,
-                                 d.usermodified
-                            FROM {grading_definitions} d
-                            $join
-                            WHERE $select";
+         $sql = "SELECT gd.id,
+                        gd.method,
+                        gd.name,
+                        gd.description,
+                        gd.timecopied,
+                        gd.timecreated,
+                        gd.usercreated,
+                        gd.timemodified,
+                        gd.usermodified
+                   FROM (
+                         SELECT DISTINCT d.id
+                                    FROM {grading_definitions} d
+                                   $join
+                                   WHERE $select
+                   ) ids
+                   JOIN {grading_definitions} gd ON gd.id = ids.id";
          $definitions = $DB->get_recordset_sql($sql, $params);
          $defdata = [];
          foreach ($definitions as $definition) {