-
Notifications
You must be signed in to change notification settings - Fork 8
/
view.php
117 lines (98 loc) · 4.14 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Main plugin entry point.
*
* @package mod_collabora
* @copyright 2019 Davo Smith, Synergy Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
global $PAGE, $DB, $USER;
$cmid = required_param('id', PARAM_INT);
$loadcurrentfile = optional_param('loadcurrentfile', false, PARAM_BOOL);
$loadversion = optional_param('loadversion', false, PARAM_INT); // The version is the timemodified timestamp.
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'collabora');
$PAGE->set_url('/mod/collabora/view.php', ['id' => $cm->id]);
require_login($course, false, $cm);
require_capability('mod/collabora:view', $PAGE->context);
// Completion.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Handle groups selection.
$groupid = \mod_collabora\util::get_current_groupid_from_cm($cm);
$collabora = $DB->get_record('collabora', ['id' => $cm->instance], '*', MUST_EXIST);
// Trigger course_module_viewed event.
\mod_collabora\event\course_module_viewed::trigger_from_course_cm($course, $cm, $collabora);
// Load the collabora details for this page.
$collaborafs = new \mod_collabora\api\collabora_fs($collabora, $PAGE->context, $groupid, $USER->id);
if ($loadcurrentfile) {
require_capability('mod/collabora:directdownload', $PAGE->context);
$collaborafs->send_groupfile();
die;
}
// Load the version file only if activated.
if (!$collaborafs->use_versions()) {
if (!empty($loadversion)) {
require_capability('mod/collabora:manageversions', $PAGE->context);
$collaborafs->send_version_file($loadversion);
die;
}
}
if ($collaborafs->process_lock_unlock()) {
redirect($PAGE->url); // If the locking is changed we have to reload the page.
}
// Set up the page.
$PAGE->set_title($collabora->name);
$PAGE->set_heading($course->fullname);
$aspopup = false;
if ($collabora->display === \mod_collabora\util::DISPLAY_NEW) {
$PAGE->set_pagelayout('embedded');
$aspopup = true;
}
$opts = [
'id' => $collabora->id,
'contextid' => $PAGE->context->id,
'collaboraurl' => $collaborafs->get_collabora_url()->out(),
'origincollabora' => $collaborafs->get_collabora_origin(),
'originmoodle' => $collaborafs->get_moodle_origin(),
'courseurl' => (new moodle_url('/course/view.php', ['id' => $course->id]))->out(),
'aspopup' => $aspopup,
'iframeid' => 'collaboraiframe_' . $collabora->id,
'versionviewerid' => 'version_viewer_' . $collabora->id,
'versionmanager' => has_capability('mod/collabora:manageversions', $cm->context),
'strback' => get_string('back'),
'imgbackurl' => $CFG->wwwroot . '/mod/collabora/pix/go_back.svg',
'uimode' => $collaborafs->get_ui_mode(),
];
$PAGE->requires->js_call_amd('mod_collabora/postmessage', 'init', [$opts]);
// Decide whether or not we show the description.
if ($PAGE->pagelayout == 'embedded' || !$collaborafs->display_description() || !trim(strip_tags($collabora->intro))) {
$PAGE->activityheader->set_attrs(['description' => '']);
}
/** @var \mod_collabora\output\renderer $renderer */
$renderer = $PAGE->get_renderer('mod_collabora');
// Start the output.
echo $renderer->header();
// Main iframe (or warning message, if no groups available).
$widget = new \mod_collabora\output\content(
$cm,
$collabora,
$collaborafs,
$groupid
);
echo $renderer->render($widget);
echo $renderer->footer();