diff --git a/badges/criteria/award_criteria_badge.php b/badges/criteria/award_criteria_badge.php index d9bd7957dc459..ebddecf818026 100644 --- a/badges/criteria/award_criteria_badge.php +++ b/badges/criteria/award_criteria_badge.php @@ -112,7 +112,7 @@ public function get_options(&$mform) { if ($this->id !== 0) { $selected = array_keys($this->params); } - $settings = array('multiple' => 'multiple', 'size' => 20, 'class' => 'selectbadge'); + $settings = array('multiple' => 'multiple', 'size' => 20, 'class' => 'selectbadge', 'required' => 'required'); $mform->addElement('select', 'badge_badges', get_string('addbadge', 'badges'), $select, $settings); $mform->addRule('badge_badges', get_string('requiredbadge', 'badges'), 'required'); $mform->addHelpButton('badge_badges', 'addbadge', 'badges'); @@ -243,7 +243,6 @@ public function get_completed_criteria_sql() { if ($this->method == BADGE_CRITERIA_AGGREGATION_ANY) { // User has received ANY of the required badges. $join = " LEFT JOIN {badge_issued} bi2 ON bi2.userid = u.id"; - $where = "AND ("; $i = 0; foreach ($this->params as $param) { if ($i == 0) { @@ -254,7 +253,10 @@ public function get_completed_criteria_sql() { $params['badgeid'.$i] = $param['badge']; $i++; } - $where .= ") "; + // MDL-66032 Do not create expression if there are no badges in criteria. + if (!empty($where)) { + $where = ' AND (' . $where . ') '; + } return array($join, $where, $params); } else { // User has received ALL of the required badges.