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 contentbank
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 contentbank extends course_file {
29
    /**
30
     * Show the name of the file as it appears in content bank
31
     *
32
     * @return string
33
     * @throws \dml_exception
34
     */
35
    protected function get_displayed_filename(): string {
36
        global $DB;
37
        $cb = $DB->get_record('contentbank_content', ['id' => $this->file->itemid]);
38
        return $cb->name;
39
    }
40
 
41
    /**
42
     * Try to get the download url for a file.
43
     *
44
     * @return null|\moodle_url
45
     * @throws \moodle_exception
46
     */
47
    protected function get_file_download_url(): ?\moodle_url {
48
        return $this->get_standard_file_download_url();
49
    }
50
 
51
    /**
52
     * Try to get the url for the component (module or course).
53
     *
54
     * @return null|\moodle_url
55
     * @throws \moodle_exception
56
     */
57
    protected function get_component_url(): ?\moodle_url {
58
        return new \moodle_url('/contentbank/index.php', ['contextid' => $this->file->contextid]);
59
    }
60
 
61
    /**
62
     * Not checking content bank
63
     *
64
     * @return null
65
     * @throws \moodle_exception
66
     */
67
    protected function is_file_used(): ?bool {
68
        $fs = new \file_storage();
69
        $f = new \stored_file($fs, $this->file);
70
        return $fs->get_references_count_by_storedfile($f) > 1;
71
    }
72
}