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
/**
18
 * Output rendering for the plugin.
19
 *
20
 * @package     local_listcoursefiles
21
 * @copyright   2022 Martin Gauk (@innoCampus, TU Berlin)
22
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
namespace local_listcoursefiles\output;
25
 
26
use moodle_url;
27
use local_listcoursefiles\course_file;
28
use local_listcoursefiles\course_files;
29
use local_listcoursefiles\licences;
30
 
31
/**
32
 * Implements the plugin renderer
33
 *
34
 * @copyright 2022 Martin Gauk (@innoCampus, TU Berlin)
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class renderer extends \plugin_renderer_base {
38
    /**
39
     * Render overview page.
40
     *
41
     * @param moodle_url $url
42
     * @param course_files $files
43
     * @param int $page
44
     * @param int $limit
45
     * @param array $filelist
46
     * @param bool $changelicenseallowed
47
     * @param bool $downloadallowed
48
     * @return string
49
     * @throws \moodle_exception
50
     */
51
    public function overview_page(moodle_url $url, course_files $files, int $page, int $limit,
52
            array $filelist, bool $changelicenseallowed, bool $downloadallowed): string {
53
        $tpldata = new \stdClass();
54
        $tpldata->course_selection_html = $this->get_course_selection($url, $files->get_course_id());
55
        $tpldata->component_selection_html = $this->get_component_selection($url, $files->get_components(),
56
            $files->get_filter_component());
57
        $tpldata->file_type_selection_html = $this->get_file_type_selection($url, $files->get_filter_file_type());
58
        $tpldata->paging_bar_html = $this->output->paging_bar($files->get_file_list_total_size(), $page , $limit, $url);
59
        $tpldata->url = $url;
60
        $tpldata->sesskey = sesskey();
61
        $tpldata->files = [];
62
        $tpldata->files_exist = count($filelist) > 0;
63
        $tpldata->change_license_allowed = $changelicenseallowed;
64
        $tpldata->download_allowed = $downloadallowed;
65
        $licenses = licences::get_available_licenses();
66
        $tpldata->license_select_html = \html_writer::select($licenses, 'license');
67
        foreach ($filelist as $file) {
68
            $tpldata->files[] = course_file::create($file);
69
        }
70
        return $this->render_from_template('local_listcoursefiles/view', $tpldata);
71
    }
72
 
73
    /**
74
     * Builds the course select drop-down menu HTML snippet.
75
     *
76
     * @param moodle_url $url
77
     * @param int $currentcourseid
78
     * @return string
79
     * @throws \coding_exception
80
     */
81
    public function get_course_selection(moodle_url $url, int $currentcourseid): string {
82
        $url = clone $url;
83
        $url->remove_params('courseid', 'page');
84
 
85
        $availcourses = [];
86
        $allcourses = enrol_get_my_courses();
87
        foreach ($allcourses as $course) {
88
            $context = \context_course::instance($course->id, IGNORE_MISSING);
89
            if (has_capability('local/listcoursefiles:view', $context)) {
90
                $availcourses[$course->id] = $course->shortname;
91
            }
92
        }
93
 
94
        return $this->output->single_select($url, 'courseid', $availcourses, $currentcourseid, null, 'courseselector');
95
    }
96
 
97
    /**
98
     * Builds the file component select drop-down menu HTML snippet.
99
     *
100
     * @param moodle_url $url
101
     * @param array $allcomponents
102
     * @param string $currentcomponent
103
     * @return string
104
     */
105
    public function get_component_selection(moodle_url $url, array $allcomponents, string $currentcomponent): string {
106
        $url = clone $url;
107
        $url->remove_params('page');
108
 
109
        return $this->output->single_select($url, 'component', $allcomponents, $currentcomponent, null, 'componentselector');
110
    }
111
 
112
    /**
113
     * Builds the file type select drop-down menu HTML snippet.
114
     *
115
     * @param moodle_url $url
116
     * @param string $currenttype
117
     * @return string
118
     * @throws \coding_exception
119
     */
120
    public function get_file_type_selection(moodle_url $url, string $currenttype): string {
121
        $url = clone $url;
122
        $url->remove_params('page');
123
 
124
        return $this->output->single_select($url, 'filetype', course_files::get_file_types(),
125
            $currenttype, null, 'filetypeselector');
126
    }
127
}