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
/**
18
 * Admin presets callbacks
19
 *
20
 * @package     tool_admin_presets
21
 * @copyright   2024 David Carrillo <davidmc@moodle.com>
22
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
declare(strict_types=1);
26
 
27
use core\output\inplace_editable;
28
 
29
/**
30
 * Inplace editable functionality
31
 *
32
 * @param string $itemtype
33
 * @param int $itemid
34
 * @param string $newvalue
35
 * @return inplace_editable
36
 */
37
function tool_admin_presets_inplace_editable(string $itemtype, int $itemid, string $newvalue): inplace_editable {
38
    global $DB;
39
    $context = \context_system::instance();
40
    \core_external\external_api::validate_context($context);
41
 
42
    require_capability('moodle/site:config', $context);
43
 
44
    switch ($itemtype) {
45
        case 'presetname':
46
            $newvalue = clean_param($newvalue, PARAM_TEXT);
47
            $edithint = get_string('editadminpresetname', 'tool_admin_presets');
48
            $displayvalue = format_string($newvalue, true, ['context' => \context_system::instance(), 'escape' => false]);
49
            $editlabel = get_string('newvaluefor', 'form', $displayvalue);
50
 
51
            // Update value in database.
52
            $DB->set_field('adminpresets', 'name', $newvalue, [
53
                'id' => $itemid,
54
                'iscore' => \core_adminpresets\manager::NONCORE_PRESET,
55
            ]);
56
 
57
            break;
58
        default:
59
            throw new \coding_exception('Unexpected admin preset inplace editable item type');
60
    }
61
 
62
    return new inplace_editable('tool_admin_presets', $itemtype, $itemid, true, $displayvalue, $newvalue, $edithint, $editlabel);
63
}