MDL-69002 core_badges: performance update to set default sitebackpack
[moodle.git] / admin / settings / badges.php
CommitLineData
27806552
YB
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19* This file defines settingpages and externalpages under the "badges" section
20*
21* @package core
22* @subpackage badges
23* @copyright 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
24* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
26*/
27
28global $SITE;
27806552 29
f2770bfe 30if (($hassiteconfig || has_any_capability(array(
27806552
YB
31 'moodle/badges:viewawarded',
32 'moodle/badges:createbadge',
33 'moodle/badges:manageglobalsettings',
34 'moodle/badges:awardbadge',
a72c2cd6 35 'moodle/badges:configurecriteria',
27806552
YB
36 'moodle/badges:configuremessages',
37 'moodle/badges:configuredetails',
38 'moodle/badges:deletebadge'), $systemcontext))) {
39
2188a697
DW
40 require_once($CFG->libdir . '/badgeslib.php');
41
27806552 42 $globalsettings = new admin_settingpage('badgesettings', new lang_string('badgesettings', 'badges'),
f2770bfe 43 array('moodle/badges:manageglobalsettings'), empty($CFG->enablebadges));
27806552
YB
44
45 $globalsettings->add(new admin_setting_configtext('badges_defaultissuername',
46 new lang_string('defaultissuername', 'badges'),
47 new lang_string('defaultissuername_desc', 'badges'),
48 $SITE->fullname ? $SITE->fullname : $SITE->shortname, PARAM_TEXT));
49
50 $globalsettings->add(new admin_setting_configtext('badges_defaultissuercontact',
51 new lang_string('defaultissuercontact', 'badges'),
52 new lang_string('defaultissuercontact_desc', 'badges'),
53 get_config('moodle','supportemail'), PARAM_EMAIL));
54
55 $globalsettings->add(new admin_setting_configtext('badges_badgesalt',
56 new lang_string('badgesalt', 'badges'),
57 new lang_string('badgesalt_desc', 'badges'),
58 'badges' . $SITE->timecreated, PARAM_ALPHANUM));
59
aae219ac
DW
60 $backpacks = badges_get_site_backpacks();
61 $choices = array();
5c0d795b 62 $defaultchoice = 0;
aae219ac
DW
63 foreach ($backpacks as $backpack) {
64 $choices[$backpack->id] = $backpack->backpackweburl;
5c0d795b
PD
65 if ($backpack->backpackweburl == BADGRIO_BACKPACKWEBURL) {
66 $defaultchoice = $backpack->id;
67 }
aae219ac 68 }
27806552
YB
69
70 $globalsettings->add(new admin_setting_configcheckbox('badges_allowcoursebadges',
71 new lang_string('allowcoursebadges', 'badges'),
72 new lang_string('allowcoursebadges_desc', 'badges'), 1));
73
74 $ADMIN->add('badges', $globalsettings);
75
76 $ADMIN->add('badges',
77 new admin_externalpage('managebadges',
78 new lang_string('managebadges', 'badges'),
f2770bfe 79 new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE)),
e2805314
YB
80 array(
81 'moodle/badges:viewawarded',
82 'moodle/badges:createbadge',
83 'moodle/badges:awardbadge',
a72c2cd6 84 'moodle/badges:configurecriteria',
e2805314
YB
85 'moodle/badges:configuremessages',
86 'moodle/badges:configuredetails',
87 'moodle/badges:deletebadge'
19226a30
DP
88 ),
89 empty($CFG->enablebadges)
27806552
YB
90 )
91 );
92
93 $ADMIN->add('badges',
94 new admin_externalpage('newbadge',
95 new lang_string('newbadge', 'badges'),
f2770bfe
PS
96 new moodle_url('/badges/newbadge.php', array('type' => BADGE_TYPE_SITE)),
97 array('moodle/badges:createbadge'), empty($CFG->enablebadges)
27806552
YB
98 )
99 );
aae219ac
DW
100 $backpacksettings = new admin_settingpage('backpacksettings', new lang_string('backpacksettings', 'badges'),
101 array('moodle/badges:manageglobalsettings'), empty($CFG->enablebadges));
102
103 $backpacksettings->add(new admin_setting_configcheckbox('badges_allowexternalbackpack',
104 new lang_string('allowexternalbackpack', 'badges'),
105 new lang_string('allowexternalbackpack_desc', 'badges'), 1));
106
107 $backpacksettings->add(new admin_setting_configselect('badges_site_backpack',
108 new lang_string('sitebackpack', 'badges'),
109 new lang_string('sitebackpack_help', 'badges'),
5c0d795b 110 $defaultchoice, $choices));
aae219ac
DW
111
112 $ADMIN->add('badges', $backpacksettings);
113
114 $ADMIN->add('badges',
115 new admin_externalpage('managebackpacks',
116 new lang_string('managebackpacks', 'badges'),
117 new moodle_url('/badges/backpacks.php'),
118 array('moodle/badges:manageglobalsettings'), empty($CFG->enablebadges) || empty($CFG->badges_allowexternalbackpack)
119 )
120 );
27806552 121}