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_book
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_book 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
        if ($this->file->filearea == 'chapter') {
37
            return $this->get_standard_file_download_url();
38
        }
39
        return parent::get_file_download_url();
40
    }
41
 
42
    /**
43
     * Creates the URL for the editor where the file is added
44
     *
45
     * @return \moodle_url|null
46
     * @throws \dml_exception
47
     * @throws \moodle_exception
48
     */
49
    protected function get_edit_url(): ?\moodle_url {
50
        global $DB;
51
        if ($this->file->filearea === 'chapter') { // Just checking description for now.
52
            $ctx = $DB->get_record('context', ['id' => $this->file->contextid]);
53
            return new \moodle_url('/mod/book/edit.php', ['cmid' => $ctx->instanceid, 'id' => $this->file->itemid]);
54
        }
55
        return parent::get_edit_url();
56
    }
57
 
58
    /**
59
     * Checks if embedded files have been used
60
     *
61
     * @return bool|null
62
     * @throws \dml_exception
63
     */
64
    protected function is_file_used(): ?bool {
65
        // File areas = intro, chapter.
66
        global $DB;
67
        if ($this->file->filearea === 'chapter') {
68
            $chapter = $DB->get_record('book_chapters', ['id' => $this->file->itemid]);
69
            return $this->is_embedded_file_used($chapter, 'content', $this->file->filename);
70
        }
71
        return parent::is_file_used();
72
    }
73
}