-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
168 lines (145 loc) · 6.44 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?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 activity view
*
* @package mod
* @subpackage googlecollab
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/locallib.php');
$cmid = $id = optional_param('id', 0, PARAM_INT);
$currentgroup = optional_param('group', 0, PARAM_INT); // Group ID
$cm = get_coursemodule_from_id('googlecollab', $id, 0, false, MUST_EXIST);
$googlecollab = googlecollab::get_instance($cm->instance);
$PAGE->set_url('/mod/googlecollab/view.php', array('id' => $googlecollab->cm->id));
$PAGE->set_title($googlecollab->googlecollab->name);
$PAGE->set_heading($googlecollab->course->shortname);
$PAGE->requires->js_init_call('M.googlecollab.viewresizer',
array(), true, googlecollab_get_js_module());
$PAGE->set_button(update_module_button($googlecollab->cm->id, $googlecollab->course->id,
get_string('modulename', 'googlecollab')));
echo $OUTPUT->header();
$groupmode = groups_get_activity_groupmode($cm);
//all participants is groupid 0 ....careful
if (empty($currentgroup)) {
$currentgroup = groups_get_activity_group($cm, true);
$currentgroup = !empty($currentgroup) ? $currentgroup : 0;
}
$docid = $googlecollab->getdocref($currentgroup);//ID of doc for this activity
echo $googlecollab->renderer->render_group_selector($googlecollab, $currentgroup);
echo $googlecollab->renderer->render_activity_heading($googlecollab->googlecollab->name);
echo $googlecollab->renderer->render_intro($googlecollab->googlecollab->intro);
$showsharedoc = false;//Set true to show the interactive shared doc
$checkcap = false;//Set to true to check cap on read only view
$loginfo = 'viewdoc';
if ($groupmode == NOGROUPS) {
$showsharedoc = true;//Default is everyone gets the proper doc
} else if ($groupmode == SEPARATEGROUPS) {
$showsharedoc = groups_is_member($currentgroup, $USER->id);
$checkcap = true;//Check cap when looking at other groups
} else if ($groupmode == VISIBLEGROUPS) {
$showsharedoc = groups_is_member($currentgroup, $USER->id);
}
//If group is 0 check for special case when google groups on
if ($currentgroup === 0) {
if ($googlecollab->siteconfig->gappgroups == googlecollab::GROUPMODE_ON) {
$showsharedoc = false;//only interact if in special course group
//If group mode is on we need a course group for the doc sharing
if ($groupid = groups_get_group_by_name($googlecollab->course->id,
$googlecollab->get_moodle_course_group_name())) {
//Course group exists if user is in this show shared doc
if (groups_is_member($groupid)) {
$showsharedoc = true;
}
}
}
}
//Code to control what the user sees
if ($showsharedoc &&
has_capability('mod/googlecollab:viewdoc', $googlecollab->modcontext)) {
if (empty($docid)) {
//Create doc and share with group or individual
//TODO - should this always happen - or only for some?
$docid = $googlecollab->create_document($currentgroup, $USER->id);
if (empty($docid)) {
throw new moodle_exception('googleerror', 'googlecollab');
}
}
//Share doc...
$sharingid = $googlecollab->get_sharing_name($currentgroup);
if (!$shared = $googlecollab->add_sharing_on_the_fly($docid, $sharingid)) {
//Sharing failed show error and show read only ver
echo $OUTPUT->notification(get_string('sharingerror', 'googlecollab'));
}
$sharingurl = $googlecollab->get_sharing_link($docid);
if (empty($sharingurl)) {
throw new moodle_exception('googleerror', 'googlecollab');
}
$readingurl = $googlecollab->get_reading_link($docid);
$usercheck = $googlecollab->check_user_in_google();
// Show doc with/without editing link.
if (!$shared || !$usercheck) {
// Show the read only instead.
echo $googlecollab->renderer->documentreader($readingurl);
$loginfo = 'viewreaddoc';
} else {
echo $googlecollab->renderer->render_gdoc_link($sharingurl);
echo $googlecollab->renderer->documentreader($readingurl);
}
} else {
//Show read only doc
if ($checkcap) {
if (!has_capability('mod/googlecollab:viewall', $googlecollab->modcontext) &&
!has_capability('moodle/site:accessallgroups', $googlecollab->modcontext)) {
//Neither capability
echo $googlecollab->renderer->nopermissionsondoc();
} else {
$checkcap = false;
}
}
if (!$checkcap) {//Note shouldn't be else if check cap is reset/off
if (empty($docid)) {
echo $googlecollab->renderer->documentnotavailable();
$loginfo = 'viewnodoc';
} else {
//admin/tutor might need to get to actual doc but not be in group
//In some instances we've already checked these above - do again anyway
if (has_capability('mod/googlecollab:viewall', $googlecollab->modcontext) ||
has_capability('moodle/site:accessallgroups', $googlecollab->modcontext)) {
$sharingurl = $googlecollab->get_sharing_link($docid);
if ($sharingurl) {
echo $googlecollab->renderer->render_gdoc_link($sharingurl);
}
}
$readingurl = $googlecollab->get_reading_link($docid);
echo $googlecollab->renderer->documentreader($readingurl);
$loginfo = 'viewreaddoc';
}
}
}
// Finish the page
echo $OUTPUT->footer();
$params = array(
'context' => $googlecollab->modcontext,
'objectid' => $cm->instance,
'other' => array('loginfo' => $loginfo)
);
$event = \mod_googlecollab\event\course_module_viewed::create($params);
$event->trigger();