MDL-69002 core_badges: performance update to set default sitebackpack
[moodle.git] / admin / settings / badges.php
index b1671b4..a97097f 100644 (file)
@@ -59,8 +59,12 @@ if (($hassiteconfig || has_any_capability(array(
 
     $backpacks = badges_get_site_backpacks();
     $choices = array();
+    $defaultchoice = 0;
     foreach ($backpacks as $backpack) {
         $choices[$backpack->id] = $backpack->backpackweburl;
+        if ($backpack->backpackweburl == BADGRIO_BACKPACKWEBURL) {
+            $defaultchoice = $backpack->id;
+        }
     }
 
     $globalsettings->add(new admin_setting_configcheckbox('badges_allowcoursebadges',
@@ -100,11 +104,10 @@ if (($hassiteconfig || has_any_capability(array(
             new lang_string('allowexternalbackpack', 'badges'),
             new lang_string('allowexternalbackpack_desc', 'badges'), 1));
 
-    $bp = $DB->get_record('badge_external_backpack', ['backpackweburl' => BADGRIO_BACKPACKWEBURL]);
     $backpacksettings->add(new admin_setting_configselect('badges_site_backpack',
             new lang_string('sitebackpack', 'badges'),
             new lang_string('sitebackpack_help', 'badges'),
-            $bp->id, $choices));
+            $defaultchoice, $choices));
 
     $ADMIN->add('badges', $backpacksettings);