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
 * AI placement plugin info class.
24
 *
25
 * @package    core
26
 * @copyright 2024 Matt Porritt <matt.porritt@moodle.com>
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class aiprovider extends base {
30
    /** @var string Enable a plugin */
31
    public const ENABLE = 'enable';
32
 
33
    /** @var string Disable a plugin */
34
    public const DISABLE = 'disable';
35
 
36
    /** @var string Move a plugin up in the plugin order */
37
    public const UP = 'up';
38
 
39
    /** @var string Move a plugin down in the plugin order */
40
    public const DOWN = 'down';
41
 
42
    #[\Override]
43
    public function is_uninstall_allowed(): bool {
44
        return true;
45
    }
46
 
47
    #[\Override]
48
    public function get_settings_section_name(): string {
49
        return $this->type . '_' . $this->name;
50
    }
51
 
52
    #[\Override]
53
    public static function get_manage_url(): moodle_url {
54
        return new moodle_url('/admin/settings.php', [
55
            'section' => 'aiprovider',
56
        ]);
57
    }
58
 
59
    #[\Override]
60
    public static function get_enabled_plugins(): ?array {
61
        $pluginmanager = core_plugin_manager::instance();
62
        $plugins = $pluginmanager->get_installed_plugins('aiprovider');
63
 
64
        if (!$plugins) {
65
            return [];
66
        }
67
 
68
        $plugins = array_keys($plugins);
69
 
70
        // Filter to return only enabled plugins.
71
        $enabled = [];
72
        foreach ($plugins as $plugin) {
73
            $disabled = get_config('aiprovider_' . $plugin, 'disabled');
74
            if (empty($disabled)) {
75
                $enabled[$plugin] = $plugin;
76
            }
77
        }
78
        return $enabled;
79
    }
80
 
81
    /**
82
     * Returns the list of available actions with provider.
83
     *
84
     * @return array
85
     */
86
    public static function get_provider_actions(): array {
87
        return [self::UP, self::DOWN];
88
    }
89
 
90
    #[\Override]
91
    public function uninstall_cleanup(): void {
92
        global $DB;
93
 
94
        $provider = $this->get_settings_section_name() . '\provider';
95
        $DB->delete_records('ai_providers', ['provider' => $provider]);
96
 
97
        parent::uninstall_cleanup();
98
    }
99
}