MDL-53893 core_badges: Add strictness to manual badge criteria
authorSimey Lameze <simey@moodle.com>
Wed, 31 Aug 2016 06:07:38 +0000 (14:07 +0800)
committerSimey Lameze <simey@moodle.com>
Fri, 9 Sep 2016 00:40:48 +0000 (08:40 +0800)
badges/criteria/award_criteria_manual.php

index fd0ad2e..51a7959 100644 (file)
@@ -207,12 +207,15 @@ class award_criteria_manual extends award_criteria {
             return array($join, $where, $params);
         } else {
             foreach ($this->params as $param) {
-                $join .= " LEFT JOIN {badge_manual_award} bma{$param['role']} ON
-                          bma{$param['role']}.recipientid = u.id AND
-                          bma{$param['role']}.issuerrole = :issuerrole{$param['role']} ";
-                $where .= " AND bma{$param['role']}.issuerrole IS NOT NULL ";
+                $roledata[] = " bma.issuerrole = :issuerrole{$param['role']} ";
                 $params["issuerrole{$param['role']}"] = $param['role'];
             }
+            if (!empty($roledata)) {
+                $extraon = implode(' AND ', $roledata);
+                $join = " JOIN {badge_manual_award} bma ON bma.recipientid = u.id
+                          AND bma.badgeid = :badgeid{$this->badgeid} AND ({$extraon})";
+                $params["badgeid{$this->badgeid}"] = $this->badgeid;
+            }
             return array($join, $where, $params);
         }
     }