-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimeslotnotifications.php
85 lines (68 loc) · 2.95 KB
/
timeslotnotifications.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
<?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/>.
/**
* Timeslot notifications management page.
*
* @package mod_observation
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
* @author Matthew Hilton <mj.hilton@outlook.com>, Jack Kepper <Jack@Kepper.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../config.php');
$id = required_param('id', PARAM_INT); // Observation instance ID.
$action = optional_param('action', null, PARAM_TEXT);
$notifyid = optional_param('notifyid', null, PARAM_INT);
list($observation, $course, $cm) = \mod_observation\observation_manager::get_observation_course_cm_from_obid($id);
$pageurl = new moodle_url('/mod/observation/timeslotnotifications.php', ['id' => $id]);
// Check permissions.
require_login($course, true, $cm);
// Check for actions in URL params.
if (!empty($action)) {
if (empty($notifyid)) {
throw new \moodle_exception('missingparam', 'error', null, $a = 'notifyid');
}
if ($action === 'delete') {
require_sesskey();
\mod_observation\timeslot_manager::delete_notification($observation->id, $USER->id, $notifyid);
redirect($pageurl);
}
}
// Get current timeslot user registered to.
$timeslot = \mod_observation\timeslot_manager::get_registered_timeslot($observation->id, $USER->id);
// Load forms.
$prefill = [
'id' => $observation->id,
'slotid' => $timeslot->id
];
$notificationeditor = new \mod_observation\form\notificationeditor(null, $prefill);
if ($fromform = $notificationeditor->get_data()) {
$data = (object) [
'interval_amount' => (int)$fromform->interval_amount,
'interval_multiplier' => (int)$fromform->interval_multiplier
];
\mod_observation\timeslot_manager::create_notification($fromform->id, $fromform->slotid, $USER->id, $data);
redirect($pageurl);
}
// Render page.
$PAGE->set_url($pageurl);
$PAGE->set_title($course->shortname.': '.$observation->name);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($observation->name, 2);
echo $OUTPUT->heading(get_string('timeslotnotifications', 'observation'), 3);
$notificationeditor->display();
echo \mod_observation\table\notifications\notifications_display::notifications_table($observation->id, $USER->id, $pageurl);
echo $OUTPUT->footer();