Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
43 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
namespace local_listcoursefiles\components;
18
 
19
use local_listcoursefiles\course_file;
20
 
21
/**
22
 * Class course
23
 * @package local_listcoursefiles
24
 * @author Jeremy FitzPatrick
25
 * @copyright 2022 Te Wānanga o Aotearoa
26
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class course extends course_file {
29
    /**
30
     * Try to get the download url for a file.
31
     *
32
     * @return null|\moodle_url
33
     * @throws \moodle_exception
34
     */
35
    protected function get_file_download_url(): ?\moodle_url {
36
        switch ($this->file->filearea) {
37
            case 'section':
38
                return $this->get_standard_file_download_url();
39
            case 'legacy':
40
                return new \moodle_url('/file.php/' . $this->courseid . $this->file->filepath . $this->file->filename);
41
            case 'overviewfiles':
42
                return $this->get_standard_file_download_url(false);
43
            default:
44
                return parent::get_file_download_url();
45
        }
46
    }
47
 
48
    /**
49
     * Try to get the url for the component (module or course).
50
     *
51
     * @return null|\moodle_url
52
     * @throws \moodle_exception
53
     */
54
    protected function get_component_url(): ?\moodle_url {
55
        if ($this->file->component === 'contentbank') {
56
            return new \moodle_url('/contentbank/index.php', ['contextid' => $this->file->contextid]);
57
        }
58
        if ($this->file->filearea === 'section') {
59
            return new \moodle_url('/course/view.php', ['id' => $this->courseid, 'sectionid' => $this->file->itemid]);
60
        }
61
        return new \moodle_url('/course/info.php', ['id' => $this->courseid]);
62
    }
63
 
64
    /**
65
     * Creates the URL for the editor where the file is added
66
     *
67
     * @return \moodle_url|null
68
     * @throws \moodle_exception
69
     */
70
    protected function get_edit_url(): ?\moodle_url {
71
        if ($this->file->filearea === 'section') {
72
            return new \moodle_url('/course/editsection.php?', ['id' => $this->file->itemid]);
73
        }
74
        if ($this->file->filearea === 'overviewfiles' || $this->file->filearea === 'summary') {
75
            return new \moodle_url('/course/edit.php?', ['id' => $this->courseid]);
76
        }
77
        return parent::get_edit_url();
78
    }
79
 
80
    /**
81
     * Checks if embedded files have been used
82
     *
83
     * @return bool|null
84
     * @throws \dml_exception
85
     */
86
    protected function is_file_used(): ?bool {
87
        global $DB;
88
        switch ($this->file->filearea) {
89
            case 'section':
90
                $section = $DB->get_record('course_sections', ['id' => $this->file->itemid]);
91
                return $this->is_embedded_file_used($section, 'summary', $this->file->filename);
92
            case 'overviewfiles':
93
                return true;
94
            case 'summary':
95
                $course = $DB->get_record('course', ['id' => $this->courseid]);
96
                return $this->is_embedded_file_used($course, 'summary', $this->file->filename);
97
            default:
98
                return parent::is_file_used();
99
        }
100
    }
101
}