Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea -...
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
 
16
 
-
 
17
namespace core_badges\form;
-
 
18
 
-
 
19
use core_badges\backpack_api;
25
namespace core_badges\form;
20
 
Línea 26... Línea 21...
26
defined('MOODLE_INTERNAL') || die();
21
defined('MOODLE_INTERNAL') || die();
Línea 27... Línea 22...
27
 
22
 
Línea 42... Línea 37...
42
     */
37
     */
43
    public function definition() {
38
    public function definition() {
44
        global $CFG;
39
        global $CFG;
Línea 45... Línea 40...
45
 
40
 
46
        $mform = $this->_form;
-
 
47
        $backpack = false;
-
 
48
 
-
 
49
        if (isset($this->_customdata['externalbackpack'])) {
41
        $mform = $this->_form;
50
            $backpack = $this->_customdata['externalbackpack'];
-
 
Línea 51... Línea 42...
51
        }
42
        $backpack = $this->_customdata['externalbackpack'] ?? null;
52
 
43
 
Línea 53... Línea 44...
53
        $mform->addElement('hidden', 'action', 'edit');
44
        $mform->addElement('hidden', 'action', 'edit');
54
        $mform->setType('action', PARAM_ALPHA);
45
        $mform->setType('action', PARAM_ALPHA);
55
 
46
 
56
        $apiversions = badges_get_badge_api_versions();
47
        $apiversions = badges_get_badge_api_versions();
57
        $mform->addElement('select', 'apiversion', get_string('apiversion', 'core_badges'), $apiversions);
48
        $mform->addElement('select', 'apiversion', get_string('apiversion', 'core_badges'), $apiversions);
Línea -... Línea 49...
-
 
49
        $mform->setType('apiversion', PARAM_RAW);
-
 
50
        $mform->setDefault('apiversion', OPEN_BADGES_V2P1);
58
        $mform->setType('apiversion', PARAM_RAW);
51
        $mform->addRule('apiversion', null, 'required', null, 'client');
59
        $mform->setDefault('apiversion', OPEN_BADGES_V2P1);
52
 
60
        $mform->addRule('apiversion', null, 'required', null, 'client');
-
 
61
 
53
        $this->add_provider_fields();
-
 
54
 
Línea 62... Línea 55...
62
        $mform->addElement('text', 'backpackweburl', get_string('backpackweburl', 'core_badges'));
55
        $mform->addElement('text', 'backpackweburl', get_string('backpackweburl', 'core_badges'));
63
        $mform->setType('backpackweburl', PARAM_URL);
56
        $mform->setType('backpackweburl', PARAM_URL);
64
        $mform->addRule('backpackweburl', null, 'required', null, 'client');
57
        $mform->addRule('backpackweburl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
-
 
58
        $mform->hideIf('backpackweburl', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
59
 
-
 
60
        $mform->addElement('text', 'backpackapiurl',  get_string('backpackapiurl', 'core_badges'));
-
 
61
        $mform->setType('backpackapiurl', PARAM_URL);
-
 
62
        $mform->addRule('backpackapiurl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
-
 
63
        $mform->hideIf('backpackapiurl', 'apiversion', 'ne', OPEN_BADGES_V2);
Línea 65... Línea 64...
65
        $mform->addRule('backpackweburl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
64
 
66
 
65
        $mform->addElement('text', 'backpackweburlv2p1', get_string('backpackweburl', 'core_badges'));
67
        $mform->addElement('text', 'backpackapiurl',  get_string('backpackapiurl', 'core_badges'));
66
        $mform->setType('backpackweburlv2p1', PARAM_URL);
68
        $mform->setType('backpackapiurl', PARAM_URL);
67
        $mform->addRule('backpackweburlv2p1', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
69
        $mform->addRule('backpackapiurl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
68
        $mform->hideIf('backpackweburlv2p1', 'apiversion', 'ne', (string) OPEN_BADGES_V2P1);
70
 
69
 
71
        $mform->addElement('hidden', 'id', ($backpack->id ?? null));
70
        $mform->addElement('hidden', 'id', ($backpack->id ?? null));
72
        $mform->setType('id', PARAM_INT);
71
        $mform->setType('id', PARAM_INT);
Línea -... Línea 72...
-
 
72
        $mform->addElement('hidden', 'badgebackpack', 0);
73
        $mform->addElement('hidden', 'badgebackpack', 0);
73
        $mform->setType('badgebackpack', PARAM_INT);
74
        $mform->setType('badgebackpack', PARAM_INT);
74
        $mform->addElement('hidden', 'userid', 0);
75
        $mform->addElement('hidden', 'userid', 0);
75
        $mform->setType('userid', PARAM_INT);
76
        $mform->setType('userid', PARAM_INT);
76
        $mform->addElement('hidden', 'backpackuid', 0);
Línea 77... Línea 77...
77
        $mform->addElement('hidden', 'backpackuid', 0);
77
        $mform->setType('backpackuid', PARAM_INT);
-
 
78
 
78
        $mform->setType('backpackuid', PARAM_INT);
79
        // Add rules for backpack URL fields.
-
 
80
        if (backpack_api::display_canvas_credentials_fields()) {
-
 
81
            $mform->hideIf('backpackweburl', 'provider', 'ne', backpack_api::PROVIDER_OTHER);
-
 
82
            $mform->hideIf('backpackapiurl', 'provider', 'ne', backpack_api::PROVIDER_OTHER);
Línea 79... Línea 83...
79
 
83
        }
80
        $mform->addElement('advcheckbox', 'includeauthdetails', null, get_string('includeauthdetails', 'core_badges'));
84
 
81
        if (!empty($backpack->backpackemail) || !empty($backpack->password)) {
85
        $issueremail = $CFG->badges_defaultissuercontact;
Línea 82... Línea -...
82
            $mform->setDefault('includeauthdetails', 1);
-
 
83
        }
-
 
84
 
-
 
85
        $issuercontact = $CFG->badges_defaultissuercontact;
-
 
86
        $this->add_auth_fields($issuercontact);
-
 
87
 
-
 
88
        if ($backpack) {
-
 
89
            $this->set_data($backpack);
86
        // Connect to a Canvas Credentials provider.
90
        }
87
        $this->add_connect_issuer_canvas_fields($issueremail);
Línea 91... Línea 88...
91
 
88
 
92
        $mform->hideIf('includeauthdetails', 'apiversion', 'in', [OPEN_BADGES_V2P1]);
89
        // Connect to another provider.
Línea -... Línea 90...
-
 
90
        $this->add_connect_issuer_fields($backpack, $issueremail);
-
 
91
 
-
 
92
        if ($backpack) {
-
 
93
            $this->set_data($backpack);
-
 
94
        }
-
 
95
 
-
 
96
        // Disable short forms.
-
 
97
        $mform->setDisableShortforms();
-
 
98
 
-
 
99
        $this->add_action_buttons();
-
 
100
    }
-
 
101
 
-
 
102
    #[\Override]
-
 
103
    public function definition_after_data(): void {
-
 
104
        parent::definition_after_data();
-
 
105
        $mform = $this->_form;
-
 
106
 
-
 
107
        if ($this->is_submitted()) {
-
 
108
            if (!$mform->elementExists('apiversion')) {
-
 
109
                return;
-
 
110
            }
-
 
111
            $apiversion = $mform->getElement('apiversion')->getValue();
-
 
112
            $apiversion = $apiversion ? array_pop($apiversion) : null;
-
 
113
            $provider = $mform->elementExists('provider') ? $mform->getElement('provider')->getValue() : null;
-
 
114
            $provider = $provider ? array_pop($provider) : null;
-
 
115
            $region = $mform->elementExists('region') ? $mform->getElement('region')->getValue() : null;
-
 
116
            $region = $region ? array_pop($region) : null;
-
 
117
            if ($apiversion == OPEN_BADGES_V2) {
-
 
118
                if (
-
 
119
                    $provider == backpack_api::PROVIDER_CANVAS_CREDENTIALS
-
 
120
                    && isset($region) && $region != backpack_api::REGION_EMPTY
-
 
121
                ) {
-
 
122
                    $mform->getElement('backpackweburl')->setValue(
-
 
123
                        backpack_api::get_region_url($region),
-
 
124
                    );
-
 
125
                    $mform->getElement('backpackapiurl')->setValue(
-
 
126
                        backpack_api::get_region_api_url($region),
-
 
127
                    );
-
 
128
 
-
 
129
                    if ($mform->getElement('includeauthdetailscanvas')->getValue()) {
-
 
130
                        $mform->getElement('backpackemail')->setValue(
-
 
131
                            $mform->getElement('backpackemailcanvas')->getValue(),
-
 
132
                        );
-
 
133
                        $mform->getElement('password')->setValue(
-
 
134
                            $mform->getElement('backpackpasswordcanvas')->getValue(),
-
 
135
                        );
-
 
136
                    }
-
 
137
                } else if (is_null($provider) || $provider == backpack_api::PROVIDER_OTHER) {
-
 
138
                    if ($mform->getElement('includeauthdetails')->getValue() == 0) {
-
 
139
                        // Clear backpack issuer fields when authentication details checkbox is not checked.
-
 
140
                        $mform->getElement('backpackemail')->setValue('');
-
 
141
                        $mform->getElement('password')->setValue('');
-
 
142
                    }
-
 
143
                }
-
 
144
            } else if ($apiversion == OPEN_BADGES_V2P1) {
-
 
145
                if (!empty($mform->getElement('backpackweburlv2p1')->getValue())) {
-
 
146
                    $mform->getElement('backpackweburl')->setValue(
-
 
147
                        $mform->getElement('backpackweburlv2p1')->getValue(),
-
 
148
                    );
-
 
149
                }
-
 
150
                // Clear backpack issuer fields when OBv2.1 is selected.
-
 
151
                $mform->getElement('includeauthdetails')->setValue(0);
-
 
152
                $mform->getElement('backpackemail')->setValue('');
-
 
153
                $mform->getElement('password')->setValue('');
-
 
154
            }
-
 
155
        }
-
 
156
    }
-
 
157
 
-
 
158
    #[\Override]
-
 
159
    public function set_data($backpack) {
-
 
160
        if ($backpack->apiversion == OPEN_BADGES_V2) {
-
 
161
            if (backpack_api::is_canvas_credentials_region($backpack->backpackweburl)) {
-
 
162
                // Calculate provider and region fields based on backpack URLs.
-
 
163
                $backpack->provider = backpack_api::PROVIDER_CANVAS_CREDENTIALS;
-
 
164
                $backpack->region = backpack_api::get_regionid_from_url($backpack->backpackweburl);
-
 
165
                $backpack->backpackweburl = '';
-
 
166
                $backpack->backpackapiurl = '';
-
 
167
                if (isset($backpack->backpackemail) && !empty($backpack->backpackemail)) {
-
 
168
                    // Update Canvas Credentials fields.
-
 
169
                    $backpack->includeauthdetailscanvas = 1;
-
 
170
                    $backpack->backpackemailcanvas = $backpack->backpackemail;
-
 
171
                    $backpack->backpackpasswordcanvas = $backpack->password;
-
 
172
                    // Clear email and password fields for another providers.
-
 
173
                    $backpack->includeauthdetails = 0;
-
 
174
                    $backpack->backpackemail = '';
-
 
175
                    $backpack->password = '';
-
 
176
                }
93
        $mform->hideIf('backpackemail', 'includeauthdetails');
177
            } else {
94
        $mform->hideIf('backpackemail', 'apiversion', 'in', [OPEN_BADGES_V2P1]);
178
                $backpack->provider = backpack_api::PROVIDER_OTHER;
95
        $mform->hideIf('password', 'includeauthdetails');
179
            }
96
        $mform->hideIf('password', 'apiversion', 'in', [OPEN_BADGES_V1, OPEN_BADGES_V2P1]);
180
        } else if ($backpack->apiversion == OPEN_BADGES_V2P1) {
97
        $mform->hideIf('backpackapiurl', 'apiversion', 'in', [OPEN_BADGES_V1, OPEN_BADGES_V2P1]);
181
            $backpack->backpackweburlv2p1 = $backpack->backpackweburl;
Línea 111... Línea 195...
111
     */
195
     */
112
    public function validation($data, $files) {
196
    public function validation($data, $files) {
113
        $errors = parent::validation($data, $files);
197
        $errors = parent::validation($data, $files);
Línea 114... Línea 198...
114
 
198
 
-
 
199
        // Ensure backpackapiurl and backpackweburl are valid URLs.
115
        // Ensure backpackapiurl and backpackweburl are valid URLs.
200
        $isobv20 = isset($data['apiversion']) && $data['apiversion'] == OPEN_BADGES_V2;
116
        $isobv21 = isset($data['apiversion']) && $data['apiversion'] == OPEN_BADGES_V2P1;
201
        $isobv2p1 = isset($data['apiversion']) && $data['apiversion'] == OPEN_BADGES_V2P1;
-
 
202
        if ($isobv20) {
-
 
203
            $errors = array_merge($errors, $this->validate_obv20($data));
-
 
204
        } else if ($isobv2p1) {
-
 
205
            $errors = array_merge($errors, $this->validate_obv2p1($data));
-
 
206
        }
-
 
207
 
-
 
208
        // Check email and password are not empty when including auth details.
-
 
209
        if (!empty($data['includeauthdetails']) && empty($data['backpackemail'])) {
-
 
210
            $errors['backpackemail'] = get_string('err_required', 'form');
-
 
211
        }
-
 
212
        if (!empty($data['includeauthdetails']) && empty($data['password'])) {
-
 
213
            $errors['password'] = get_string('err_required', 'form');
-
 
214
        }
-
 
215
 
-
 
216
        return $errors;
-
 
217
    }
-
 
218
 
-
 
219
    /**
-
 
220
     * Validate the data for Open Badges v2.0.
-
 
221
     *
-
 
222
     * @param array $data Form data.
-
 
223
     * @return string[] An array of error messages.
-
 
224
     */
-
 
225
    private function validate_obv20(array $data): array {
-
 
226
        $errors = [];
-
 
227
 
-
 
228
        $displaycanvasfields = backpack_api::display_canvas_credentials_fields();
-
 
229
        if (
-
 
230
            $displaycanvasfields
-
 
231
            && (!array_key_exists('provider', $data) || $data['provider'] == backpack_api::PROVIDER_EMPTY)
-
 
232
        ) {
-
 
233
            // Check provider is set.
-
 
234
            $errors['provider'] = get_string('err_required', 'form');
-
 
235
        } else if (
-
 
236
            $displaycanvasfields
-
 
237
            && ($data['provider'] == backpack_api::PROVIDER_CANVAS_CREDENTIALS)
-
 
238
        ) {
-
 
239
            // Check region is set.
-
 
240
            if (!array_key_exists('region', $data) || $data['region'] == backpack_api::REGION_EMPTY) {
-
 
241
                $errors['region'] = get_string('err_required', 'form');
-
 
242
            }
-
 
243
        } else {
-
 
244
            if (empty($data['backpackweburl'])) {
-
 
245
                $errors['backpackweburl'] = get_string('err_required', 'form');
-
 
246
            } else if (!preg_match('@^https?://.+@', $data['backpackweburl'])) {
-
 
247
                $errors['backpackweburl'] = get_string('invalidurl', 'badges');
117
        if (!$isobv21) {
248
            }
118
            if (empty($data['backpackapiurl'])) {
249
            if (empty($data['backpackapiurl'])) {
119
                $errors['backpackapiurl'] = get_string('err_required', 'form');
250
                $errors['backpackapiurl'] = get_string('err_required', 'form');
120
            } else if (!preg_match('@^https?://.+@', $data['backpackapiurl'])) {
251
            } else if (!preg_match('@^https?://.+@', $data['backpackapiurl'])) {
121
                $errors['backpackapiurl'] = get_string('invalidurl', 'badges');
252
                $errors['backpackapiurl'] = get_string('invalidurl', 'badges');
122
            }
253
            }
-
 
254
        }
-
 
255
 
123
        }
256
        if ($displaycanvasfields) {
124
        if (!empty($data['backpackweburl']) && !preg_match('@^https?://.+@', $data['backpackweburl'])) {
257
            if (!empty($data['includeauthdetailscanvas']) && empty($data['backpackemailcanvas'])) {
-
 
258
                $errors['backpackemailcanvas'] = get_string('err_required', 'form');
-
 
259
            }
-
 
260
            if (!empty($data['includeauthdetailscanvas']) && empty($data['backpackpasswordcanvas'])) {
-
 
261
                $errors['backpackpasswordcanvas'] = get_string('err_required', 'form');
125
            $errors['backpackweburl'] = get_string('invalidurl', 'badges');
262
            }
Línea 126... Línea 263...
126
        }
263
        }
127
 
264
 
Línea 128... Línea 265...
128
        return $errors;
265
        return $errors;
129
    }
-
 
130
 
266
    }
131
    /**
267
 
132
     * Return submitted data if properly submitted or returns NULL if validation fails or
268
    /**
-
 
269
     * Validate the data for Open Badges v2.1.
133
     * if there is no submitted data.
270
     *
134
     *
271
     * @param array $data Form data.
135
     * @return object|void
-
 
136
     */
272
     * @return string[] An array of error messages.
137
    public function get_data() {
-
 
138
        $data = parent::get_data();
-
 
139
        if ($data ) {
-
 
140
            if ((isset($data->includeauthdetails) && !$data->includeauthdetails)
-
 
141
                || (isset($data->apiversion) && $data->apiversion == 2.1)) {
-
 
Línea -... Línea 273...
-
 
273
     */
-
 
274
    private function validate_obv2p1(array $data): array {
142
                $data->backpackemail = "";
275
        $errors = [];
-
 
276
 
-
 
277
        if (empty($data['backpackweburlv2p1'])) {
-
 
278
            $errors['backpackweburlv2p1'] = get_string('err_required', 'form');
-
 
279
        } else if (!preg_match('@^https?://.+@', $data['backpackweburlv2p1'])) {
-
 
280
            $errors['backpackweburlv2p1'] = get_string('invalidurl', 'badges');
-
 
281
        }
-
 
282
 
-
 
283
        return $errors;
-
 
284
    }
-
 
285
 
143
                $data->password = "";
286
    /**
-
 
287
     * Add provider fields to the form.
-
 
288
     */
-
 
289
    protected function add_provider_fields(): void {
144
            }
290
        $mform = $this->_form;
145
 
291
 
Línea -... Línea 292...
-
 
292
        if (!backpack_api::display_canvas_credentials_fields()) {
-
 
293
            // If canvas credentials fields are not to be displayed, return early.
-
 
294
            return;
-
 
295
        }
-
 
296
 
-
 
297
        // Add an empty option at the start.
-
 
298
        $providers = backpack_api::get_providers();
-
 
299
        $providers = [backpack_api::PROVIDER_EMPTY => ''] + $providers;
-
 
300
        $mform->addElement('select', 'provider', get_string('provider', 'core_badges'), $providers);
-
 
301
        $mform->setType('provider', PARAM_RAW);
-
 
302
        $mform->hideIf('provider', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
303
 
-
 
304
        // Add an empty option at the start.
-
 
305
        $regions = backpack_api::get_regions();
-
 
306
        $regions = [backpack_api::REGION_EMPTY => ''] + array_column($regions, 'name');
-
 
307
        $mform->addElement('select', 'region', get_string('region', 'core_badges'), $regions);
-
 
308
        $mform->setType('region', PARAM_RAW);
-
 
309
        $mform->hideIf('region', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
-
 
310
        $mform->hideIf('region', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
311
    }
-
 
312
 
-
 
313
    /**
-
 
314
     * Add Canvas backpack specific issuer auth details.
-
 
315
     *
-
 
316
     * @param string|null $email The email addressed provided or null if it's new.
-
 
317
     */
-
 
318
    protected function add_connect_issuer_canvas_fields(?string $email): void {
-
 
319
        $mform = $this->_form;
-
 
320
 
-
 
321
        if (!backpack_api::display_canvas_credentials_fields()) {
-
 
322
            // If canvas credentials fields are not to be displayed, return early.
-
 
323
            return;
-
 
324
        }
146
            if ((isset($data->apiversion) && $data->apiversion == 1)) {
325
 
-
 
326
        $providers = backpack_api::get_providers();
-
 
327
        $regions = backpack_api::get_regions();
-
 
328
        if (empty($providers) || empty($regions)) {
-
 
329
            // If no providers or regions are available, return early.
-
 
330
            return;
-
 
331
        }
-
 
332
 
-
 
333
        // Checkbox and information to enable/disable issuer account.
-
 
334
        $mform->addElement('static', '', null, '');
-
 
335
        $mform->addElement(
-
 
336
            'advcheckbox',
-
 
337
            'includeauthdetailscanvas',
-
 
338
            null,
-
 
339
            '<strong>' . get_string('includeauthdetailscanvas', 'core_badges') . '</strong> '
-
 
340
            . get_string('includeauthdetailscanvas_subtitle', 'core_badges'),
-
 
341
        );
-
 
342
        if (!empty($backpack->backpackemail) || !empty($backpack->password)) {
-
 
343
            $mform->setDefault('includeauthdetailscanvas', 1);
-
 
344
        }
-
 
345
        $mform->addHelpButton('includeauthdetailscanvas', 'includeauthdetailscanvas', 'core_badges');
-
 
346
        $mform->hideIf('includeauthdetailscanvas', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
347
        $mform->hideIf('includeauthdetailscanvas', 'region', 'eq', backpack_api::REGION_EMPTY);
-
 
348
        $mform->hideIf('includeauthdetailscanvas', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
-
 
349
 
-
 
350
        $mform->addElement(
-
 
351
            'static',
-
 
352
            'includeauthdetailscanvasdesc',
-
 
353
            null,
-
 
354
            get_string('includeauthdetailscanvas_desc', 'core_badges'),
-
 
355
        );
-
 
356
        $mform->hideIf('includeauthdetailscanvasdesc', 'includeauthdetailscanvas');
-
 
357
        $mform->hideIf('includeauthdetailscanvasdesc', 'region', 'eq', backpack_api::REGION_EMPTY);
-
 
358
        $mform->hideIf('includeauthdetailscanvasdesc', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
-
 
359
        $mform->hideIf('includeauthdetailscanvasdesc', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
360
 
-
 
361
        // Email.
-
 
362
        $mform->addElement('text', 'backpackemailcanvas', get_string('issueremail', 'core_badges'));
-
 
363
        $mform->setType('backpackemailcanvas', PARAM_EMAIL);
-
 
364
        $mform->setDefault('backpackemailcanvas', $email);
-
 
365
        $mform->hideIf('backpackemailcanvas', 'includeauthdetailscanvas');
-
 
366
        $mform->hideIf('backpackemailcanvas', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
367
        $mform->hideIf('backpackemailcanvas', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
-
 
368
 
-
 
369
        // Password.
-
 
370
        $mform->addElement('passwordunmask', 'backpackpasswordcanvas', get_string('password'));
-
 
371
        $mform->setType('backpackpasswordcanvas', PARAM_RAW);
-
 
372
        $mform->hideIf('backpackpasswordcanvas', 'includeauthdetailscanvas');
-
 
373
        $mform->hideIf('backpackpasswordcanvas', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
374
        $mform->hideIf('backpackpasswordcanvas', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
-
 
375
    }
-
 
376
 
-
 
377
    /**
-
 
378
     * Add generic backpack issuer auth details.
-
 
379
     *
-
 
380
     * @param \stdClass|null $backpack The backpack instance.
-
 
381
     * @param string|null $email The issuer email or null if it's new.
-
 
382
     */
-
 
383
    protected function add_connect_issuer_fields(?\stdClass $backpack, ?string $email): void {
-
 
384
        $mform = $this->_form;
-
 
385
 
-
 
386
        // Checkbox and information to enable/disable issuer account.
-
 
387
        $mform->addElement(
-
 
388
            'advcheckbox',
-
 
389
            'includeauthdetails',
-
 
390
            null,
-
 
391
            '<strong>' . get_string('includeauthdetails', 'core_badges') . '</strong>',
-
 
392
        );
-
 
393
        if ($backpack && (!empty($backpack->backpackemail) || !empty($backpack->password))) {
-
 
394
            $mform->setDefault('includeauthdetails', 1);
-
 
395
        }
-
 
396
        $mform->addHelpButton('includeauthdetails', 'includeauthdetails', 'core_badges');
-
 
397
        $mform->hideIf('includeauthdetails', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
-
 
398
        $mform->hideIf('includeauthdetails', 'apiversion', 'ne', OPEN_BADGES_V2);
-
 
399
 
-
 
400
        $mform->addElement('static', 'includeauthdetailsdesc', null, get_string('includeauthdetails_desc', 'core_badges'));
147
                $data->password = "";
401
        $mform->hideIf('includeauthdetailsdesc', 'includeauthdetails');
Línea 148... Línea 402...
148
            }
402
        $mform->hideIf('includeauthdetailsdesc', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
149
        }
403
 
150
 
404
        // Email and password fields.
Línea 158... Línea 412...
158
     * @param bool $includepassword Include the password field. Defaults to true
412
     * @param bool $includepassword Include the password field. Defaults to true
159
     * @throws \coding_exception
413
     * @throws \coding_exception
160
     */
414
     */
161
    protected function add_auth_fields(?string $email, bool $includepassword = true) {
415
    protected function add_auth_fields(?string $email, bool $includepassword = true) {
162
        $mform = $this->_form;
416
        $mform = $this->_form;
163
        $emailstring = get_string('email');
-
 
164
        $passwordstring = get_string('password');
-
 
165
        $showpasswordhelp = false;
-
 
166
        if (!isset($this->_customdata['userbackpack'])) {
-
 
167
            $emailstring = get_string('defaultissuercontact', 'core_badges');
-
 
168
            $passwordstring = get_string('defaultissuerpassword', 'core_badges');
-
 
169
            $showpasswordhelp = true;
-
 
170
        }
-
 
Línea -... Línea 417...
-
 
417
 
171
 
418
        // Email.
172
        $mform->addElement('text', 'backpackemail', $emailstring);
419
        $mform->addElement('text', 'backpackemail', get_string('issueremail', 'core_badges'));
173
        $mform->setType('backpackemail', PARAM_EMAIL);
420
        $mform->setType('backpackemail', PARAM_EMAIL);
-
 
421
        $mform->setDefault('backpackemail', $email);
-
 
422
        $mform->hideIf('backpackemail', 'includeauthdetails');
-
 
423
        $mform->hideIf('backpackemail', 'apiversion', 'ne', OPEN_BADGES_V2);
Línea -... Línea 424...
-
 
424
        $mform->hideIf('backpackemail', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
174
        $mform->setDefault('backpackemail', $email);
425
 
175
 
426
        // Password.
176
        if ($includepassword) {
427
        if ($includepassword) {
177
            $mform->addElement('passwordunmask', 'password', $passwordstring);
-
 
178
            $mform->setType('password', PARAM_RAW);
-
 
179
            if ($showpasswordhelp) {
-
 
180
                $mform->addHelpButton('password', 'defaultissuerpassword', 'badges');
428
            $mform->addElement('passwordunmask', 'password', get_string('password'));
-
 
429
            $mform->setType('password', PARAM_RAW);
-
 
430
        }
-
 
431
        $mform->hideIf('password', 'includeauthdetails');
181
            }
432
        $mform->hideIf('password', 'apiversion', 'ne', OPEN_BADGES_V2);
182
        }
433
        $mform->hideIf('password', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);