on-demand release 3.8dev+
[moodle.git] / badges / classes / form / external_backpack.php
blob7b7d6534da3a4561db91a56a51d4afffb8ddd28a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * External backpack form
20 * @package core_badges
21 * @copyright 2019 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_badges\form;
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir.'/formslib.php');
30 /**
31 * Backpack form class.
33 * @package core_badges
34 * @copyright 2019 Damyon Wiese
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class external_backpack extends \moodleform {
39 /**
40 * Create the form.
43 public function definition() {
44 global $CFG;
46 $mform = $this->_form;
47 $backpack = false;
49 if (isset($this->_customdata['externalbackpack'])) {
50 $backpack = $this->_customdata['externalbackpack'];
51 } else {
52 throw new \coding_exception('backpack is required.');
55 $url = $backpack->backpackapiurl;
57 $mform->addElement('static', 'backpackapiurlinfo', get_string('backpackapiurl', 'core_badges'), $url);
59 $mform->addElement('hidden', 'backpackapiurl', $url);
60 $mform->setType('backpackapiurl', PARAM_URL);
62 $url = $backpack->backpackweburl;
63 $mform->addElement('static', 'backpackweburlinfo', get_string('backpackweburl', 'core_badges'), $url);
64 $mform->addElement('hidden', 'backpackweburl', $url);
65 $mform->setType('backpackweburl', PARAM_URL);
67 $options = badges_get_badge_api_versions();
68 $label = $options[$backpack->apiversion];
69 $mform->addElement('static', 'apiversioninfo', get_string('apiversion', 'core_badges'), $label);
70 $mform->addElement('hidden', 'apiversion', $backpack->apiversion);
71 $mform->setType('apiversion', PARAM_INTEGER);
73 $mform->addElement('hidden', 'id', $backpack->id);
74 $mform->setType('id', PARAM_INTEGER);
76 $mform->addElement('hidden', 'action', 'edit');
77 $mform->setType('action', PARAM_ALPHA);
79 $issuername = $CFG->badges_defaultissuername;
80 $mform->addElement('static', 'issuerinfo', get_string('defaultissuername', 'core_badges'), $issuername);
82 $issuercontact = $CFG->badges_defaultissuercontact;
83 $mform->addElement('static', 'issuerinfo', get_string('defaultissuercontact', 'core_badges'), $issuercontact);
85 $mform->addElement('passwordunmask', 'password', get_string('defaultissuerpassword', 'core_badges'));
86 $mform->setType('password', PARAM_RAW);
87 $mform->addHelpButton('password', 'defaultissuerpassword', 'badges');
88 $mform->hideIf('password', 'apiversion', 'eq', 1);
90 $this->set_data($backpack);
92 // Disable short forms.
93 $mform->setDisableShortforms();
95 $this->add_action_buttons();