forked from learnweb/moodle-mod_collaborativefolders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
80 lines (71 loc) · 3.56 KB
/
settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Settings.php for collaborativefolders activity module. Manages the login to an ownCloud account.
*
* @package mod_collaborativefolders
* @copyright 2017 Project seminar (Learnweb, University of Münster)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_collaborativefolders\issuer_management;
defined('MOODLE_INTERNAL') || die();
if ($ADMIN->fulltree) {
// Collect available issuers.
$issuers = core\oauth2\api::get_all_issuers();
$availableissuers = [0 => get_string('issuer_choice_unconfigured', 'collaborativefolders')];
// Validates which issuers implement the needed endpoints.
$validissuers = [];
foreach ($issuers as $issuer) {
if (issuer_management::is_valid_issuer($issuer)) {
$validissuers[] = $issuer->get('id');
}
$availableissuers[$issuer->get('id')] = $issuer->get('name');
}
// All issuers that are valid are displayed seperately (if any).
if (count($validissuers) === 0) {
$issuershint = get_string('no_right_issuers', 'mod_collaborativefolders');
} else {
$validissuerstext = array_map(function($id) use ($availableissuers) {
return $availableissuers[$id];
}, $validissuers);
$issuershint = get_string('right_issuers', 'mod_collaborativefolders', implode(', ', $validissuerstext));
}
// Indicate quality of the chosen issuer.
// Warning if no issuer chosen / issuer invalid / issuer valid but no system account connected.
$issuerid = get_config("collaborativefolders", "issuerid");
$issuer = \core\oauth2\api::get_issuer($issuerid);
if (empty($issuerid) || !array_key_exists($issuerid, $availableissuers)) {
$issuervalidation = get_string('issuervalidation_without', 'mod_collaborativefolders');
} else if (!in_array($issuerid, $validissuers)) {
$issuervalidation = get_string('issuervalidation_invalid', 'mod_collaborativefolders', $availableissuers[$issuerid]);
} else if (!$issuer->is_system_account_connected()) {
$issuervalidation = get_string('issuervalidation_notconnected', 'mod_collaborativefolders', $availableissuers[$issuerid]);
} else {
$issuervalidation = get_string('issuervalidation_valid', 'mod_collaborativefolders', $availableissuers[$issuerid]);
}
// Render the form.
$url = new \moodle_url('/admin/tool/oauth2/issuers.php');
$settings->add(new admin_setting_configselect('collaborativefolders/issuerid',
get_string('chooseissuer', 'mod_collaborativefolders'),
implode('<br>', [
get_string('oauth2serviceslink', 'mod_collaborativefolders', $url->out()),
$issuershint,
$issuervalidation,
]),
0, $availableissuers));
$settings->add(new admin_setting_configtext('collaborativefolders/servicename',
get_string('servicename', 'mod_collaborativefolders'), '', 'ownCloud'));
}