MDL-63973 core_badges: fix related badges count in the badges tabs
authorJake Dallimore <jake@moodle.com>
Mon, 19 Nov 2018 03:06:15 +0000 (11:06 +0800)
committerJake Dallimore <jake@moodle.com>
Mon, 19 Nov 2018 03:10:14 +0000 (11:10 +0800)
If A is related to B, this should show a 1 count for either A or B.

badges/renderer.php

index 307675d..c11fd76 100644 (file)
@@ -722,8 +722,10 @@ class core_badges_renderer extends plugin_renderer_base {
         }
 
         if (has_capability('moodle/badges:configuredetails', $context)) {
-            $related = $DB->count_records_sql("SELECT COUNT(br.badgeid)
-                      FROM {badge_related} br WHERE br.badgeid = :badgeid", array('badgeid' => $badgeid));
+            $sql = "SELECT COUNT(br.badgeid)
+                      FROM {badge_related} br
+                     WHERE (br.badgeid = :badgeid OR br.relatedbadgeid = :badgeid2)";
+            $related = $DB->count_records_sql($sql, ['badgeid' => $badgeid, 'badgeid2' => $badgeid]);
             $row[] = new tabobject('brelated',
                 new moodle_url('/badges/related.php', array('id' => $badgeid)),
                 get_string('brelated', 'badges', $related)
@@ -1502,4 +1504,4 @@ class badge_competencies_alignment implements renderable
         $this->alignments = $alignments;
         $this->currentbadgeid = $currentbadgeid;
     }
-}
\ No newline at end of file
+}