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 |
* List all files in a course.
|
|
|
19 |
*
|
|
|
20 |
* @package local_listcoursefiles
|
|
|
21 |
* @copyright 2017 Martin Gauk (@innoCampus, TU Berlin)
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once(dirname(__FILE__) . '/../../config.php');
|
|
|
26 |
|
|
|
27 |
$courseid = required_param('courseid', PARAM_INT);
|
|
|
28 |
$page = optional_param('page', 0, PARAM_INT);
|
|
|
29 |
$limit = optional_param('limit', 200, PARAM_INT);
|
|
|
30 |
if ($page < 0) {
|
|
|
31 |
$page = 0;
|
|
|
32 |
}
|
|
|
33 |
if ($limit < 1 || $limit > local_listcoursefiles\course_files::MAX_FILES) {
|
|
|
34 |
$limit = local_listcoursefiles\course_files::MAX_FILES;
|
|
|
35 |
}
|
|
|
36 |
$component = optional_param('component', 'all_wo_submissions', PARAM_ALPHANUMEXT);
|
|
|
37 |
$filetype = optional_param('filetype', 'all', PARAM_ALPHAEXT);
|
|
|
38 |
$action = optional_param('action', '', PARAM_ALPHAEXT);
|
|
|
39 |
$chosenfiles = optional_param_array('file', [], PARAM_INT);
|
|
|
40 |
|
|
|
41 |
$context = context_course::instance($courseid);
|
|
|
42 |
$title = get_string('pluginname', 'local_listcoursefiles');
|
|
|
43 |
$url = new moodle_url(
|
|
|
44 |
'/local/listcoursefiles/index.php',
|
|
|
45 |
[
|
|
|
46 |
'courseid' => $courseid,
|
|
|
47 |
'page' => $page,
|
|
|
48 |
'limit' => $limit,
|
|
|
49 |
'component' => $component,
|
|
|
50 |
'filetype' => $filetype,
|
|
|
51 |
],
|
|
|
52 |
);
|
|
|
53 |
$PAGE->set_context($context);
|
|
|
54 |
$PAGE->set_title($title);
|
|
|
55 |
$PAGE->set_heading($title);
|
|
|
56 |
$PAGE->set_url($url);
|
|
|
57 |
$PAGE->set_pagelayout('incourse');
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
require_login($courseid);
|
|
|
61 |
require_capability('local/listcoursefiles:view', $context);
|
|
|
62 |
$changelicenseallowed = has_capability('local/listcoursefiles:change_license', $context);
|
|
|
63 |
$downloadallowed = has_capability('local/listcoursefiles:download', $context);
|
|
|
64 |
|
|
|
65 |
$files = new local_listcoursefiles\course_files($courseid, $context, $component, $filetype);
|
|
|
66 |
|
|
|
67 |
if ($action === 'change_license' && $changelicenseallowed) {
|
|
|
68 |
require_sesskey();
|
|
|
69 |
$license = required_param('license', PARAM_ALPHAEXT);
|
|
|
70 |
try {
|
|
|
71 |
$files->set_files_license($chosenfiles, $license);
|
|
|
72 |
} catch (moodle_exception $e) {
|
|
|
73 |
\core\notification::add($e->getMessage(), \core\output\notification::NOTIFY_ERROR);
|
|
|
74 |
}
|
|
|
75 |
} else if ($action === 'download' && $downloadallowed) {
|
|
|
76 |
require_sesskey();
|
|
|
77 |
try {
|
|
|
78 |
$files->download_files($chosenfiles);
|
|
|
79 |
} catch (moodle_exception $e) {
|
|
|
80 |
\core\notification::add($e->getMessage(), \core\output\notification::NOTIFY_ERROR);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$filelist = $files->get_file_list($page * $limit, $limit);
|
|
|
85 |
$renderer = $PAGE->get_renderer('local_listcoursefiles');
|
|
|
86 |
|
|
|
87 |
echo $OUTPUT->header();
|
|
|
88 |
echo $renderer->overview_page($url, $files, $page, $limit, $filelist, $changelicenseallowed, $downloadallowed);
|
|
|
89 |
echo $OUTPUT->footer();
|