MDL-63262 badges: Add badgr.io
[moodle.git] / badges / classes / form / external_backpack.php
CommitLineData
aae219ac
DW
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.
13//
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/>.
16
17/**
18 * External backpack form
19 *
20 * @package core_badges
21 * @copyright 2019 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25namespace core_badges\form;
26defined('MOODLE_INTERNAL') || die();
27
28require_once($CFG->libdir.'/formslib.php');
29
30/**
31 * Backpack form class.
32 *
33 * @package core_badges
34 * @copyright 2019 Damyon Wiese
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class external_backpack extends \moodleform {
38
39 public function definition() {
40 global $CFG;
41
42 $mform = $this->_form;
43 $backpack = false;
44
45 if (isset($this->_customdata['externalbackpack'])) {
46 $backpack = $this->_customdata['externalbackpack'];
47 } else {
48 throw new \coding_exception('backpack is required.');
49 }
50
51 $url = $backpack->backpackapiurl;
52
53 $mform->addElement('static', 'backpackapiurlinfo', get_string('backpackapiurl', 'core_badges'), $url);
54
55 $mform->addElement('hidden', 'backpackapiurl', $url);
56 $mform->setType('backpackapiurl', PARAM_URL);
57
58 $url = $backpack->backpackweburl;
59 $mform->addElement('static', 'backpackweburlinfo', get_string('backpackweburl', 'core_badges'), $url);
60 $mform->addElement('hidden', 'backpackweburl', $url);
61 $mform->setType('backpackweburl', PARAM_URL);
62
63 $options = badges_get_badge_api_versions();
64 $label = $options[$backpack->apiversion];
65 $mform->addElement('static', 'apiversioninfo', get_string('apiversion', 'core_badges'), $label);
66 $mform->addElement('hidden', 'apiversion', $backpack->apiversion);
67 $mform->setType('apiversion', PARAM_INTEGER);
68
69 $mform->addElement('hidden', 'id', $backpack->id);
70 $mform->setType('id', PARAM_INTEGER);
71
72 $mform->addElement('hidden', 'action', 'edit');
73 $mform->setType('action', PARAM_ALPHA);
74
75 $issuername = $CFG->badges_defaultissuername;
76 $mform->addElement('static', 'issuerinfo', get_string('defaultissuername', 'core_badges'), $issuername);
77
78 $issuercontact = $CFG->badges_defaultissuercontact;
79 $mform->addElement('static', 'issuerinfo', get_string('defaultissuercontact', 'core_badges'), $issuercontact);
80
81 $mform->addElement('passwordunmask', 'password', get_string('defaultissuerpassword', 'core_badges'));
82 $mform->setType('password', PARAM_RAW);
83 $mform->addHelpButton('password', 'defaultissuerpassword', 'badges');
84 $mform->hideIf('password', 'apiversion', 'eq', 1);
85
86 $this->set_data($backpack);
87
88 // Disable short forms.
89 $mform->setDisableShortforms();
90
91 $this->add_action_buttons();
92 }
93
94}