-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlib.php
372 lines (320 loc) · 12 KB
/
lib.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?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/>.
/**
* Version information
*
* @package mod
* @subpackage opencast
* @copyright 2013-2015 Université de Lausanne
* @author [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will create a new instance and return the id number
* of the new instance.
*
* @param object $opencast Moodle {opencast} table DB record
*
* @return int newly created instance ID
*/
function opencast_add_instance($opencast) {
global $DB, $USER;
$opencast->timemodified = time();
$scast = new mod_opencast_series();
if (isset($opencast->newchannelname)) {
$scast->setChannelName($opencast->newchannelname);
}
//$scast->setCourseId();
// $scast->setLicense($opencast->license);
// $scast->setDepartment($opencast->department);
$scast->setAllowAnnotations($opencast->allow_annotations == OPENCAST_ANNOTATIONS);
// if (isset($opencast->template_id)) { // not set if creating new instance with existing channel
// $scast->setTemplateId($opencast->template_id);
// }
$scast->setIvt($opencast->is_ivt);
if (isset($opencast->inviting)) {
$scast->setInvitingPossible($opencast->inviting);
}
$scast->setOrganizationDomain(mod_opencast_series::getOrganizationByEmail($USER->email));
$opencast->organization_domain = $scast->getOrganization();
if ($opencast->channelnew == OPENCAST_CHANNEL_NEW) {
// New channel
$scast->setProducer(mod_opencast_user::getExtIdFromMoodleUserId($USER->id));
$scast->doCreate();
$opencast->ext_id = $scast->getExtId();
}
else {
// Existing channel
$scast->setExtId($opencast->ext_id);
$scast->update();
}
if (empty($opencast->timerestrict)) {
$opencast->timeopen = 0;
$opencast->timeclose = 0;
}
$opencast->id = $DB->insert_record('opencast', $opencast);
$completiontimeexpected = !empty($opencast->completionexpected) ? $opencast->completionexpected : null;
\core_completion\api::update_completion_date_event($opencast->coursemodule, 'opencast', $opencast->id, $completiontimeexpected);
return $opencast->id;
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
*
* @param object $opencast Moodle {opencast} table DB record
*
* @return bool true if everything went well
*/
function opencast_update_instance($opencast) {
global $DB;
$opencast->id = $opencast->instance;
$opencast->timemodified = time();
$scast = new mod_opencast_series();
$scast->fetch($opencast->id);
//$scast->setCourseId();
// $scast->setLicense($opencast->license);
// $scast->setDepartment($opencast->department);
$scast->setAllowAnnotations($opencast->allow_annotations == OPENCAST_ANNOTATIONS);
$scast->setIvt($opencast->is_ivt);
if (!isset($opencast->inviting) || $opencast->is_ivt == false) {
$opencast->inviting = false;
}
$scast->setInvitingPossible($opencast->inviting);
// Existing channel
$scast->setExtId($opencast->ext_id);
$mod_opencast_update = $scast->update();
$opencast->ext_id = $scast->getExtId();
if (empty($opencast->timerestrict)) {
$opencast->timeopen = 0;
$opencast->timeclose = 0;
}
$moodle_update = $DB->update_record('opencast', $opencast);
$completiontimeexpected = !empty($opencast->completionexpected) ? $opencast->completionexpected : null;
\core_completion\api::update_completion_date_event($opencast->coursemodule, 'opencast', $opencast->id, $completiontimeexpected);
return $mod_opencast_update && $moodle_update;
}
/**
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
* @param int $id the ID of the {opencast} DB record
*
* @return bool true if succesful
*/
function opencast_delete_instance($id) {
global $DB;
// make sure plugin instance exists
if (!$opencast = $DB->get_record('opencast', ['id' => $id])) {
return false;
}
// delete all clip members of this plugin instance
if (!$DB->delete_records('opencast_cmember', ['opencastid' => $opencast->id])) {
return false;
}
// delete plugin instance itself
if (!$DB->delete_records('opencast', ['id' => $opencast->id])) {
return false;
}
return true;
}
/**
* Gets a full opencast record
*
* @param int $opencastid the ID of the {opencast} DB record
*
* @return object|bool The {opencast} DB record or false
*/
function opencast_get_opencast($opencastid) {
global $DB;
if ($opencast = $DB->get_record('opencast', ['id' => $opencastid])) {
return $opencast;
}
return false;
}
/**
* Implementation of the function for printing the form elements that control
* whether the course reset functionality affects the opencast.
*
* @param object $mform form passed by reference
*/
function opencast_reset_course_form_definition(&$mform) {
$mform->addElement('header', 'opencastheader', get_string('modulenameplural', 'opencast'));
$mform->addElement('advcheckbox', 'reset_opencast', get_string('removeclipmembers', 'opencast'));
}
/**
* Course reset form defaults.
*
* @return array
*/
function opencast_reset_course_form_defaults($course) {
return ['reset_opencast' => 1];
}
/**
* Actual implementation of the reset course functionality, delete all the
* opencast clip members for course $data->courseid.
*
* @param object $data the data submitted from the reset course.
*
* @return array status array
*/
function opencast_reset_userdata($data) {
global $CFG, $DB;
$componentstr = get_string('modulenameplural', 'opencast');
$status = [];
if (!empty($data->reset_opencast)) {
$DB->delete_records('opencast_cmember', ['courseid' => $data->courseid]);
$status[] = [
'component' => $componentstr, 'item' => get_string('removeclipmembers', 'opencast'), 'error' => false
];
}
// updating dates - shift may be negative too
if ($data->timeshift) {
shift_course_mod_dates('opencast', ['timeopen', 'timeclose'], $data->timeshift, $data->courseid);
$status[] = ['component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false];
}
return $status;
}
/**
* @uses FEATURE_GROUPS
* @uses FEATURE_GROUPINGS
* @uses FEATURE_GROUPMEMBERSONLY
* @uses FEATURE_MOD_INTRO
* @uses FEATURE_COMPLETION_TRACKS_VIEWS
* @uses FEATURE_GRADE_HAS_GRADE
* @uses FEATURE_GRADE_OUTCOMES
*
* @param string $feature FEATURE_xx constant for requested feature
*
* @return mixed True if module supports feature, null if doesn't know
*/
function opencast_supports($feature) {
switch ($feature) {
case FEATURE_IDNUMBER:
return false;
case FEATURE_GROUPS:
return true;
case FEATURE_GROUPINGS:
return false;
case FEATURE_GROUPMEMBERSONLY:
return false;
case FEATURE_MOD_INTRO:
return true;
case FEATURE_COMPLETION_TRACKS_VIEWS:
return true;
case FEATURE_COMPLETION_HAS_RULES:
return false;
case FEATURE_GRADE_HAS_GRADE:
return false;
case FEATURE_GRADE_OUTCOMES:
return false;
case FEATURE_MOD_ARCHETYPE:
return MOD_ARCHETYPE_OTHER;
case FEATURE_BACKUP_MOODLE2:
return true;
case FEATURE_NO_VIEW_LINK:
return false;
case FEATURE_SHOW_DESCRIPTION:
return true;
default:
return null;
}
}
/**
* Adds module specific settings to the settings block
*
* @param settings_navigation $settings The settings navigation object
* @param navigation_node $opencastnode The node to add module settings to
*/
function opencast_extend_settings_navigation(settings_navigation $settings, navigation_node $opencastnode) {
global $PAGE;
$cmid = $PAGE->cm->id;
$context = $PAGE->cm->context;
$opencast = opencast_get_opencast($PAGE->cm->instance);
if (has_capability('mod/opencast:isproducer', $context)
|| ($opencast->userupload && has_capability('mod/opencast:uploadclip', $context))) {
$opencastnode->add(get_string('upload_clip', 'opencast'),
new \moodle_url('/mod/opencast/upload_event.php?id=' . $cmid));
}
if (has_capability('mod/opencast:isproducer', $context) && $opencast->userupload) {
$opencastnode->add(get_string('view_useruploads', 'opencast'),
new \moodle_url('/mod/opencast/uploads.php?id=' . $cmid));
}
if (has_capability('mod/opencast:isproducer', $context)) {
$sc_obj = new mod_opencast_series();
$sc_obj->fetch($opencast->id);
$opencastnode->add(get_string('edit_at_switch', 'opencast'), new \moodle_url($sc_obj->getEditLink()));
}
// NOTE ND : forget it because no way to make this open in a new window
// if (has_capability('mod/opencast:isproducer', $PAGE->cm->context)) {
// $sc_obj = new mod_opencast_obj();
// $sc_obj->read($PAGE->cm->instance);
// if ($sc_obj->isProducer(mod_opencast_user::getExtIdFromMoodleUserId($USER->id))) {
// $opencastnode->add(get_string('edit_at_switch', 'opencast'), new moodle_url($sc_obj->getEditLink()), navigation_node::TYPE_SETTING);
// $opencastnode->add(get_string('upload_clip', 'opencast'), new moodle_url($sc_obj->getUploadForm()), navigation_node::TYPE_SETTING);
// }
// }
}
/**
* Return a list of page types
*
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
*/
function opencast_page_type_list($pagetype, $parentcontext, $currentcontext) {
$module_pagetype = ['mod-opencast-*' => get_string('page-mod-opencast-x', 'opencast')];
return $module_pagetype;
}
/**
* mod_opencast cron
*
* @return true
*/
function opencast_cron() {
mtrace('mod_opencast: processing uploaded clips');
mod_opencast_series::processUploadedClips();
return true;
}
/**
* This function receives a calendar event and returns the action associated with it, or null if there is none.
*
* This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
* is not displayed on the block.
*
* @param calendar_event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\entities\action_interface|null
*/
function mod_opencast_core_calendar_provide_event_action(calendar_event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['opencast'][$event->instance];
$completion = new \completion_info($cm->get_course());
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/opencast/view.php', ['id' => $cm->id]),
1,
true
);
}