1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* @package mod
|
|
|
19 |
* @subpackage eduplayer
|
|
|
20 |
* @author Humanage Srl <info@humanage.it>
|
|
|
21 |
* @copyright 2013 Humanage Srl <info@humanage.it>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
require_once($CFG->libdir.'/filelib.php');
|
|
|
28 |
require_once('locallib.php');
|
|
|
29 |
|
|
|
30 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
31 |
// Moodle core API //
|
|
|
32 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Returns the information on whether the module supports a feature
|
|
|
36 |
*
|
|
|
37 |
* @see plugin_supports() in lib/moodlelib.php
|
|
|
38 |
* @param string $feature FEATURE_xx constant for requested feature
|
|
|
39 |
* @return mixed true if the feature is supported, null if unknown
|
|
|
40 |
*/
|
|
|
41 |
function eduplayer_supports($feature) {
|
|
|
42 |
switch($feature) {
|
|
|
43 |
case FEATURE_MOD_INTRO: return true;
|
|
|
44 |
case FEATURE_GROUPS: return false;
|
|
|
45 |
case FEATURE_GROUPINGS: return false;
|
|
|
46 |
case FEATURE_GROUPMEMBERSONLY: return true;
|
|
|
47 |
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
|
|
|
48 |
case FEATURE_GRADE_HAS_GRADE: return false;
|
|
|
49 |
case FEATURE_GRADE_OUTCOMES: return false;
|
|
|
50 |
case FEATURE_BACKUP_MOODLE2: return true;
|
|
|
51 |
case FEATURE_SHOW_DESCRIPTION: return true;
|
|
|
52 |
default: return null;
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Saves a new instance of the eduplayer into the database
|
|
|
58 |
*
|
|
|
59 |
* Given an object containing all the necessary data,
|
|
|
60 |
* (defined by the form in mod_form.php) this function
|
|
|
61 |
* will create a new instance and return the id number
|
|
|
62 |
* of the new instance.
|
|
|
63 |
*
|
|
|
64 |
* @param object $eduplayer An object from the form in mod_form.php
|
|
|
65 |
* @param mod_eduplayer_mod_form $mform
|
|
|
66 |
* @return int The id of the newly inserted eduplayer record
|
|
|
67 |
*/
|
|
|
68 |
function eduplayer_add_instance(stdClass $eduplayer, mod_eduplayer_mod_form $mform = null) {
|
|
|
69 |
global $DB, $CFG;
|
|
|
70 |
|
|
|
71 |
$eduplayer->timecreated = time();
|
|
|
72 |
$context = get_context_instance(CONTEXT_MODULE, $eduplayer->coursemodule);
|
|
|
73 |
|
|
|
74 |
$fs = get_file_storage();
|
|
|
75 |
|
|
|
76 |
if ($eduplayer->urltype == 1) {
|
|
|
77 |
$items = array('file', 'image', 'captionsfile');
|
|
|
78 |
} else {
|
|
|
79 |
$items = array('image', 'captionsfile');
|
|
|
80 |
$eduplayer->eduplayerfile = $eduplayer->linkurl;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
foreach ($items as $value) {
|
|
|
84 |
|
|
|
85 |
$file = '';
|
|
|
86 |
$draftitemid = file_get_submitted_draft_itemid($value);
|
|
|
87 |
file_prepare_draft_area($draftitemid, $context->id, 'mod_eduplayer', $value, 0, array('subdirs'=>0));
|
|
|
88 |
file_save_draft_area_files($draftitemid, $context->id, 'mod_eduplayer', $value, 0, array('subdirs'=>0));
|
|
|
89 |
$file = $fs->get_area_files($context->id, 'mod_eduplayer', $value, 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
|
|
|
90 |
$file_details = $fs->get_file_by_hash(key($file));
|
|
|
91 |
if( empty( $file ) ){
|
|
|
92 |
$eduplayer->$value = NULL;
|
|
|
93 |
continue;
|
|
|
94 |
}
|
|
|
95 |
if ($value == 'file') {
|
|
|
96 |
$eduplayer->eduplayerfile = $file_details->get_filename();
|
|
|
97 |
} else {
|
|
|
98 |
if (!empty($file)) {
|
|
|
99 |
$eduplayer->$value = $file_details->get_filename();
|
|
|
100 |
} else {
|
|
|
101 |
$eduplayer->$value = NULL;
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
}
|
|
|
106 |
$eduplayer->height = normalize_height( $eduplayer );
|
|
|
107 |
$eduplayer = file_postupdate_standard_editor($eduplayer, 'notes', array('subdirs'=>0, 'maxfiles'=>3, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true, 'context'=>$context), $context, 'mod_eduplayer', 'notes', 0);
|
|
|
108 |
$eduplayer = file_postupdate_standard_editor($eduplayer, 'sharemailmessage', array('subdirs'=>0, 'maxfiles'=>3, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true, 'context'=>$context), $context, 'mod_eduplayer', 'sharemailmessage', 0);
|
|
|
109 |
|
|
|
110 |
return $DB->insert_record('eduplayer', $eduplayer);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Updates an instance of the eduplayer in the database
|
|
|
115 |
*
|
|
|
116 |
* Given an object containing all the necessary data,
|
|
|
117 |
* (defined by the form in mod_form.php) this function
|
|
|
118 |
* will update an existing instance with new data.
|
|
|
119 |
*
|
|
|
120 |
* @param object $eduplayer An object from the form in mod_form.php
|
|
|
121 |
* @param mod_eduplayer_mod_form $mform
|
|
|
122 |
* @return boolean Success/Fail
|
|
|
123 |
*/
|
|
|
124 |
function eduplayer_update_instance(stdClass $eduplayer, mod_eduplayer_mod_form $mform = null) {
|
|
|
125 |
|
|
|
126 |
global $DB, $CFG;
|
|
|
127 |
|
|
|
128 |
$eduplayer->timemodified = time();
|
|
|
129 |
$eduplayer->id = $eduplayer->instance;
|
|
|
130 |
|
|
|
131 |
//$context = get_context_instance(CONTEXT_MODULE, $eduplayer->coursemodule);
|
|
|
132 |
//Mihir moodle3.2
|
|
|
133 |
$context = context_module::instance($eduplayer->coursemodule);
|
|
|
134 |
|
|
|
135 |
$fs = get_file_storage();
|
|
|
136 |
|
|
|
137 |
if ($eduplayer->urltype == 1) {
|
|
|
138 |
$items = array('file', 'image', 'captionsfile');
|
|
|
139 |
} else {
|
|
|
140 |
$items = $items = array('image', 'captionsfile');
|
|
|
141 |
$eduplayer->eduplayerfile = $eduplayer->linkurl;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
foreach ($items as $value) {
|
|
|
145 |
$file = '';
|
|
|
146 |
$draftitemid = file_get_submitted_draft_itemid($value);
|
|
|
147 |
file_prepare_draft_area($draftitemid, $context->id, 'mod_eduplayer', $value, 0, array('subdirs'=>0));
|
|
|
148 |
file_save_draft_area_files($draftitemid, $context->id, 'mod_eduplayer', $value, 0, array('subdirs'=>0));
|
|
|
149 |
$file = $fs->get_area_files($context->id, 'mod_eduplayer', $value, 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
|
|
|
150 |
if( empty( $file ) ){
|
|
|
151 |
$eduplayer->$value = NULL;
|
|
|
152 |
continue;
|
|
|
153 |
}
|
|
|
154 |
$file_details = $fs->get_file_by_hash(key($file));
|
|
|
155 |
|
|
|
156 |
if ($value == 'file') {
|
|
|
157 |
$eduplayer->eduplayerfile = $file_details->get_filename();
|
|
|
158 |
} else {
|
|
|
159 |
if (!empty($file)) {
|
|
|
160 |
$eduplayer->$value = $file_details->get_filename();
|
|
|
161 |
} else {
|
|
|
162 |
$eduplayer->$value = NULL;
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
$eduplayer->height = normalize_height( $eduplayer );
|
|
|
169 |
if(!isset($eduplayer->downloadenabled))
|
|
|
170 |
$eduplayer->downloadenabled = 0;
|
|
|
171 |
|
|
|
172 |
$eduplayer = file_postupdate_standard_editor($eduplayer, 'notes', array('subdirs'=>0, 'maxfiles'=>3, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true, 'context'=>$context), $context, 'mod_eduplayer', 'notes', 0);
|
|
|
173 |
$eduplayer = file_postupdate_standard_editor($eduplayer, 'sharemailmessage', array('subdirs'=>0, 'maxfiles'=>3, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true, 'context'=>$context), $context, 'mod_eduplayer', 'sharemailmessage', 0);
|
|
|
174 |
|
|
|
175 |
return $DB->update_record('eduplayer', $eduplayer);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
/**
|
|
|
179 |
* Removes an instance of the eduplayer from the database
|
|
|
180 |
*
|
|
|
181 |
* Given an ID of an instance of this module,
|
|
|
182 |
* this function will permanently delete the instance
|
|
|
183 |
* and any data that depends on it.
|
|
|
184 |
*
|
|
|
185 |
* @param int $id Id of the module instance
|
|
|
186 |
* @return boolean Success/Failure
|
|
|
187 |
*/
|
|
|
188 |
function eduplayer_delete_instance($id) {
|
|
|
189 |
global $DB;
|
|
|
190 |
|
|
|
191 |
if (! $eduplayer = $DB->get_record('eduplayer', array('id' => $id))) {
|
|
|
192 |
return false;
|
|
|
193 |
}
|
|
|
194 |
$DB->delete_records('eduplayer', array('id' => $eduplayer->id));
|
|
|
195 |
return true;
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
/**
|
|
|
199 |
* Returns a small object with summary information about what a
|
|
|
200 |
* user has done with a given particular instance of this module
|
|
|
201 |
* Used for user activity reports.
|
|
|
202 |
* $return->time = the time they did it
|
|
|
203 |
* $return->info = a short text description
|
|
|
204 |
*
|
|
|
205 |
* @return stdClass|null
|
|
|
206 |
*/
|
|
|
207 |
function eduplayer_user_outline($course, $user, $mod, $eduplayer) {
|
|
|
208 |
|
|
|
209 |
$return = new stdClass();
|
|
|
210 |
$return->time = 0;
|
|
|
211 |
$return->info = '';
|
|
|
212 |
return $return;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
/**
|
|
|
216 |
* Prints a detailed representation of what a user has done with
|
|
|
217 |
* a given particular instance of this module, for user activity reports.
|
|
|
218 |
*
|
|
|
219 |
* @param stdClass $course the current course record
|
|
|
220 |
* @param stdClass $user the record of the user we are generating report for
|
|
|
221 |
* @param cm_info $mod course module info
|
|
|
222 |
* @param stdClass $eduplayer the module instance record
|
|
|
223 |
* @return void, is supposed to echp directly
|
|
|
224 |
*/
|
|
|
225 |
function eduplayer_user_complete($course, $user, $mod, $eduplayer) {
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
/**
|
|
|
229 |
* Given a course and a time, this module should find recent activity
|
|
|
230 |
* that has occurred in eduplayer activities and print it out.
|
|
|
231 |
* Return true if there was output, or false is there was none.
|
|
|
232 |
*
|
|
|
233 |
* @return boolean
|
|
|
234 |
*/
|
|
|
235 |
function eduplayer_print_recent_activity($course, $viewfullnames, $timestart) {
|
|
|
236 |
return false; // True if anything was printed, otherwise false
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
/**
|
|
|
240 |
* Prepares the recent activity data
|
|
|
241 |
*
|
|
|
242 |
* This callback function is supposed to populate the passed array with
|
|
|
243 |
* custom activity records. These records are then rendered into HTML via
|
|
|
244 |
* {@link eduplayer_print_recent_mod_activity()}.
|
|
|
245 |
*
|
|
|
246 |
* @param array $activities sequentially indexed array of objects with the 'cmid' property
|
|
|
247 |
* @param int $index the index in the $activities to use for the next record
|
|
|
248 |
* @param int $timestart append activity since this time
|
|
|
249 |
* @param int $courseid the id of the course we produce the report for
|
|
|
250 |
* @param int $cmid course module id
|
|
|
251 |
* @param int $userid check for a particular user's activity only, defaults to 0 (all users)
|
|
|
252 |
* @param int $groupid check for a particular group's activity only, defaults to 0 (all groups)
|
|
|
253 |
* @return void adds items into $activities and increases $index
|
|
|
254 |
*/
|
|
|
255 |
function eduplayer_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
/**
|
|
|
259 |
* Prints single activity item prepared by {@see eduplayer_get_recent_mod_activity()}
|
|
|
260 |
|
|
|
261 |
* @return void
|
|
|
262 |
*/
|
|
|
263 |
function eduplayer_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames) {
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
/**
|
|
|
267 |
* Function to be run periodically according to the moodle cron
|
|
|
268 |
* This function searches for things that need to be done, such
|
|
|
269 |
* as sending out mail, toggling flags etc ...
|
|
|
270 |
*
|
|
|
271 |
* @return boolean
|
|
|
272 |
* @todo Finish documenting this function
|
|
|
273 |
**/
|
|
|
274 |
function eduplayer_cron () {
|
|
|
275 |
return true;
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
/**
|
|
|
279 |
* Returns all other caps used in the module
|
|
|
280 |
*
|
|
|
281 |
* @example return array('moodle/site:accessallgroups');
|
|
|
282 |
* @return array
|
|
|
283 |
*/
|
|
|
284 |
function eduplayer_get_extra_capabilities() {
|
|
|
285 |
return array();
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
289 |
// Gradebook API //
|
|
|
290 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
291 |
|
|
|
292 |
/**
|
|
|
293 |
* Is a given scale used by the instance of eduplayer?
|
|
|
294 |
*
|
|
|
295 |
* This function returns if a scale is being used by one eduplayer
|
|
|
296 |
* if it has support for grading and scales. Commented code should be
|
|
|
297 |
* modified if necessary. See forum, glossary or journal modules
|
|
|
298 |
* as reference.
|
|
|
299 |
*
|
|
|
300 |
* @param int $eduplayerid ID of an instance of this module
|
|
|
301 |
* @return bool true if the scale is used by the given eduplayer instance
|
|
|
302 |
*/
|
|
|
303 |
function eduplayer_scale_used($eduplayerid, $scaleid) {
|
|
|
304 |
global $DB;
|
|
|
305 |
|
|
|
306 |
/** @example */
|
|
|
307 |
if ($scaleid and $DB->record_exists('eduplayer', array('id' => $eduplayerid, 'grade' => -$scaleid))) {
|
|
|
308 |
return true;
|
|
|
309 |
} else {
|
|
|
310 |
return false;
|
|
|
311 |
}
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
/**
|
|
|
315 |
* Checks if scale is being used by any instance of eduplayer.
|
|
|
316 |
*
|
|
|
317 |
* This is used to find out if scale used anywhere.
|
|
|
318 |
*
|
|
|
319 |
* @param $scaleid int
|
|
|
320 |
* @return boolean true if the scale is used by any eduplayer instance
|
|
|
321 |
*/
|
|
|
322 |
function eduplayer_scale_used_anywhere($scaleid) {
|
|
|
323 |
global $DB;
|
|
|
324 |
|
|
|
325 |
/** @example */
|
|
|
326 |
if ($scaleid and $DB->record_exists('eduplayer', array('grade' => -$scaleid))) {
|
|
|
327 |
return true;
|
|
|
328 |
} else {
|
|
|
329 |
return false;
|
|
|
330 |
}
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
/**
|
|
|
334 |
* Creates or updates grade item for the give eduplayer instance
|
|
|
335 |
*
|
|
|
336 |
* Needed by grade_update_mod_grades() in lib/gradelib.php
|
|
|
337 |
*
|
|
|
338 |
* @param stdClass $eduplayer instance object with extra cmidnumber and modname property
|
|
|
339 |
* @return void
|
|
|
340 |
*/
|
|
|
341 |
function eduplayer_grade_item_update(stdClass $eduplayer) {
|
|
|
342 |
global $CFG;
|
|
|
343 |
require_once($CFG->libdir.'/gradelib.php');
|
|
|
344 |
|
|
|
345 |
/** @example */
|
|
|
346 |
$item = array();
|
|
|
347 |
$item['itemname'] = clean_param($eduplayer->name, PARAM_NOTAGS);
|
|
|
348 |
$item['gradetype'] = GRADE_TYPE_VALUE;
|
|
|
349 |
$item['grademax'] = $eduplayer->grade;
|
|
|
350 |
$item['grademin'] = 0;
|
|
|
351 |
|
|
|
352 |
grade_update('mod/eduplayer', $eduplayer->course, 'mod', 'eduplayer', $eduplayer->id, 0, null, $item);
|
|
|
353 |
}
|
|
|
354 |
|
|
|
355 |
/**
|
|
|
356 |
* Update eduplayer grades in the gradebook
|
|
|
357 |
*
|
|
|
358 |
* Needed by grade_update_mod_grades() in lib/gradelib.php
|
|
|
359 |
*
|
|
|
360 |
* @param stdClass $eduplayer instance object with extra cmidnumber and modname property
|
|
|
361 |
* @param int $userid update grade of specific user only, 0 means all participants
|
|
|
362 |
* @return void
|
|
|
363 |
*/
|
|
|
364 |
function eduplayer_update_grades(stdClass $eduplayer, $userid = 0) {
|
|
|
365 |
global $CFG, $DB;
|
|
|
366 |
require_once($CFG->libdir.'/gradelib.php');
|
|
|
367 |
|
|
|
368 |
/** @example */
|
|
|
369 |
$grades = array(); // populate array of grade objects indexed by userid
|
|
|
370 |
|
|
|
371 |
grade_update('mod/eduplayer', $eduplayer->course, 'mod', 'eduplayer', $eduplayer->id, 0, $grades);
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
375 |
// File API //
|
|
|
376 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
377 |
|
|
|
378 |
/**
|
|
|
379 |
* Returns the lists of all browsable file areas within the given module context
|
|
|
380 |
*
|
|
|
381 |
* The file area 'intro' for the activity introduction field is added automatically
|
|
|
382 |
* by {@link file_browser::get_file_info_context_module()}
|
|
|
383 |
*
|
|
|
384 |
* @param stdClass $course
|
|
|
385 |
* @param stdClass $cm
|
|
|
386 |
* @param stdClass $context
|
|
|
387 |
* @return array of [(string)filearea] => (string)description
|
|
|
388 |
*/
|
|
|
389 |
function eduplayer_get_file_areas($course, $cm, $context) {
|
|
|
390 |
$areas = array('file', 'notes', 'image', 'captionsfile');
|
|
|
391 |
$areas['file'] = get_string('eduplayerfile', 'eduplayer');
|
|
|
392 |
$areas['notes'] = get_string('notes', 'eduplayer');
|
|
|
393 |
$areas['image'] = get_string('image', 'eduplayer');
|
|
|
394 |
$areas['captionsfile'] = get_string('captionsfile', 'eduplayer');
|
|
|
395 |
return $areas;
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
/**
|
|
|
399 |
* File browsing support for eduplayer file areas
|
|
|
400 |
*
|
|
|
401 |
* @package mod_eduplayer
|
|
|
402 |
* @category files
|
|
|
403 |
*
|
|
|
404 |
* @param file_browser $browser
|
|
|
405 |
* @param array $areas
|
|
|
406 |
* @param stdClass $course
|
|
|
407 |
* @param stdClass $cm
|
|
|
408 |
* @param stdClass $context
|
|
|
409 |
* @param string $filearea
|
|
|
410 |
* @param int $itemid
|
|
|
411 |
* @param string $filepath
|
|
|
412 |
* @param string $filename
|
|
|
413 |
* @return file_info instance or null if not found
|
|
|
414 |
*/
|
|
|
415 |
function eduplayer_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
|
|
|
416 |
global $CFG;
|
|
|
417 |
|
|
|
418 |
if (!has_capability('moodle/course:managefiles', $context)) {
|
|
|
419 |
// students can not peak here!
|
|
|
420 |
return null;
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
$fs = get_file_storage();
|
|
|
424 |
|
|
|
425 |
if ($filearea == 'file' || $filearea == 'notes' || $filearea == 'image' || $filearea == 'captionsfile') {
|
|
|
426 |
|
|
|
427 |
$filepath = is_null($filepath) ? '/' : $filepath;
|
|
|
428 |
$filename = is_null($filename) ? '.' : $filename;
|
|
|
429 |
|
|
|
430 |
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
|
|
431 |
if (!$storedfile = $fs->get_file($context->id, 'mod_eduplayer', $filearea, 0, $filepath, $filename)) {
|
|
|
432 |
if ($filepath === '/' and $filename === '.') {
|
|
|
433 |
$storedfile = new virtual_root_file($context->id, 'mod_eduplayer', $filearea, 0);
|
|
|
434 |
} else {
|
|
|
435 |
// not found
|
|
|
436 |
return null;
|
|
|
437 |
}
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
return new eduplayer_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, true, false);
|
|
|
441 |
|
|
|
442 |
}
|
|
|
443 |
// note: resource_intro handled in file_browser automatically
|
|
|
444 |
|
|
|
445 |
return null;
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
/**
|
|
|
449 |
* Serves the files from the eduplayer file areas
|
|
|
450 |
*
|
|
|
451 |
* @package mod_eduplayer
|
|
|
452 |
* @category files
|
|
|
453 |
*
|
|
|
454 |
* @param stdClass $course the course object
|
|
|
455 |
* @param stdClass $cm the course module object
|
|
|
456 |
* @param stdClass $context the eduplayer's context
|
|
|
457 |
* @param string $filearea the name of the file area
|
|
|
458 |
* @param array $args extra arguments (itemid, path)
|
|
|
459 |
* @param bool $forcedownload whether or not force download
|
|
|
460 |
* @param array $options additional options affecting the file serving
|
|
|
461 |
*/
|
|
|
462 |
function eduplayer_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) {
|
|
|
463 |
global $DB, $CFG;
|
|
|
464 |
|
|
|
465 |
if ($context->contextlevel != CONTEXT_MODULE) {
|
|
|
466 |
send_file_not_found();
|
|
|
467 |
}
|
|
|
468 |
|
|
|
469 |
require_course_login($course, true, $cm);
|
|
|
470 |
|
|
|
471 |
if (($filearea == 'notes') || ($filearea == 'file') || ($filearea == 'image') || ($filearea == 'captionsfile')) {
|
|
|
472 |
#OK Continue..
|
|
|
473 |
} else {
|
|
|
474 |
return false;
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
$fileid = (int)array_shift($args);
|
|
|
478 |
$fs = get_file_storage();
|
|
|
479 |
$relativepath = implode('/', $args);
|
|
|
480 |
|
|
|
481 |
//$fullpath = "/$context->id/mod_eduplayer/$filearea/$fileid/$relativepath";
|
|
|
482 |
$fullpath = "/$context->id/mod_eduplayer/$filearea/0/$relativepath";
|
|
|
483 |
|
|
|
484 |
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory() ) {
|
|
|
485 |
return false;
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
send_stored_file($file, 360, 0, $forcedownload);
|
|
|
489 |
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
/**
|
|
|
493 |
* File browsing support class
|
|
|
494 |
*/
|
|
|
495 |
class eduplayer_content_file_info extends file_info_stored {
|
|
|
496 |
public function get_parent() {
|
|
|
497 |
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
|
|
|
498 |
return $this->browser->get_file_info($this->context);
|
|
|
499 |
}
|
|
|
500 |
return parent::get_parent();
|
|
|
501 |
}
|
|
|
502 |
public function get_visible_name() {
|
|
|
503 |
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
|
|
|
504 |
return $this->topvisiblename;
|
|
|
505 |
}
|
|
|
506 |
return parent::get_visible_name();
|
|
|
507 |
}
|
|
|
508 |
}
|
|
|
509 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
510 |
// Navigation API //
|
|
|
511 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
512 |
|
|
|
513 |
/**
|
|
|
514 |
* Extends the global navigation tree by adding eduplayer nodes if there is a relevant content
|
|
|
515 |
*
|
|
|
516 |
* This can be called by an AJAX request so do not rely on $PAGE as it might not be set up properly.
|
|
|
517 |
*
|
|
|
518 |
* @param navigation_node $navref An object representing the navigation tree node of the eduplayer module instance
|
|
|
519 |
* @param stdClass $course
|
|
|
520 |
* @param stdClass $module
|
|
|
521 |
* @param cm_info $cm
|
|
|
522 |
*/
|
|
|
523 |
function eduplayer_extend_navigation(navigation_node $navref, stdclass $course, stdclass $module, cm_info $cm) {
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
/**
|
|
|
527 |
* Extends the settings navigation with the eduplayer settings
|
|
|
528 |
*
|
|
|
529 |
* This function is called when the context for the page is a eduplayer module. This is not called by AJAX
|
|
|
530 |
* so it is safe to rely on the $PAGE.
|
|
|
531 |
*
|
|
|
532 |
* @param settings_navigation $settingsnav {@link settings_navigation}
|
|
|
533 |
* @param navigation_node $eduplayernode {@link navigation_node}
|
|
|
534 |
*/
|
|
|
535 |
function eduplayer_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $eduplayernode=null) {
|
|
|
536 |
}
|
|
|
537 |
|
|
|
538 |
|
|
|
539 |
/**
|
|
|
540 |
* Construct Javascript SWFObject embed code for <body> section of view.php
|
|
|
541 |
* Please note: some URLs append a '?'.time(); query to prevent browser caching
|
|
|
542 |
*
|
|
|
543 |
* @param $eduplayer (mdl_mplayer DB record for current mplayer module instance)
|
|
|
544 |
* @return string
|
|
|
545 |
*/
|
|
|
546 |
function eduplayer_video($eduplayer) {
|
|
|
547 |
global $CFG, $COURSE, $CFG;
|
|
|
548 |
|
|
|
549 |
$cm = get_coursemodule_from_instance('eduplayer', $eduplayer->id, $COURSE->id);
|
|
|
550 |
//$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
551 |
$context = context_module::instance($cm->id); //Moodle 3.2 Mihir
|
|
|
552 |
|
|
|
553 |
$video = eduplayer_player_helper($eduplayer, $cm, $context);
|
|
|
554 |
|
|
|
555 |
//Notes
|
|
|
556 |
$eduplayer->notes = file_rewrite_pluginfile_urls($eduplayer->notes, 'pluginfile.php', $context->id, 'mod_eduplayer', 'notes', 0);
|
|
|
557 |
$video .= html_writer::tag('div', $eduplayer->notes, array('id' => 'videoNotes'));
|
|
|
558 |
|
|
|
559 |
//If eduplayer type is audio and has no image poster set overflow to every container
|
|
|
560 |
if( $eduplayer->type=='audio' && ( $eduplayer->image == '' || is_null( $eduplayer->image ) ) )
|
|
|
561 |
$video .= html_writer::tag('style', '.jwplayer{height: 120px !important;} object{outline: none;}');
|
|
|
562 |
// $video .= html_writer::tag('style', '#page-content, #region-main-box, #region-main-wrap, #region-main, .region-content{overflow: visible !important;}');
|
|
|
563 |
|
|
|
564 |
return $video;
|
|
|
565 |
}
|
|
|
566 |
|
|
|
567 |
/*
|
|
|
568 |
* Enabled video extensions
|
|
|
569 |
*/
|
|
|
570 |
function eduplayer_video_extensions() {
|
|
|
571 |
$extensions = array(
|
|
|
572 |
'.mp4',
|
|
|
573 |
'.flv',
|
|
|
574 |
'.webm',
|
|
|
575 |
'.MP4',
|
|
|
576 |
'.FLV',
|
|
|
577 |
'.WEBM'
|
|
|
578 |
);
|
|
|
579 |
return $extensions;
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
/*
|
|
|
583 |
* Enabled image extensions
|
|
|
584 |
*/
|
|
|
585 |
function eduplayer_image_extensions() {
|
|
|
586 |
$extensions = array(
|
|
|
587 |
'.jpg',
|
|
|
588 |
'.jpeg',
|
|
|
589 |
'.png',
|
|
|
590 |
'.JPG',
|
|
|
591 |
'.JPEG',
|
|
|
592 |
'.PNG'
|
|
|
593 |
);
|
|
|
594 |
return $extensions;
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
/*
|
|
|
598 |
* Enabled captions extensions
|
|
|
599 |
*/
|
|
|
600 |
function eduplayer_captions_extensions() {
|
|
|
601 |
$extensions = array(
|
|
|
602 |
'.vtt',
|
|
|
603 |
'.srt',
|
|
|
604 |
'.VTT',
|
|
|
605 |
'.SRT'
|
|
|
606 |
);
|
|
|
607 |
return $extensions;
|
|
|
608 |
}
|
|
|
609 |
|
|
|
610 |
/*
|
|
|
611 |
* Enabled audio extensions
|
|
|
612 |
*/
|
|
|
613 |
function eduplayer_audio_extensions() {
|
|
|
614 |
$extensions = array(
|
|
|
615 |
'.mp3',
|
|
|
616 |
'.m4a'
|
|
|
617 |
);
|
|
|
618 |
return $extensions;
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
/*
|
|
|
622 |
* Normalize height for audio format
|
|
|
623 |
* If is audio force the height to 35 px only if poster is empty
|
|
|
624 |
*/
|
|
|
625 |
function normalize_height( $eduplayer ){
|
|
|
626 |
|
|
|
627 |
if( $eduplayer->type === 'audio' && ( is_null( $eduplayer->image ) || $eduplayer->image=='') ){
|
|
|
628 |
$eduplayer->height = '35';
|
|
|
629 |
}else if( $eduplayer->type === 'audio' && $eduplayer->image!='' && $eduplayer->height < '360' ){
|
|
|
630 |
$eduplayer->height = '360';
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
return $eduplayer->height;
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
/*
|
|
|
637 |
* Return
|
|
|
638 |
* 'true' if you want show the logo
|
|
|
639 |
* 'false' if you don't ant ot
|
|
|
640 |
*/
|
|
|
641 |
function showlogo(){
|
|
|
642 |
return 'false';
|
|
|
643 |
}
|