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_ai\admin;
18
 
19
use admin_setting;
20
use coding_exception;
21
 
22
/**
23
 * Admin setting provider manager.
24
 *
25
 * @package    core_ai
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 admin_setting_provider_manager extends admin_setting {
30
    /**
31
     * Constructor.
32
     *
33
     * @param string $pluginname The name of the plugin these actions related too.
34
     * @param string $tableclass The class of the management table to use.
35
     * @param string $name The unique name.
36
     * @param string $visiblename The localised name.
37
     * @param string $description The localised long description in Markdown format.
38
     * @param string $defaultsetting The default setting.
39
     */
40
    public function __construct(
41
        /** @var string The name of the plugin these actions related too */
42
        protected string $pluginname,
43
        /** @var string The class of the management table to use */
44
        protected string $tableclass,
45
        string $name,
46
        string $visiblename,
47
        string $description = '',
48
        string $defaultsetting = '',
49
    ) {
50
        $this->nosave = true;
51
        parent::__construct($name, $visiblename, $description, $defaultsetting);
52
    }
53
 
54
    #[\Override]
55
    public function get_setting(): bool {
56
        return true;
57
    }
58
 
59
    #[\Override]
60
    public function write_setting($data): string {
61
        // Do not write any setting.
62
        return '';
63
    }
64
 
65
    #[\Override]
66
    public function output_html($data, $query = ''): string {
67
        $table = new $this->tableclass($this->pluginname);
68
        if (
69
            !($table instanceof \core_ai\table\aiprovider_management_table)
70
        ) {
71
            throw new coding_exception(sprintf(
72
                "% must be an instance aiprovider_management_table",
73
                $this->tableclass
74
            ));
75
        }
76
        return highlight($query, $table->get_content());
77
    }
78
}