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 |
namespace core_communication\admin;
|
|
|
18 |
|
|
|
19 |
use admin_setting;
|
|
|
20 |
use core_plugin_manager;
|
|
|
21 |
use core_text;
|
|
|
22 |
use html_table;
|
|
|
23 |
use html_table_row;
|
|
|
24 |
use html_writer;
|
|
|
25 |
use moodle_url;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Communication providers manager. Allow enable/disable communication providers and jump to settings.
|
|
|
29 |
*
|
|
|
30 |
* @package core_communication
|
|
|
31 |
* @copyright 2023 Huong Nguyen <huongnv13@gmail.com>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class manage_communication_providers_page extends admin_setting {
|
|
|
35 |
public function __construct() {
|
|
|
36 |
$this->nosave = true;
|
|
|
37 |
parent::__construct(
|
|
|
38 |
'managecommunications',
|
|
|
39 |
new \lang_string('managecommunicationproviders', 'core_communication'),
|
|
|
40 |
'',
|
|
|
41 |
''
|
|
|
42 |
);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public function get_setting(): bool {
|
|
|
46 |
return true;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function write_setting($data): string {
|
|
|
50 |
// Do not write any setting.
|
|
|
51 |
return '';
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public function output_html($data, $query = ''): string {
|
|
|
55 |
global $OUTPUT;
|
|
|
56 |
|
|
|
57 |
$pluginmanager = core_plugin_manager::instance();
|
|
|
58 |
$plugins = $pluginmanager->get_plugins_of_type('communication');
|
|
|
59 |
if (empty($plugins)) {
|
|
|
60 |
return get_string('nocommunicationprovider', 'core_communication');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
$table = new html_table();
|
|
|
64 |
$table->head = [
|
|
|
65 |
get_string('name'),
|
|
|
66 |
get_string('enable'),
|
|
|
67 |
get_string('settings'),
|
|
|
68 |
get_string('uninstallplugin', 'core_admin'),
|
|
|
69 |
];
|
|
|
70 |
$table->align = ['left', 'center', 'center', 'center'];
|
|
|
71 |
$table->attributes['class'] = 'managecommunicationtable generaltable admintable';
|
|
|
72 |
$table->data = [];
|
|
|
73 |
|
|
|
74 |
foreach ($plugins as $plugin) {
|
|
|
75 |
$class = '';
|
|
|
76 |
$actionurl = new moodle_url('/admin/communication.php', ['sesskey' => sesskey(), 'name' => $plugin->name]);
|
|
|
77 |
if (
|
|
|
78 |
$pluginmanager->get_plugin_info('communication_' . $plugin->name)->get_status() ===
|
|
|
79 |
core_plugin_manager::PLUGIN_STATUS_MISSING
|
|
|
80 |
) {
|
|
|
81 |
$strtypename = $plugin->displayname . ' (' . get_string('missingfromdisk') . ')';
|
|
|
82 |
} else {
|
|
|
83 |
$strtypename = $plugin->displayname;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
if ($plugin->is_enabled()) {
|
|
|
87 |
$hideshow = html_writer::link(
|
|
|
88 |
$actionurl->out(false, ['action' => 'disable']),
|
|
|
89 |
$OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', ['class' => 'iconsmall'])
|
|
|
90 |
);
|
|
|
91 |
} else {
|
|
|
92 |
$class = 'dimmed_text';
|
|
|
93 |
$hideshow = html_writer::link(
|
|
|
94 |
$actionurl->out(false, ['action' => 'enable']),
|
|
|
95 |
$OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', ['class' => 'iconsmall'])
|
|
|
96 |
);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
$settings = '';
|
|
|
100 |
if ($plugin->get_settings_url()) {
|
|
|
101 |
$settings = html_writer::link($plugin->get_settings_url(), get_string('settings'));
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
$uninstall = '';
|
|
|
105 |
if (
|
|
|
106 |
$uninstallurl = core_plugin_manager::instance()->get_uninstall_url(
|
|
|
107 |
'communication_' . $plugin->name,
|
|
|
108 |
'manage'
|
|
|
109 |
)
|
|
|
110 |
) {
|
|
|
111 |
$uninstall = html_writer::link($uninstallurl, get_string('uninstallplugin', 'core_admin'));
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
$row = new html_table_row([$strtypename, $hideshow, $settings, $uninstall]);
|
|
|
115 |
if ($class) {
|
|
|
116 |
$row->attributes['class'] = $class;
|
|
|
117 |
}
|
|
|
118 |
$table->data[] = $row;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
return highlight($query, html_writer::table($table));
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public function is_related($query): bool {
|
|
|
125 |
if (parent::is_related($query)) {
|
|
|
126 |
return true;
|
|
|
127 |
}
|
|
|
128 |
$types = core_plugin_manager::instance()->get_plugins_of_type('communication');
|
|
|
129 |
foreach ($types as $type) {
|
|
|
130 |
if (
|
|
|
131 |
strpos($type->component, $query) !== false ||
|
|
|
132 |
strpos(core_text::strtolower($type->displayname), $query) !== false
|
|
|
133 |
) {
|
|
|
134 |
return true;
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
return false;
|
|
|
138 |
}
|
|
|
139 |
}
|