1441 |
ariadna |
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 |
namespace core\plugininfo;
|
|
|
19 |
|
|
|
20 |
use core\url;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Plugin information for the gradepenalty plugin type.
|
|
|
24 |
*
|
|
|
25 |
* @package core
|
|
|
26 |
* @copyright 2024 Catalyst IT Australia Pty Ltd
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
class gradepenalty extends base {
|
|
|
30 |
#[\Override]
|
|
|
31 |
public function is_uninstall_allowed(): bool {
|
|
|
32 |
return true;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
#[\Override]
|
|
|
36 |
public static function get_manage_url(): url {
|
|
|
37 |
return new url('/grade/penalty/manage_penalty_plugins.php');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
#[\Override]
|
|
|
41 |
public static function plugintype_supports_disabling(): bool {
|
|
|
42 |
return true;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
#[\Override]
|
|
|
46 |
public static function get_enabled_plugins(): array {
|
|
|
47 |
// List of enabled plugins, string delimited.
|
|
|
48 |
$plugins = get_config('core_grades', 'gradepenalty_enabled_plugins');
|
|
|
49 |
|
|
|
50 |
// Return empty array if no plugins are enabled.
|
|
|
51 |
return $plugins ? array_flip(explode(',', $plugins)) : [];
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
#[\Override]
|
|
|
55 |
public static function enable_plugin(string $pluginname, int $enabled): bool {
|
|
|
56 |
// Current enabled plugins.
|
|
|
57 |
$enabledplugins = self::get_enabled_plugins();
|
|
|
58 |
|
|
|
59 |
// If we are enabling the plugin.
|
|
|
60 |
if ($enabled) {
|
|
|
61 |
$enabledplugins[$pluginname] = $pluginname;
|
|
|
62 |
} else {
|
|
|
63 |
unset($enabledplugins[$pluginname]);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// Convert to string.
|
|
|
67 |
$enabledplugins = implode(',', array_keys($enabledplugins));
|
|
|
68 |
|
|
|
69 |
// Save the new list of enabled plugins.
|
|
|
70 |
set_config('gradepenalty_enabled_plugins', $enabledplugins, 'core_grades');
|
|
|
71 |
|
|
|
72 |
return true;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
#[\Override]
|
|
|
76 |
public function is_enabled(): bool {
|
|
|
77 |
return self::is_plugin_enabled($this->name);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* If the provided plugin is enabled.
|
|
|
82 |
*
|
|
|
83 |
* @param string $pluginname The name of the plugin.
|
|
|
84 |
* @return bool if the plugin is enabled.
|
|
|
85 |
*/
|
|
|
86 |
public static function is_plugin_enabled(string $pluginname): bool {
|
|
|
87 |
// Check if the plugin contains plugin type, remove it.
|
|
|
88 |
$pluginname = str_replace('gradepenalty_', '', $pluginname);
|
|
|
89 |
|
|
|
90 |
return key_exists($pluginname, self::get_enabled_plugins());
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
#[\Override]
|
|
|
94 |
public function get_settings_section_name(): string {
|
|
|
95 |
return $this->component;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
#[\Override]
|
|
|
99 |
public function get_settings_url(): ?url {
|
|
|
100 |
$plugins = get_plugin_list_with_function('gradepenalty', 'get_settings_url');
|
|
|
101 |
if (isset($plugins[$this->component])) {
|
|
|
102 |
return component_callback($this->component, 'get_settings_url');
|
|
|
103 |
} else {
|
|
|
104 |
// Use the default settings page.
|
|
|
105 |
return parent::get_settings_url();
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|