forked from marxjohnson/moodle-mod_pcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
254 lines (190 loc) · 8.73 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?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 pcast
*
* You can have a rather longer description of the file as well,
* if you like, and it can span multiple lines.
*
* @package mod_pcast
* @copyright 2010 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->libdir . '/completionlib.php');
$id = optional_param('id', 0, PARAM_INT); // course_module ID.
// COPIED FROM GLOSSARY
$mode = optional_param('mode', PCAST_STANDARD_VIEW, PARAM_ALPHANUM); // term entry cat date letter search author approval
$hook = optional_param('hook', 'ALL', PARAM_CLEAN); // the term, entry, cat, etc... to look for based on mode
$sortkey = optional_param('sortkey', '', PARAM_ALPHANUM); // Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME...
$sortorder = optional_param('sortorder', 'asc', PARAM_ALPHA); // it defines the order of the sorting (ASC or DESC)
$page = optional_param('page', 0,PARAM_INT); // Page to show (for paging purposes)
// END COPY
if ($id) {
$cm = get_coursemodule_from_id('pcast', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$pcast = $DB->get_record('pcast', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
print_error('invalidcmorid', 'pcast');
}
require_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/pcast:view',$context);
add_to_log($course->id, 'pcast', 'view', "view.php?id=$cm->id", $pcast->name, $cm->id);
/// Mark as viewed
$completion=new completion_info($course);
$completion->set_module_viewed($cm);
/// Print the page header
$PAGE->set_url('/mod/pcast/view.php', array('id' => $cm->id, 'mode'=>$mode));
$PAGE->set_title($pcast->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_context($context);
// Output starts here
echo $OUTPUT->header();
//Set Up Groups
$groupmode = groups_get_activity_groupmode($cm);
if($groupmode) {
groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, new moodle_url('/mod/pcast/view.php',array('id'=>$id)));
}
echo $OUTPUT->heading_with_help(get_string("viewpcast","pcast",$pcast->name), 'pcast' ,'pcast', 'icon');
/// Show the add entry button if allowed (usercan post + write or manage caps)
if (((has_capability('mod/pcast:write', $context))and ($pcast->userscanpost)) or (has_capability('mod/pcast:manage', $context))) {
$url = new moodle_url('/mod/pcast/edit.php', array('cmid'=>$cm->id));
$out = html_writer::start_tag('div',array('class'=>'pcast-addentry')). "\n";
$out .= html_writer::start_tag('form',array('id'=>'newentryform','method'=>'get', 'action'=>$url)). "\n";
$out .= html_writer::start_tag('div',array('class'=>'singlebutton')). "\n";
$out .= html_writer::empty_tag('input',array('type'=>'hidden','name'=>'cmid','value'=>$cm->id)). "\n";
$out .= html_writer::empty_tag('input',array('type'=>'submit','value'=>get_string('addnewepisode', 'pcast'))). "\n";
$out .= html_writer::end_tag('div'). "\n";
$out .= html_writer::end_tag('form'). "\n";
$out .= html_writer::end_tag('div'). "\n";
$out .= html_writer::empty_tag('br'). "\n";
echo $out;
}
// Print heading and tabs
// *************************************************************************
//Sorting info
if (!isset($sortorder)) {
$sortorder = '';
}
if (!isset($sortkey)) {
$sortkey = '';
}
//make sure variables are properly cleaned
$sortkey = clean_param($sortkey, PARAM_ALPHANUM);// Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME...
$sortorder = clean_param($sortorder, PARAM_ALPHA); // it defines the order of the sorting (ASC or DESC)
$tabrows = array();
$browserow = array();
$url = new moodle_url('/mod/pcast/view.php', array('id'=>$id, 'mode'=>PCAST_STANDARD_VIEW));
$browserow[] = new tabobject(PCAST_STANDARD_VIEW, $url, get_string('standardview', 'pcast'));
if($pcast->userscancategorize) {
$url = new moodle_url('/mod/pcast/view.php', array('id'=>$id, 'mode'=>PCAST_CATEGORY_VIEW));
$browserow[] = new tabobject(PCAST_CATEGORY_VIEW, $url, get_string('categoryview', 'pcast'));
}
$url = new moodle_url('/mod/pcast/view.php', array('id'=>$id, 'mode'=>PCAST_DATE_VIEW));
$browserow[] = new tabobject(PCAST_DATE_VIEW, $url, get_string('dateview', 'pcast'));
if($pcast->displayauthor or has_capability('mod/pcast:manage', $context)) {
$url = new moodle_url('/mod/pcast/view.php', array('id'=>$id, 'mode'=>PCAST_AUTHOR_VIEW));
$browserow[] = new tabobject(PCAST_AUTHOR_VIEW, $url, get_string('authorview', 'pcast'));
}
if (has_capability('mod/pcast:approve', $context)) {
$url = new moodle_url('/mod/pcast/view.php', array('id'=>$id, 'mode'=>PCAST_APPROVAL_VIEW));
$browserow[] = new tabobject(PCAST_APPROVAL_VIEW, $url, get_string('approvalview', 'pcast'));
}
/// Put all this info together
$tabrows[] = $browserow; // Always put these at the top
echo html_writer::start_tag('div',array('class'=>'pcastdisplay')). "\n";
print_tabs($tabrows, $mode);
echo html_writer::end_tag('div'). "\n";
if (!isset($category)) {
$category = "";
}
// Check to see if any content should be displayed (prevents guessing of URLs)
if((!$pcast->userscancategorize) and ($mode == PCAST_CATEGORY_VIEW)) {
print_error('errorinvalidmode','pcast');
} else if((!$pcast->displayauthor and !has_capability('mod/pcast:manage', $context)) and ($mode == PCAST_AUTHOR_VIEW)) {
print_error('errorinvalidmode','pcast');
} else if ((!has_capability('mod/pcast:approve', $context)) and ($mode == PCAST_APPROVAL_VIEW)) {
print_error('errorinvalidmode','pcast');
}
switch ($mode) {
case PCAST_CATEGORY_VIEW:
pcast_print_categories_menu($cm, $pcast, $hook);
break;
case PCAST_APPROVAL_VIEW:
if (!$sortkey) {
$sortkey = PCAST_DATE_CREATED;
}
if (!$sortorder) {
$sortorder = 'asc';
}
pcast_print_approval_menu($cm, $pcast, $mode, $hook, $sortkey, $sortorder);
break;
case PCAST_AUTHOR_VIEW:
if (!$sortkey) {
$sortkey = PCAST_AUTHOR_LNAME;
}
if (!$sortorder) {
$sortorder = 'asc';
}
pcast_print_author_menu($cm, $pcast, $mode, $hook, $sortkey, $sortorder);
break;
case PCAST_DATE_VIEW:
if (!$sortkey) {
$sortkey = PCAST_DATE_UPDATED;
}
if (!$sortorder) {
$sortorder = 'desc';
}
pcast_print_date_menu($cm, $pcast, $mode, $hook, $sortkey, $sortorder);
break;
case PCAST_STANDARD_VIEW:
default:
pcast_print_alphabet_menu($cm, $pcast, $mode, $hook, $sortkey, $sortorder);
break;
}
echo html_writer::empty_tag('hr'). "\n";
//**************************************************************************
// Print the main part of the page (The content)
echo html_writer::start_tag('div',array('id'=>'pcast-view','class'=>'generalbox')). "\n";
echo html_writer::start_tag('div',array('class'=>'generalboxcontent')). "\n";
/// Next print the list of episodes
switch($mode) {
case PCAST_STANDARD_VIEW:
pcast_display_standard_episodes($pcast, $cm, $groupmode, $hook, $sortkey, $sortorder);
break;
case PCAST_CATEGORY_VIEW:
pcast_display_category_episodes($pcast, $cm, $groupmode, $hook);
break;
case PCAST_DATE_VIEW:
pcast_display_date_episodes($pcast, $cm, $groupmode, $hook, $sortkey, $sortorder);
break;
case PCAST_AUTHOR_VIEW:
pcast_display_author_episodes($pcast, $cm, $groupmode, $hook, $sortkey, $sortorder);
break;
case PCAST_APPROVAL_VIEW:
pcast_display_approval_episodes($pcast, $cm, $groupmode, $hook, $sortkey, $sortorder);
break;
default:
pcast_display_standard_episodes($pcast, $cm, $groupmode, $hook, $sortkey, $sortorder);
break; }
echo html_writer::end_tag('div'). "\n";
echo html_writer::end_tag('div'). "\n";
// Finish the page
echo $OUTPUT->footer();