From 4221e36b160c70b478ee244380b92338edb7cc85 Mon Sep 17 00:00:00 2001 From: Sara Arjona <sara@moodle.com> Date: Wed, 29 May 2019 15:09:39 +0200 Subject: [PATCH] MDL-65787 badges: fix warning count() with PHP 7.2 --- badges/classes/form/collections.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/badges/classes/form/collections.php b/badges/classes/form/collections.php index 6f221b79e0a..5a57ba2b426 100644 --- a/badges/classes/form/collections.php +++ b/badges/classes/form/collections.php @@ -79,24 +79,25 @@ class collections extends moodleform { $hasgroups = false; if (!empty($groups)) { foreach ($groups as $group) { - // Assertions or badges. $count = 0; - + // Handle attributes based on backpack's supported version. if ($sitebackpack->apiversion == OPEN_BADGES_V2) { + // OpenBadges v2 data attributes. if (empty($group->published)) { // Only public collections. continue; } - } - if (!empty($group->assertions)) { + + // Get the number of badges associated with this collection from the assertions array returned. $count = count($group->assertions); - } - if (!empty($group->badges)) { - $count = count($group->badges); - } - if (!empty($group->groupId)) { + } else { + // OpenBadges v1 data attributes. $group->entityId = $group->groupId; + + // Get the number of badges associated with this collection. In that case, the number is returned directly. + $count = $group->badges; } + if (!$hasgroups) { $mform->addElement('static', 'selectgroup', '', get_string('selectgroup_start', 'badges')); }