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 mod_feedback
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 mod_feedback 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 'item':
38
            case 'page_after_submit':
39
                return $this->get_standard_file_download_url();
40
            default:
41
                return parent::get_file_download_url();
42
        }
43
    }
44
 
45
    /**
46
     * Creates the URL for the editor where the file is added
47
     *
48
     * @return \moodle_url|null
49
     * @throws \dml_exception
50
     * @throws \moodle_exception
51
     */
52
    protected function get_edit_url(): ?\moodle_url {
53
        global $DB;
54
        switch ($this->file->filearea) {
55
            case 'item':
56
            case 'page_after_submit':
57
                $sql = "SELECT cm.*
58
                          FROM {context} ctx
59
                          JOIN {course_modules} cm ON cm.id = ctx.instanceid
60
                         WHERE ctx.id = ?";
61
                $mod = $DB->get_record_sql($sql, [$this->file->contextid]);
62
                return new \moodle_url('/course/modedit.php?', ['update' => $mod->id]);
63
            default:
64
                return parent::get_edit_url();
65
        }
66
    }
67
 
68
    /**
69
     * Checks if embedded files have been used
70
     *
71
     * @return bool|null
72
     * @throws \dml_exception
73
     */
74
    protected function is_file_used(): ?bool {
75
        // File areas = intro, item, page_after_submit.
76
        global $DB;
77
        switch ($this->file->filearea) {
78
            case 'item':
79
                $item = $DB->get_record('feedback_item', ['id' => $this->file->itemid]);
80
                return $this->is_embedded_file_used($item, 'presentation', $this->file->filename);
81
            case 'page_after_submit':
82
                $sql = "SELECT m.*
83
                          FROM {feedback} m
84
                          JOIN {course_modules} cm ON cm.instance = m.id
85
                          JOIN {context} ctx ON ctx.instanceid = cm.id
86
                         WHERE ctx.id = ?";
87
                $feedback = $DB->get_record_sql($sql, [$this->file->contextid]);
88
                return $this->is_embedded_file_used($feedback, 'page_after_submit', $this->file->filename);
89
            default:
90
                return parent::is_file_used();
91
        }
92
    }
93
}