1 |
efrain |
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 |
* Admin setting for AWS regions.
|
|
|
19 |
*
|
|
|
20 |
* @package core
|
|
|
21 |
* @author Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
|
|
22 |
* @copyright 2020 Catalyst IT
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace core\aws;
|
|
|
27 |
|
|
|
28 |
defined('MOODLE_INTERNAL') || die();
|
|
|
29 |
|
|
|
30 |
require_once($CFG->dirroot . '/lib/adminlib.php');
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Admin setting for a list of AWS regions.
|
|
|
34 |
*
|
|
|
35 |
* @package core
|
|
|
36 |
* @copyright 2020 Catalyst IT
|
|
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
38 |
*/
|
|
|
39 |
class admin_settings_aws_region extends \admin_setting_configtext {
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Return part of form with setting.
|
|
|
43 |
*
|
|
|
44 |
* @param mixed $data array or string depending on setting
|
|
|
45 |
* @param string $query
|
|
|
46 |
* @return string
|
|
|
47 |
*/
|
|
|
48 |
public function output_html($data, $query='') {
|
|
|
49 |
global $CFG, $OUTPUT;
|
|
|
50 |
|
|
|
51 |
$default = $this->get_defaultsetting();
|
|
|
52 |
$options = [];
|
|
|
53 |
// We do require() not require_once() here, as the file returns a value and we may need to get
|
|
|
54 |
// this value more than once.
|
|
|
55 |
$all = require($CFG->dirroot . '/lib/aws-sdk/src/data/endpoints.json.php');
|
|
|
56 |
$ends = $all['partitions'][0]['regions'];
|
|
|
57 |
if ($ends) {
|
|
|
58 |
foreach ($ends as $key => $value) {
|
|
|
59 |
$options[] = [
|
|
|
60 |
'value' => $key,
|
|
|
61 |
'label' => $key . ' - ' . $value['description'],
|
|
|
62 |
];
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
$context = [
|
|
|
67 |
'list' => $this->get_full_name(),
|
|
|
68 |
'name' => $this->get_full_name(),
|
|
|
69 |
'id' => $this->get_id(),
|
|
|
70 |
'value' => $data,
|
|
|
71 |
'size' => $this->size,
|
|
|
72 |
'options' => $options,
|
|
|
73 |
];
|
|
|
74 |
$element = $OUTPUT->render_from_template('core/aws/setting_aws_region', $context);
|
|
|
75 |
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
|
|
|
76 |
}
|
|
|
77 |
}
|