1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of local_downloadcenter for 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 |
* Download center plugin
|
|
|
19 |
*
|
|
|
20 |
* @package local_downloadcenter
|
|
|
21 |
* @author Simeon Naydenov (moniNaydenov@gmail.com)
|
|
|
22 |
* @copyright 2020 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
require_once(__DIR__ . '/../../config.php');
|
|
|
28 |
require_once(__DIR__ . '/locallib.php');
|
|
|
29 |
require_once(__DIR__ . '/download_form.php');
|
|
|
30 |
|
|
|
31 |
// Raise timelimit as this could take a while for big archives.
|
|
|
32 |
core_php_time_limit::raise();
|
|
|
33 |
raise_memory_limit(MEMORY_HUGE);
|
|
|
34 |
|
|
|
35 |
$courseid = required_param('courseid', PARAM_INT);
|
|
|
36 |
|
|
|
37 |
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
|
|
|
38 |
|
|
|
39 |
require_course_login($course);
|
|
|
40 |
|
|
|
41 |
$context = context_course::instance($course->id);
|
|
|
42 |
|
|
|
43 |
require_capability('local/downloadcenter:view', $context);
|
|
|
44 |
|
|
|
45 |
$PAGE->set_url(new moodle_url('/local/downloadcenter/index.php', array('courseid' => $course->id)));
|
|
|
46 |
|
|
|
47 |
$PAGE->set_pagelayout('incourse');
|
|
|
48 |
$PAGE->add_body_class('limitedwidth');
|
|
|
49 |
|
|
|
50 |
$downloadcenter = new local_downloadcenter_factory($course, $USER);
|
|
|
51 |
|
|
|
52 |
$userresources = $downloadcenter->get_resources_for_user();
|
|
|
53 |
|
|
|
54 |
$PAGE->requires->js_call_amd('local_downloadcenter/modfilter', 'init', $downloadcenter->get_js_modnames());
|
|
|
55 |
|
|
|
56 |
$downloadform = new local_downloadcenter_download_form(null,
|
|
|
57 |
['res' => $userresources],
|
|
|
58 |
'post',
|
|
|
59 |
'',
|
|
|
60 |
['data-double-submit-protection' => 'off']);
|
|
|
61 |
|
|
|
62 |
$PAGE->set_title(get_string('navigationlink', 'local_downloadcenter') . ': ' . $course->fullname);
|
|
|
63 |
$PAGE->set_heading($course->fullname);
|
|
|
64 |
|
|
|
65 |
if ($data = $downloadform->get_data()) {
|
|
|
66 |
|
|
|
67 |
$event = \local_downloadcenter\event\zip_downloaded::create(array(
|
|
|
68 |
'objectid' => $PAGE->course->id,
|
|
|
69 |
'context' => $PAGE->context,
|
|
|
70 |
));
|
|
|
71 |
$event->add_record_snapshot('course', $PAGE->course);
|
|
|
72 |
$event->trigger();
|
|
|
73 |
|
|
|
74 |
$downloadcenter->parse_form_data($data);
|
|
|
75 |
$hash = $downloadcenter->create_zip();
|
|
|
76 |
} else if ($downloadform->is_cancelled()) {
|
|
|
77 |
redirect(new moodle_url('/course/view.php', array('id' => $course->id)));
|
|
|
78 |
die;
|
|
|
79 |
} else {
|
|
|
80 |
$event = \local_downloadcenter\event\plugin_viewed::create(array(
|
|
|
81 |
'objectid' => $PAGE->course->id,
|
|
|
82 |
'context' => $PAGE->context,
|
|
|
83 |
));
|
|
|
84 |
$event->add_record_snapshot('course', $PAGE->course);
|
|
|
85 |
$event->trigger();
|
|
|
86 |
echo $OUTPUT->header();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
echo $OUTPUT->heading(get_string('navigationlink', 'local_downloadcenter'), 1);
|
|
|
90 |
|
|
|
91 |
$downloadform->display();
|
|
|
92 |
|
|
|
93 |
echo $OUTPUT->footer();
|