Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
namespace mod_bigbluebuttonbn\plugininfo;
17
 
18
use core\plugininfo\base;
19
use mod_bigbluebuttonbn\extension;
20
 
21
/**
22
 * Subplugin extension info class.
23
 *
24
 * @package   mod_bigbluebuttonbn
25
 * @copyright 2022 onwards, Blindside Networks Inc
26
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @author    Laurent David (laurent@call-learning.fr)
28
 */
29
class bbbext extends base {
30
    /**
31
     * Check if BigBlueButton plugin is enabled
32
     * @return bool
33
     */
34
    private static function is_bbb_enabled(): bool {
35
        $enabledplugins = \core\plugininfo\mod::get_enabled_plugins();
36
        return isset($enabledplugins['bigbluebuttonbn']);
37
    }
38
 
39
    /**
40
     * Get a list of enabled plugins
41
     *
42
     * @return array
43
     * @throws \dml_exception
44
     */
45
    public static function get_enabled_plugins(): array {
46
        // If the mod_bigbluebuttonbn is not enabled, then all subplugin are disabled.
47
        if (!self::is_bbb_enabled()) {
48
            return [];
49
        }
50
        // Get all available plugins.
51
        $plugins = \core_plugin_manager::instance()->get_installed_plugins(extension::BBB_EXTENSION_PLUGIN_NAME);
52
        if (!$plugins) {
53
            return [];
54
        }
55
 
56
        // Check they are enabled using get_config (which is cached and hopefully fast).
57
        $enabled = [];
58
        foreach ($plugins as $plugin => $version) {
59
            $disabled = get_config(extension::BBB_EXTENSION_PLUGIN_NAME . '_' . $plugin, 'disabled');
60
            if (empty($disabled)) {
61
                $enabled[$plugin] = $plugin;
62
            }
63
        }
64
 
65
        return $enabled;
66
    }
67
 
68
    /**
69
     * Enable the plugin
70
     *
71
     * @param string $pluginname
72
     * @param int $enabled
73
     * @return bool
74
     * @throws \dml_exception
75
     */
76
    public static function enable_plugin(string $pluginname, int $enabled): bool {
77
        $haschanged = false;
78
        // If the mod_bigbluebuttonbn is not enabled, then all subplugin are disabled.
79
        if (!self::is_bbb_enabled()) {
80
            return false;
81
        }
82
        $plugin = extension::BBB_EXTENSION_PLUGIN_NAME. '_' . $pluginname;
83
        $oldvalue = get_config($plugin, 'disabled');
84
        $disabled = !$enabled;
85
        // Only set value if there is no config setting or if the value is different from the previous one.
86
        if ($oldvalue == false && $disabled) {
87
            set_config('disabled', $disabled, $plugin);
88
            $haschanged = true;
89
        } else if ($oldvalue != false && !$disabled) {
90
            unset_config('disabled', $plugin);
91
            $haschanged = true;
92
        }
93
 
94
        if ($haschanged) {
95
            add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
96
            \core_plugin_manager::reset_caches();
97
        }
98
 
99
        return $haschanged;
100
    }
101
 
102
    /**
103
     * Loads plugin settings to the settings tree
104
     *
105
     * This function usually includes settings.php file in plugins folder.
106
     * Alternatively it can create a link to some settings page (instance of admin_externalpage)
107
     *
108
     * @param \part_of_admin_tree $adminroot
109
     * @param string $parentnodename
110
     * @param bool $hassiteconfig whether the current user has moodle/site:config capability
111
     */
112
    public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
113
        // If the mod_bigbluebuttonbn is not enabled, then all subplugin are disabled.
114
        if (!self::is_bbb_enabled()) {
115
            return;
116
        }
117
        $ADMIN = $adminroot;
118
        $plugininfo = $this;
119
 
120
        if (!$this->is_installed_and_upgraded()) {
121
            return;
122
        }
123
 
124
        if (!$hassiteconfig || !file_exists($this->full_path('settings.php'))) {
125
            return;
126
        }
127
 
128
        $section = $this->get_settings_section_name();
129
 
130
        $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config',
131
            $this->is_enabled() === false);
132
 
133
        if ($adminroot->fulltree) {
134
            $shortsubtype = substr($this->type, strlen(extension::BBB_EXTENSION_PLUGIN_NAME));
135
            include($this->full_path('settings.php'));
136
        }
137
 
138
        $adminroot->add($this->type . 'plugins', $settings);
139
    }
140
 
141
    /**
142
     * Get settings section name
143
     *
144
     * @return string
145
     */
146
    public function get_settings_section_name() {
147
        return $this->type . '_' . $this->name;
148
    }
149
 
150
    /**
151
     * Should there be a way to uninstall the plugin via the administration UI.
152
     *
153
     *
154
     * @return bool
155
     */
156
    public function is_uninstall_allowed() {
157
        return true;
158
    }
159
}