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
 
17
namespace mod_assign\plugininfo;
18
 
19
use core\plugininfo\base;
20
use core_plugin_manager;
21
use moodle_url;
22
 
23
/**
24
 * Assign feedback subplugin info class.
25
 *
26
 * @package   mod_assign
27
 * @copyright 2013 Petr Skoda {@link http://skodak.org}
28
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class assignfeedback extends base {
31
 
32
    public static function plugintype_supports_disabling(): bool {
33
        return true;
34
    }
35
 
36
    /**
37
     * Finds all enabled plugins, the result may include missing plugins.
38
     * @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
39
     */
40
    public static function get_enabled_plugins() {
41
        global $DB;
42
 
43
        $plugins = core_plugin_manager::instance()->get_installed_plugins('assignfeedback');
44
        if (!$plugins) {
45
            return array();
46
        }
47
        $installed = array();
48
        foreach ($plugins as $plugin => $version) {
49
            $installed[] = 'assignfeedback_'.$plugin;
50
        }
51
 
52
        list($installed, $params) = $DB->get_in_or_equal($installed, SQL_PARAMS_NAMED);
53
        $disabled = $DB->get_records_select('config_plugins', "plugin $installed AND name = 'disabled'", $params, 'plugin ASC');
54
        foreach ($disabled as $conf) {
55
            if (empty($conf->value)) {
56
                continue;
57
            }
58
            list($type, $name) = explode('_', $conf->plugin, 2);
59
            unset($plugins[$name]);
60
        }
61
 
62
        $enabled = array();
63
        foreach ($plugins as $plugin => $version) {
64
            $enabled[$plugin] = $plugin;
65
        }
66
 
67
        return $enabled;
68
    }
69
 
70
    public static function enable_plugin(string $pluginname, int $enabled): bool {
71
        $haschanged = false;
72
 
73
        $plugin = 'assignfeedback_' . $pluginname;
74
        $oldvalue = get_config($plugin, 'disabled');
75
        $disabled = !$enabled;
76
        // Only set value if there is no config setting or if the value is different from the previous one.
77
        if ($oldvalue === false || ((bool) $oldvalue != $disabled)) {
78
            set_config('disabled', $disabled, $plugin);
79
            $haschanged = true;
80
 
81
            add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
82
            \core_plugin_manager::reset_caches();
83
        }
84
 
85
        return $haschanged;
86
    }
87
 
88
    public function is_uninstall_allowed() {
89
        return true;
90
    }
91
 
92
    /**
93
     * Return URL used for management of plugins of this type.
94
     * @return moodle_url
95
     */
96
    public static function get_manage_url() {
97
        return new moodle_url('/mod/assign/adminmanageplugins.php', array('subtype'=>'assignfeedback'));
98
    }
99
 
100
    /**
101
     * Pre-uninstall hook.
102
     * @private
103
     */
104
    public function uninstall_cleanup() {
105
        global $DB;
106
 
107
        $DB->delete_records('assign_plugin_config', array('plugin'=>$this->name, 'subtype'=>'assignfeedback'));
108
 
109
        parent::uninstall_cleanup();
110
    }
111
 
112
    public function get_settings_section_name() {
113
        return $this->type . '_' . $this->name;
114
    }
115
 
116
    /**
117
     * Loads plugin settings to the settings tree
118
     *
119
     * This function usually includes settings.php file in plugins folder.
120
     * Alternatively it can create a link to some settings page (instance of admin_externalpage)
121
     *
122
     * @param \part_of_admin_tree $adminroot
123
     * @param string $parentnodename
124
     * @param bool $hassiteconfig whether the current user has moodle/site:config capability
125
     */
126
    public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
127
        global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
128
        $ADMIN = $adminroot; // May be used in settings.php.
129
        $plugininfo = $this; // Also can be used inside settings.php.
130
 
131
        if (!$this->is_installed_and_upgraded()) {
132
            return;
133
        }
134
 
135
        if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) {
136
            return;
137
        }
138
 
139
        $section = $this->get_settings_section_name();
140
 
141
        $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
142
 
143
        if ($adminroot->fulltree) {
144
            $shortsubtype = substr($this->type, strlen('assign'));
145
            include($this->full_path('settings.php'));
146
        }
147
 
148
        $adminroot->add($this->type . 'plugins', $settings);
149
    }
150
}