Skip to content

Commit

Permalink
MDL-63973 core_badges: exclude related badges when adding related badges
Browse files Browse the repository at this point in the history
The form which allows a user to add related badges should exclude any
related badges, regardless of the direction of the relationship.
  • Loading branch information
snake committed Nov 19, 2018
1 parent c660772 commit 810da68
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions badges/related_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ public function get_badges_option($badge) {
$sql = "SELECT b.id, b.name, b.version, b.language, b.type
FROM {badge} b
WHERE b.id <> :badgeid
AND b.id NOT IN (SELECT br.relatedbadgeid
FROM {badge_related} br WHERE br.badgeid = :badgeid1)";
$params = array('badgeid' => $badge->id, 'badgeid1' => $badge->id);
AND b.id NOT IN (
SELECT DISTINCT b.id
FROM {badge_related} br
JOIN {badge} b ON (br.relatedbadgeid = b.id OR br.badgeid = b.id)
WHERE (br.badgeid = :badgeid2 OR br.relatedbadgeid = :badgeid3) AND b.id != :badgeid4)";
$params = ['badgeid' => $badge->id, 'badgeid2' => $badge->id, 'badgeid3' => $badge->id, 'badgeid4' => $badge->id];
if ($badge->type == BADGE_TYPE_COURSE) {
$sql .= " AND (b.courseid = :courseid OR b.type = :badgetype)";
$params['courseid'] = $badge->courseid;
Expand Down

0 comments on commit 810da68

Please sign in to comment.