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_admin\admin;
|
|
|
18 |
|
|
|
19 |
use admin_setting;
|
|
|
20 |
use core_plugin_manager;
|
|
|
21 |
use core_text;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Admin setting plugin manager.
|
|
|
25 |
*
|
|
|
26 |
* @package core_admin
|
|
|
27 |
* @subpackage admin
|
|
|
28 |
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class admin_setting_plugin_manager extends admin_setting {
|
|
|
32 |
/** @var core_plugin_manager The plugin manager instance */
|
|
|
33 |
protected core_plugin_manager $pluginmanager;
|
|
|
34 |
|
|
|
35 |
/** @var string The plugintype that this manager covers */
|
|
|
36 |
protected string $plugintype;
|
|
|
37 |
|
|
|
38 |
/** @var string The class of the management table to use */
|
|
|
39 |
protected string $tableclass;
|
|
|
40 |
|
|
|
41 |
public function __construct(
|
|
|
42 |
string $plugintype,
|
|
|
43 |
string $tableclass,
|
|
|
44 |
string $name,
|
|
|
45 |
string $visiblename,
|
|
|
46 |
string $description = '',
|
|
|
47 |
string $defaultsetting = '',
|
|
|
48 |
) {
|
|
|
49 |
$this->nosave = true;
|
|
|
50 |
$this->pluginmanager = core_plugin_manager::instance();
|
|
|
51 |
$this->plugintype = $plugintype;
|
|
|
52 |
$this->tableclass = $tableclass;
|
|
|
53 |
|
|
|
54 |
parent::__construct($name, $visiblename, $description, $defaultsetting);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Always returns true, does nothing
|
|
|
59 |
*
|
|
|
60 |
* @return true
|
|
|
61 |
*/
|
|
|
62 |
public function get_setting(): bool {
|
|
|
63 |
return true;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Always returns true, does nothing
|
|
|
68 |
*
|
|
|
69 |
* @return true
|
|
|
70 |
*/
|
|
|
71 |
public function get_defaultsetting(): bool {
|
|
|
72 |
return true;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Always returns '', does not write anything
|
|
|
77 |
*
|
|
|
78 |
* @return string Always returns ''
|
|
|
79 |
*/
|
|
|
80 |
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
|
|
81 |
public function write_setting($data): string {
|
|
|
82 |
// Do not write any setting.
|
|
|
83 |
return '';
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Checks if $query is one of the available editors
|
|
|
88 |
*
|
|
|
89 |
* @param string $query The string to search for
|
|
|
90 |
* @return bool Returns true if found, false if not
|
|
|
91 |
*/
|
|
|
92 |
public function is_related($query) {
|
|
|
93 |
if (parent::is_related($query)) {
|
|
|
94 |
return true;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
$plugins = $this->pluginmanager->get_installed_plugins($this->plugintype);
|
|
|
98 |
foreach (array_keys($plugins) as $plugin) {
|
|
|
99 |
$plugin = "{$this->plugintype}_{$plugin}";
|
|
|
100 |
if (str_contains($plugin, $query)) {
|
|
|
101 |
return true;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
$pluginname = get_string('pluginname', $plugin);
|
|
|
105 |
if (strpos(core_text::strtolower($pluginname), $query) !== false) {
|
|
|
106 |
return true;
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
return false;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Builds the XHTML to display the control
|
|
|
115 |
*
|
|
|
116 |
* @param string $data Unused
|
|
|
117 |
* @param string $query
|
|
|
118 |
* @return string
|
|
|
119 |
*/
|
|
|
120 |
public function output_html($data, $query = ''): string {
|
|
|
121 |
$table = new $this->tableclass();
|
|
|
122 |
if (!($table instanceof \core_admin\table\plugin_management_table)) {
|
|
|
123 |
throw new \coding_exception("{$this->tableclass} must be an instance of \\core_admin\\table\\plugin_management_table");
|
|
|
124 |
}
|
|
|
125 |
return highlight($query, $table->get_content());
|
|
|
126 |
}
|
|
|
127 |
}
|