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
/**
18
 * Tour.
19
 *
20
 * @package    tool_usertours
21
 * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
use core_external\external_api;
26
use tool_usertours\helper;
27
 
28
/**
29
 * Manage inplace editable saves.
30
 *
31
 * @param string $itemtype The type of item.
32
 * @param int $itemid The ID of the item.
33
 * @param mixed $newvalue The new value
34
 * @return \core\output\inplace_editable
35
 */
36
function tool_usertours_inplace_editable($itemtype, $itemid, $newvalue) {
37
    $context = \context_system::instance();
38
    external_api::validate_context($context);
39
    require_capability('tool/usertours:managetours', $context);
40
 
41
    if ($itemtype === 'tourname') {
42
        $tour = helper::get_tour($itemid);
43
        $tour->set_name($newvalue)->persist();
44
 
45
        return helper::render_tourname_inplace_editable($tour);
46
    } else if ($itemtype === 'tourdescription') {
47
        $tour = helper::get_tour($itemid);
48
        $tour->set_description($newvalue)->persist();
49
 
50
        return helper::render_tourdescription_inplace_editable($tour);
51
    } else if ($itemtype === 'tourenabled') {
52
        $tour = helper::get_tour($itemid);
53
        $tour->set_enabled(!!$newvalue)->persist();
54
        return helper::render_tourenabled_inplace_editable($tour);
55
    } else if ($itemtype === 'stepname') {
56
        $step = helper::get_step($itemid);
57
        $step->set_title($newvalue)->persist();
58
 
59
        return helper::render_stepname_inplace_editable($step);
60
    }
61
}
62
 
63
/**
64
 * Extend the user navigation to bootstrap tours.
65
 */
66
function tool_usertours_extend_navigation_user() {
67
    \tool_usertours\helper::bootstrap();
68
}
69
 
70
/**
71
 * Map icons for font-awesome themes.
72
 */
73
function tool_usertours_get_fontawesome_icon_map() {
74
    return [
75
        'tool_usertours:t/export' => 'fa-download',
76
        'tool_usertours:i/reload' => 'fa-refresh',
77
        'tool_usertours:t/filler' => 'fa-spacer',
78
    ];
79
}
80
 
81
 
82
/**
83
 * Serves any files associated with the user tour content.
84
 *
85
 * @param stdClass $course Course object
86
 * @param stdClass $cm Course module object
87
 * @param context $context Context
88
 * @param string $filearea File area for data privacy
89
 * @param array $args Arguments
90
 * @param bool $forcedownload If we are forcing the download
91
 * @param array $options More options
92
 * @return bool Returns false if we don't find a file.
93
 */
94
function tool_usertours_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []): bool {
95
    if ($context->contextlevel != CONTEXT_SYSTEM) {
96
        return false;
97
    }
98
 
99
    $fs = get_file_storage();
100
    $file = $fs->get_file($context->id, 'tool_usertours', $filearea, $args[0], '/', $args[1]);
101
    if (!$file) {
102
        return false; // No such file.
103
    }
104
    send_stored_file($file, null, 0, $forcedownload, $options);
105
    return true;
106
}