forked from learnweb/moodle-mod_collabora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
107 lines (90 loc) · 3.59 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
<?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);
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'collabora');
$rec = $DB->get_record('collabora', ['id' => $cm->instance], '*', MUST_EXIST);
$PAGE->set_url('/mod/collabora/view.php', ['id' => $cm->id]);
require_login($course, false, $cm);
require_capability('mod/collabora:view', $PAGE->context);
// Trigger course_module_viewed event.
\mod_collabora\event\course_module_viewed::trigger_from_course_cm($course, $cm, $rec);
// Completion.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Handle groups selection.
$groupid = groups_get_activity_group($cm, true);
if ($groupid === false) {
$groupid = 0; // No groups, so use id 0 for everyone.
} else if ($groupid === 0) {
// Groups in use, but none currently selected, so we need to find the first available group.
$allgroups = has_capability('moodle/site:accessallgroups', $PAGE->context);
// Start with groups we are a member of.
$allowedgroups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid);
if (!$allowedgroups && ($allgroups || groups_get_activity_groupmode($cm) === VISIBLEGROUPS)) {
// Not a member of any groups, but can see some groups, so get the full list.
$allowedgroups = groups_get_all_groups($cm->course, 0, $cm->groupingid);
}
if (!$allowedgroups) {
// No access to any group - will just display a warning message.
$groupid = -1;
} else {
// Phew ... we found some group(s) we can access, so display the first one.
$firstgroup = reset($allowedgroups);
$groupid = $firstgroup->id;
}
}
// Load the collabora details for this page.
$collabora = new \mod_collabora\collabora($rec, $PAGE->context, $groupid, $USER->id);
if ($loadcurrentfile) {
$collabora->send_groupfile();
die;
}
$collabora->process_lock_unlock();
// Set up the page.
$PAGE->set_title($rec->name);
$PAGE->set_heading($course->fullname);
$closewindow = false;
if ($rec->display === \mod_collabora\collabora::DISPLAY_NEW) {
$PAGE->set_pagelayout('embedded');
$closewindow = true;
}
$opts = [
'courseurl' => (new moodle_url('/course/view.php', ['id' => $course->id]))->out(),
'closewindow' => $closewindow,
];
$PAGE->requires->js_call_amd('mod_collabora/monitorclose', 'init', [$opts]);
$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,
$rec,
$collabora,
$groupid
);
echo $renderer->render($widget);
echo $renderer->footer();