-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathview.php
143 lines (127 loc) · 5.22 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
<?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/>.
/**
* Prints a particular instance of mediagallery
*
* @package mod_mediagallery
* @copyright NetSpot Pty Ltd
* @author Adam Olley <[email protected]>
* @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');
$id = optional_param('id', 0, PARAM_INT); // A course_module id.
$m = optional_param('m', 0, PARAM_INT); // A mediagallery id.
$g = optional_param('g', 0, PARAM_INT); // A mediagallery_gallery id.
$action = optional_param('action', 'viewcollection', PARAM_ALPHA);
$page = optional_param('page', 0, PARAM_INT);
$focus = optional_param('focus', null, PARAM_INT);
$editing = optional_param('editing', false, PARAM_BOOL);
$forcesync = optional_param('sync', false, PARAM_BOOL);
$viewcontrols = 'gallery';
$gallery = false;
$mediasize = get_user_preferences('mod_mediagallery_mediasize', \mod_mediagallery\output\gallery\renderable::MEDIASIZE_MD);
$options = array(
'focus' => $focus,
'mediasize' => $mediasize,
'editing' => $editing,
'page' => $page,
'action' => $action,
'viewcontrols' => $viewcontrols,
);
if ($g) {
$gallery = new \mod_mediagallery\gallery($g, $options);
$gallery->sync($forcesync);
$options['action'] = 'viewgallery';
$m = $gallery->instanceid;
$options['viewcontrols'] = 'item';
$mediagallery = $gallery->get_collection();
$course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST);
$cm = $mediagallery->cm;
} else if ($id) {
$cm = get_coursemodule_from_id('mediagallery', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$mediagallery = new \mod_mediagallery\collection($cm->instance);
} else if ($m) {
$mediagallery = new \mod_mediagallery\collection($m);
$course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('mediagallery', $mediagallery->id, $course->id, false, MUST_EXIST);
} else {
throw new \moodle_exception('missingparameter');
}
// The single collection type was contributed by github user eSrem.
// It is not officially supported by UNSW.
if ($mediagallery->colltype == "single") {
switch($mediagallery->count_galleries()) {
case 0:
// Redirect to adding a gallery.
redirect(new moodle_url('/mod/mediagallery/gallery.php', array('m' => $mediagallery->id)));
break;
case 1:
$galleries = $mediagallery->get_visible_galleries();
$gallery = reset($galleries);
$options['action'] = 'viewgallery';
$options['viewcontrols'] = 'item';
break;
default: // More than one, delete others.
throw new \moodle_exception('toomany', 'mod_mediagallery');
break;
}
}
$context = context_module::instance($cm->id);
// Request update from theBox (does nothing if synced within the past hour).
if (!$gallery) {
$mediagallery->sync($forcesync);
}
if ($mediagallery->was_deleted()) {
$coursecontext = $context->get_course_context();
$pageurl = new moodle_url('/mod/mediagallery/view.php');
$PAGE->set_context($coursecontext);
$PAGE->set_pagelayout('incourse');
$PAGE->set_url($pageurl);
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('collectionwasdeleted', 'mediagallery'));
echo $OUTPUT->footer();
exit;
}
$PAGE->set_cm($cm, $course);
$canedit = $gallery && $gallery->user_can_contribute();
if ($mediagallery->is_read_only() || !$canedit) {
$options['editing'] = false;
}
if ($gallery) {
$pageurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $g, 'page' => $page));
if ($options['editing']) {
$pageurl->param('editing', true);
}
} else {
$pageurl = new moodle_url('/mod/mediagallery/view.php', array('id' => $cm->id));
}
$PAGE->set_url($pageurl);
require_login($course, true, $cm);
if ($gallery && $mediagallery->colltype != "single") {
$navnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY);
if (empty($navnode)) {
$navnode = $PAGE->navbar;
}
$navurl = clone $pageurl;
$navurl->remove_params('editing');
$node = $navnode->add(format_string($gallery->name), $navurl);
$node->make_active();
}
$controller = new \mod_mediagallery\viewcontroller($context, $cm, $course, $mediagallery, $gallery, $pageurl, $options);
echo $controller->display_action($options['action']);