-
Notifications
You must be signed in to change notification settings - Fork 85
/
lib.php
771 lines (630 loc) · 24.6 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
<?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/>.
/**
* Library (public API) of the scheduler module
*
* @package mod_scheduler
* @copyright 2011 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use \mod_scheduler\model\scheduler;
// Library of functions and constants for module Scheduler.
require_once($CFG->dirroot.'/mod/scheduler/locallib.php');
require_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
require_once($CFG->dirroot.'/mod/scheduler/renderer.php');
require_once($CFG->dirroot.'/mod/scheduler/renderable.php');
define('SCHEDULER_TIMEUNKNOWN', 0); // This is used for appointments for which no time is entered.
define('SCHEDULER_SELF', 0); // Used for setting conflict search scope.
define('SCHEDULER_OTHERS', 1); // Used for setting conflict search scope.
define('SCHEDULER_ALL', 2); // Used for setting conflict search scope.
define ('SCHEDULER_MEAN_GRADE', 0); // Used for grading strategy.
define ('SCHEDULER_MAX_GRADE', 1); // Used for grading strategy.
/**
* Given an object containing all the necessary data,
* will create a new instance and return the id number
* of the new instance.
*
* @param stdClass $data the current instance
* @param mod_scheduler_mod_form $mform the form that the user filled
* @return int the new instance id
* @uses $DB
*/
function scheduler_add_instance($data, $mform = null) {
global $DB;
$cmid = $data->coursemodule;
$data->timemodified = time();
$data->scale = isset($data->grade) ? $data->grade : 0;
$data->id = $DB->insert_record('scheduler', $data);
$DB->set_field('course_modules', 'instance', $data->id, array('id' => $cmid));
$context = context_module::instance($cmid);
if ($mform) {
$mform->save_mod_data($data, $context);
}
scheduler_grade_item_update($data);
if (class_exists('\core_completion\api')) {
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'scheduler', $data->id, $completiontimeexpected);
}
return $data->id;
}
function scheduler_student_autocomplete_callback($value) {
global $OUTPUT;
$fields = 'id ' . \core_user\fields::for_name()->get_sql()->selects;
$user = \core_user::get_user($value, $fields);
$useroptiondata = [
'fullname' => fullname($user)
];
return $OUTPUT->render_from_template('mod_scheduler/studentid', $useroptiondata);
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
* will update an existing instance with new data.
*
* @param stdClass $data
* @param mod_scheduler_mod_form $mform the form that the user filled
* @return bool the updated instance
* @uses $DB
*/
function scheduler_update_instance($data, $mform) {
global $DB;
$data->timemodified = time();
$data->id = $data->instance;
$data->scale = $data->grade;
$DB->update_record('scheduler', $data);
$context = context_module::instance($data->coursemodule);
$mform->save_mod_data($data, $context);
// Update grade item and grades.
scheduler_update_grades($data);
if (class_exists('\core_completion\api')) {
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'scheduler', $data->id, $completiontimeexpected);
}
return true;
}
/**
* 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 instance to be deleted
* @return bool true if success, false otherwise
* @uses $DB
*/
function scheduler_delete_instance($id) {
global $DB;
if (! $DB->record_exists('scheduler', array('id' => $id))) {
return false;
}
$scheduler = scheduler::load_by_id($id);
$scheduler->delete();
// Clean up any possibly remaining event records.
$params = array('modulename' => 'scheduler', 'instance' => $id);
$DB->delete_records('event', $params);
return true;
}
/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
* Used for user activity reports.
*
* $return->time = the time they did it
* $return->info = a short text description
* @param object $course the course instance
* @param object $user the concerned user instance
* @param object $mod the current course module instance
* @param object $scheduler the activity module behind the course module instance
* @return object an information object as defined above
*/
function scheduler_user_outline($course, $user, $mod, $scheduler) {
$scheduler = scheduler::load_by_coursemodule_id($mod->id);
$upcoming = count($scheduler->get_upcoming_slots_for_student($user->id));
$attended = count($scheduler->get_attended_slots_for_student($user->id));
$text = '';
if ($attended + $upcoming > 0) {
$a = array('attended' => $attended, 'upcoming' => $upcoming);
$text .= get_string('outlineappointments', 'scheduler', $a);
}
if ($scheduler->uses_grades()) {
$grade = $scheduler->get_gradebook_info($user->id);
if ($grade) {
$text .= get_string('outlinegrade', 'scheduler', $grade->str_long_grade);
}
}
$return = new stdClass();
$return->info = $text;
return $return;
}
/**
* Prints a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
*
* @param object $course the course instance
* @param object $user the concerned user instance
* @param object $mod the current course module instance
* @param object $scheduler the activity module behind the course module instance
*/
function scheduler_user_complete($course, $user, $mod, $scheduler) {
global $PAGE;
$scheduler = scheduler::load_by_coursemodule_id($mod->id);
$output = $PAGE->get_renderer('mod_scheduler', null, RENDERER_TARGET_GENERAL);
$appointments = $scheduler->get_appointments_for_student($user->id);
if (count($appointments) > 0) {
$table = new scheduler_slot_table($scheduler);
$table->showattended = true;
foreach ($appointments as $app) {
$table->add_slot($app->get_slot(), $app, null, false);
}
echo $output->render($table);
} else {
echo get_string('noappointments', 'scheduler');
}
if ($scheduler->uses_grades()) {
$grade = $scheduler->get_gradebook_info($user->id);
if ($grade) {
$info = new scheduler_totalgrade_info($scheduler, $grade);
echo $output->render($info);
}
}
}
/**
* Given a course and a time, this module should find recent activity
* that has occurred in scheduler activities and print it out.
* Return true if there was output, or false is there was none.
*
* @param object $course the course instance
* @param bool $isteacher true tells a teacher uses the function
* @param int $timestart a time start timestamp
* @return bool true if anything was printed, otherwise false
*/
function scheduler_print_recent_activity($course, $isteacher, $timestart) {
return false;
}
/**
* This function returns whether a scale is being used by a scheduler.
*
* @param int $cmid ID of an instance of this module
* @param int $scaleid the id of the scale in question
* @return mixed
* @uses $DB
**/
function scheduler_scale_used($cmid, $scaleid) {
global $DB;
$return = false;
// Note: scales are assigned using negative index in the grade field of the appointment (see mod/assignement/lib.php).
$rec = $DB->get_record('scheduler', array('id' => $cmid, 'scale' => -$scaleid));
if (!empty($rec) && !empty($scaleid)) {
$return = true;
}
return $return;
}
/**
* Checks if scale is being used by any instance of scheduler
*
* @param int $scaleid the id of the scale in question
* @return bool True if the scale is used by any scheduler
* @uses $DB
*/
function scheduler_scale_used_anywhere($scaleid) {
global $DB;
if ($scaleid && $DB->record_exists('scheduler', array('scale' => -$scaleid))) {
return true;
} else {
return false;
}
}
/*
* Course resetting API
*
*/
/**
* Called by course/reset.php
*
* @param MoodleQuickForm $mform form passed by reference
* @uses $COURSE
* @uses $DB
*/
function scheduler_reset_course_form_definition(&$mform) {
global $COURSE, $DB;
$mform->addElement('header', 'schedulerheader', get_string('modulenameplural', 'scheduler'));
if ($DB->record_exists('scheduler', array('course' => $COURSE->id))) {
$mform->addElement('checkbox', 'reset_scheduler_slots', get_string('resetslots', 'scheduler'));
$mform->addElement('checkbox', 'reset_scheduler_appointments', get_string('resetappointments', 'scheduler'));
$mform->disabledIf('reset_scheduler_appointments', 'reset_scheduler_slots', 'checked');
}
}
/**
* Default values for the reset form
*
* @param stdClass $course the course in which the reset takes place
*/
function scheduler_reset_course_form_defaults($course) {
return array('reset_scheduler_slots' => 1, 'reset_scheduler_appointments' => 1);
}
/**
* This function is used by the remove_course_userdata function in moodlelib.
* If this function exists, remove_course_userdata will execute it.
* This function will remove all slots and appointments from the specified scheduler.
*
* @param object $data the reset options
* @return void
*/
function scheduler_reset_userdata($data) {
global $CFG, $DB;
$status = array();
$componentstr = get_string('modulenameplural', 'scheduler');
$success = true;
if (!empty($data->reset_scheduler_appointments) || !empty($data->reset_scheduler_slots)) {
$schedulers = $DB->get_records('scheduler', ['course' => $data->courseid]);
foreach ($schedulers as $srec) {
$scheduler = scheduler::load_by_id($srec->id);
if (!empty($data->reset_scheduler_slots) ) {
$scheduler->delete_all_slots();
$status[] = array('component' => $componentstr, 'item' => get_string('resetslots', 'scheduler'), 'error' => false);
} else if (!empty($data->reset_scheduler_appointments) ) {
foreach ($scheduler->get_all_slots() as $slot) {
$slot->delete_all_appointments();
}
$status[] = array(
'component' => $componentstr,
'item' => get_string('resetappointments', 'scheduler'),
'error' => !$success
);
}
}
}
return $status;
}
/**
* Determine whether a certain feature is supported by Scheduler.
*
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, null if doesn't know
*/
function scheduler_supports($feature) {
switch($feature) {
case FEATURE_GROUPS:
return true;
case FEATURE_GROUPINGS:
return true;
case FEATURE_GROUPMEMBERSONLY:
return true;
case FEATURE_MOD_INTRO:
return true;
case FEATURE_COMPLETION_TRACKS_VIEWS:
return false;
case FEATURE_GRADE_HAS_GRADE:
return true;
case FEATURE_GRADE_OUTCOMES:
return false;
case FEATURE_BACKUP_MOODLE2:
return true;
case FEATURE_MOD_PURPOSE:
return MOD_PURPOSE_ADMINISTRATION;
default:
return null;
}
}
/* Gradebook API */
/*
* add xxx_update_grades() function into mod/xxx/lib.php
* add xxx_grade_item_update() function into mod/xxx/lib.php
* patch xxx_update_instance(), xxx_add_instance() and xxx_delete_instance() to call xxx_grade_item_update()
* patch all places of code that change grade values to call xxx_update_grades()
* patch code that displays grades to students to use final grades from the gradebook
*/
/**
* Update activity grades
*
* @param object $schedulerrecord
* @param int $userid specific user only, 0 means all
* @param bool $nullifnone not used
* @uses $CFG
* @uses $DB
*/
function scheduler_update_grades($schedulerrecord, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
$scheduler = scheduler::load_by_id($schedulerrecord->id);
if ($scheduler->scale == 0) {
scheduler_grade_item_update($schedulerrecord);
} else if ($grades = $scheduler->get_user_grades($userid)) {
foreach ($grades as $k => $v) {
if ($v->rawgrade == -1) {
$grades[$k]->rawgrade = null;
}
}
scheduler_grade_item_update($schedulerrecord, $grades);
} else {
scheduler_grade_item_update($schedulerrecord);
}
}
/**
* Create grade item for given scheduler
*
* @param object $scheduler object
* @param mixed $grades optional array/object of grade(s); 'reset' means reset grades in gradebook
* @return int 0 if ok, error code otherwise
*/
function scheduler_grade_item_update($scheduler, $grades=null) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
if (!isset($scheduler->courseid)) {
$scheduler->courseid = $scheduler->course;
}
$moduleid = $DB->get_field('modules', 'id', array('name' => 'scheduler'));
$cmid = $DB->get_field('course_modules', 'id', array('module' => $moduleid, 'instance' => $scheduler->id));
if ($scheduler->scale == 0) {
// Delete any grade item.
scheduler_grade_item_delete($scheduler);
return 0;
} else {
$params = array('itemname' => $scheduler->name, 'idnumber' => $cmid);
if ($scheduler->scale > 0) {
$params['gradetype'] = GRADE_TYPE_VALUE;
$params['grademax'] = $scheduler->scale;
$params['grademin'] = 0;
} else if ($scheduler->scale < 0) {
$params['gradetype'] = GRADE_TYPE_SCALE;
$params['scaleid'] = -$scheduler->scale;
} else {
$params['gradetype'] = GRADE_TYPE_TEXT; // Allow text comments only.
}
if ($grades === 'reset') {
$params['reset'] = true;
$grades = null;
}
return grade_update('mod/scheduler', $scheduler->courseid, 'mod', 'scheduler', $scheduler->id, 0, $grades, $params);
}
}
/**
* Update all grades in gradebook.
*/
function scheduler_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {scheduler} s, {course_modules} cm, {modules} m
WHERE m.name='scheduler' AND m.id=cm.module AND cm.instance=s.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT s.*, cm.idnumber AS cmidnumber, s.course AS courseid
FROM {scheduler} s, {course_modules} cm, {modules} m
WHERE m.name='scheduler' AND m.id=cm.module AND cm.instance=s.id";
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$pbar = new progress_bar('schedulerupgradegrades', 500, true);
$i = 0;
foreach ($rs as $scheduler) {
$i++;
upgrade_set_timeout(60 * 5); // Set up timeout, may also abort execution.
scheduler_update_grades($scheduler);
$pbar->update($i, $count, "Updating scheduler grades ($i/$count).");
}
upgrade_set_timeout(); // Reset to default timeout.
}
$rs->close();
}
/**
* Delete grade item for given scheduler
*
* @param object $scheduler object
* @return object scheduler
*/
function scheduler_grade_item_delete($scheduler) {
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
if (!isset($scheduler->courseid)) {
$scheduler->courseid = $scheduler->course;
}
return grade_update('mod/scheduler', $scheduler->courseid, 'mod', 'scheduler', $scheduler->id, 0, null, array('deleted' => 1));
}
/*
* File API
*/
/**
* Lists all browsable file areas
*
* @package mod_scheduler
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function scheduler_get_file_areas($course, $cm, $context) {
return array(
'bookinginstructions' => get_string('bookinginstructions', 'scheduler'),
'slotnote' => get_string('areaslotnote', 'scheduler'),
'appointmentnote' => get_string('areaappointmentnote', 'scheduler'),
'teachernote' => get_string('areateachernote', 'scheduler')
);
}
/**
* File browsing support for scheduler module.
*
* @param file_browser $browser
* @param array $areas
* @param stdClass $course
* @param cm_info $cm
* @param context $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info_stored file_info_stored instance or null if not found
*/
function scheduler_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG, $DB, $USER;
// Note: 'intro' area is handled in file_browser automatically.
if (!has_any_capability(array('mod/scheduler:appoint', 'mod/scheduler:attend',
'mod/scheduler:viewotherteachersbooking', 'mod/scheduler:manageallappointments'), $context)) {
return null;
}
require_once(dirname(__FILE__).'/locallib.php');
$validareas = array_keys(scheduler_get_file_areas($course, $cm, $context));
if (!in_array($filearea, $validareas)) {
return null;
}
if (is_null($itemid)) {
return new scheduler_file_info($browser, $course, $cm, $context, $areas, $filearea);
}
try {
$scheduler = scheduler::load_by_coursemodule_id($cm->id);
$permissions = new \mod_scheduler\permission\scheduler_permissions($context, $USER->id);
if ($filearea === 'bookinginstructions') {
$cansee = true;
$canwrite = has_capability('moodle/course:manageactivities', $context);
$name = get_string('bookinginstructions', 'scheduler');
} else if ($filearea === 'slotnote') {
$slot = $scheduler->get_slot($itemid);
$cansee = true;
$canwrite = $permissions->can_edit_slot($slot);
$name = get_string('slot', 'scheduler'). ' '.$itemid;
} else if ($filearea === 'appointmentnote') {
if (!$scheduler->uses_appointmentnotes()) {
return null;
}
list($slot, $app) = $scheduler->get_slot_appointment($itemid);
$cansee = $permissions->can_see_appointment($app);
$canwrite = $permissions->can_edit_notes($app);
$name = get_string('appointment', 'scheduler'). ' '.$itemid;
} else if ($filearea === 'teachernote') {
if (!$scheduler->uses_teachernotes()) {
return null;
}
list($slot, $app) = $scheduler->get_slot_appointment($itemid);
$cansee = $permissions->teacher_can_see_slot($slot);
$canwrite = $permissions->can_edit_notes($app);
$name = get_string('appointment', 'scheduler'). ' '.$itemid;
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($context->id, 'mod_scheduler', $filearea, $itemid, $filepath, $filename)) {
return null;
}
$urlbase = $CFG->wwwroot.'/pluginfile.php';
return new file_info_stored($browser, $context, $storedfile, $urlbase, $name, true, true, $canwrite, false);
} catch (Exception $e) {
return null;
}
}
/**
* Serves the files embedded in various rich text fields, or uploaded by students
*
* @package mod_scheduler
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClsss $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - just send the file
*/
function scheduler_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG, $DB, $USER;
if ($context->contextlevel != CONTEXT_MODULE) {
return false;
}
require_course_login($course, true, $cm);
if (!has_any_capability(array('mod/scheduler:appoint', 'mod/scheduler:attend'), $context)) {
return false;
}
try {
$scheduler = scheduler::load_by_coursemodule_id($cm->id);
$permissions = new \mod_scheduler\permission\scheduler_permissions($context, $USER->id);
$entryid = (int)array_shift($args);
$relativepath = implode('/', $args);
if ($filearea === 'slotnote') {
if (!$scheduler->get_slot($entryid)) {
return false;
}
// No further access control required - everyone can see slots notes.
} else if ($filearea === 'appointmentnote') {
if (!$scheduler->uses_appointmentnotes()) {
return false;
}
list($slot, $app) = $scheduler->get_slot_appointment($entryid);
if (!$app) {
return false;
}
$permissions->ensure($permissions->can_see_appointment($app));
} else if ($filearea === 'teachernote') {
if (!$scheduler->uses_teachernotes()) {
return false;
}
list($slot, $app) = $scheduler->get_slot_appointment($entryid);
if (!$app) {
return false;
}
$permissions->ensure($permissions->teacher_can_see_slot($slot));
} else if ($filearea === 'bookinginstructions') {
$caps = array('moodle/course:manageactivities', 'mod/scheduler:appoint');
if (!has_any_capability($caps, $context)) {
return false;
}
} else if ($filearea === 'studentfiles') {
if (!$scheduler->uses_studentfiles()) {
return false;
}
list($slot, $app) = $scheduler->get_slot_appointment($entryid);
if (!$app) {
return false;
}
$permissions->ensure($permissions->can_see_appointment($app));
} else {
// Unknown file area.
return false;
}
} catch (Exception $e) {
// Typically, records that are not found in the database.
return false;
}
$fullpath = "/$context->id/mod_scheduler/$filearea/$entryid/$relativepath";
$fs = get_file_storage();
$file = $fs->get_file_by_hash(sha1($fullpath));
if (!$file || $file->is_directory()) {
return false;
}
send_stored_file($file, 0, 0, $forcedownload, $options);
}
/**
* 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_scheduler_core_calendar_provide_event_action(calendar_event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['scheduler'][$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/scheduler/view.php', ['id' => $cm->id]),
1,
true
);
}