Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
namespace core\plugininfo;
18
 
19
use core_plugin_manager;
20
use moodle_url;
21
 
22
/**
23
 * SMS gateway subplugin info class.
24
 *
25
 * @package core
26
 * @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class smsgateway extends base {
30
    #[\Override]
31
    public function is_uninstall_allowed(): bool {
32
        return true;
33
    }
34
 
35
    #[\Override]
36
    public function get_settings_section_name(): string {
37
        return "smsgateway{$this->name}";
38
    }
39
 
40
    #[\Override]
41
    public function load_settings(
42
        \part_of_admin_tree $adminroot,
43
        $parentnodename,
44
        $hassiteconfig,
45
    ): void {
46
        global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
47
        /** @var \admin_root $ADMIN */
48
        $ADMIN = $adminroot; // May be used in settings.php.
49
        $plugininfo = $this; // Also can be used inside settings.php.
50
 
51
        if (!$this->is_installed_and_upgraded()) {
52
            return;
53
        }
54
 
55
        if (!$hassiteconfig) {
56
            return;
57
        }
58
 
59
        $section = $this->get_settings_section_name();
60
 
61
        $settings = null;
62
        if (file_exists($this->full_path('settings.php'))) {
63
            $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
64
            include($this->full_path('settings.php')); // This may also set $settings to null.
65
        }
66
        if ($settings) {
67
            $ADMIN->add($parentnodename, $settings);
68
        }
69
    }
70
 
71
    #[\Override]
72
    public static function get_manage_url(): moodle_url {
73
        return new moodle_url('/sms/sms_gateways.php');
74
    }
75
 
76
    #[\Override]
77
    public static function get_enabled_plugins(): ?array {
78
        $pluginmanager = core_plugin_manager::instance();
79
        $plugins = $pluginmanager->get_installed_plugins('smsgateway');
80
 
81
        if (!$plugins) {
82
            return [];
83
        }
84
 
85
        $plugins = array_keys($plugins);
86
 
87
        // Filter to return only enabled plugins.
88
        $enabled = [];
89
        foreach ($plugins as $plugin) {
90
            $disabled = get_config('smsgateway_' . $plugin, 'disabled');
91
            if (empty($disabled)) {
92
                $enabled[$plugin] = $plugin;
93
            }
94
        }
95
        return $enabled;
96
    }
97
}