Skip to content

Commit f417dab

Browse files
committed
Merge branch 'MDL-66032-MOODLE_37_STABLE_awarded_badges_criteria' of https://github.com/andrewmadden/moodle into MOODLE_37_STABLE
2 parents 334e44f + 191bcca commit f417dab

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

badges/criteria/award_criteria_badge.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function get_options(&$mform) {
112112
if ($this->id !== 0) {
113113
$selected = array_keys($this->params);
114114
}
115-
$settings = array('multiple' => 'multiple', 'size' => 20, 'class' => 'selectbadge');
115+
$settings = array('multiple' => 'multiple', 'size' => 20, 'class' => 'selectbadge', 'required' => 'required');
116116
$mform->addElement('select', 'badge_badges', get_string('addbadge', 'badges'), $select, $settings);
117117
$mform->addRule('badge_badges', get_string('requiredbadge', 'badges'), 'required');
118118
$mform->addHelpButton('badge_badges', 'addbadge', 'badges');
@@ -243,7 +243,6 @@ public function get_completed_criteria_sql() {
243243
if ($this->method == BADGE_CRITERIA_AGGREGATION_ANY) {
244244
// User has received ANY of the required badges.
245245
$join = " LEFT JOIN {badge_issued} bi2 ON bi2.userid = u.id";
246-
$where = "AND (";
247246
$i = 0;
248247
foreach ($this->params as $param) {
249248
if ($i == 0) {
@@ -254,7 +253,10 @@ public function get_completed_criteria_sql() {
254253
$params['badgeid'.$i] = $param['badge'];
255254
$i++;
256255
}
257-
$where .= ") ";
256+
// MDL-66032 Do not create expression if there are no badges in criteria.
257+
if (!empty($where)) {
258+
$where = ' AND (' . $where . ') ';
259+
}
258260
return array($join, $where, $params);
259261
} else {
260262
// User has received ALL of the required badges.

0 commit comments

Comments
 (0)