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
 * unilabel type topic teaser.
19
 *
20
 * @package     unilabeltype_topicteaser
21
 * @author      Andreas Grabs <info@grabs-edv.de>
22
 * @copyright   2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @param mixed $course
25
 * @param mixed $cm
26
 * @param mixed $context
27
 * @param mixed $filearea
28
 * @param mixed $args
29
 * @param mixed $forcedownload
30
 */
31
 
32
/**
33
 * Send files provided by this plugin.
34
 *
35
 * @param  \stdClass $course
36
 * @param  \stdClass $cm
37
 * @param  \context  $context
38
 * @param  string    $filearea
39
 * @param  array     $args
40
 * @param  bool      $forcedownload
41
 * @return bool
42
 */
43
function unilabeltype_topicteaser_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
44
    $itemid       = (int) array_shift($args);
45
    $relativepath = implode('/', $args);
46
 
47
    // We switch the given component "unilabeltype_topicteaser" with the original "course".
48
    $fullpath = "/{$context->id}/course/$filearea/{$itemid}/$relativepath";
49
 
50
    $fs = get_file_storage();
51
    if ($file = $fs->get_file_by_hash(sha1($fullpath))) {
52
        if (!$file->is_directory()) {
53
            send_stored_file($file, 0, 0, true); // Download MUST be forced - security!
54
        }
55
    }
56
 
57
    return false;
58
}
59
 
60
/**
61
 * Fragment api hook to load the section content by ajax.
62
 *
63
 * @param  object|array      $args
64
 * @throws \moodle_exception
65
 * @return string            the html output of the section
66
 */
67
function unilabeltype_topicteaser_output_fragment_section($args) {
68
    global $DB;
69
    $args = (object) $args;
70
    /** @var \context $context */
71
    $context = $args->context;
72
    if (!has_capability('mod/unilabel:view', $context)) {
73
        return '';
74
    }
75
    if ($context->contextlevel != CONTEXT_COURSE) {
76
        throw new \moodle_exception('wrong context');
77
    }
78
    if (empty($args->sectionid)) {
79
        throw new \moodle_exception('missing sectionid');
80
    }
81
    if (!$section = $DB->get_record('course_sections', ['id' => $args->sectionid])) {
82
        throw new \moodle_exception('wrong sectionid');
83
    }
84
 
85
    return \unilabeltype_topicteaser\content_type::get_sections_content($context->instanceid, $section->section);
86
}