-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathview.php
More file actions
199 lines (164 loc) · 6.4 KB
/
Copy pathview.php
File metadata and controls
199 lines (164 loc) · 6.4 KB
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
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Prints an instance of mod_bookit.
*
* @package mod_bookit
* @copyright 2024 Melanie Treitinger, Ruhr-Universität Bochum <melanie.treitinger@ruhr-uni-bochum.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_bookit\event\course_module_viewed;
use mod_bookit\local\manager\resource_manager;
use mod_bookit\local\manager\event_manager;
use mod_bookit\local\manager\event_access_manager;
require(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/lib.php');
$PAGE->requires->css(new moodle_url('/mod/bookit/styles.css'));
// Course module id.
$id = optional_param('id', 0, PARAM_INT);
// Activity instance id.
$b = optional_param('b', 0, PARAM_INT);
if ($id) {
$cm = get_coursemodule_from_id('bookit', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$moduleinstance = $DB->get_record('bookit', ['id' => $cm->instance], '*', MUST_EXIST);
} else {
$moduleinstance = $DB->get_record('bookit', ['id' => $b], '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $moduleinstance->course], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('bookit', $moduleinstance->id, $course->id, false, MUST_EXIST);
}
require_login($course, true, $cm);
$modulecontext = context_module::instance($cm->id);
require_capability('mod/bookit:view', $modulecontext);
$observerrestricted = event_access_manager::is_observer_restricted_mode($modulecontext);
// Status labels for calendar filter (canonical registry vocabulary).
$statusmap = [];
foreach ([0, 1, 2, 3, 4] as $statusvalue) {
$statusmap[$statusvalue] = event_manager::get_booking_status_label($statusvalue);
}
$rooms = resource_manager::get_rooms();
$faculties = event_manager::get_faculties();
// Log view event of calendar.
$event = course_module_viewed::create([
'objectid' => $moduleinstance->id,
'context' => $modulecontext,
]);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('bookit', $moduleinstance);
// JavaScript – filter communication + Export‑modal logic (WORK IN PROGRESS).
$PAGE->requires->jquery();
// Filter Dropdown.
$PAGE->requires->js_call_amd('mod_bookit/filter_dropdown', 'init');
/* -------- send filter changes to the AMD calendar -------------------- */
$PAGE->requires->js_init_code("
require(['jquery'], function($) {
function pushFilters() {
var p = {};
var sel = window.bookitFilterSelected || {};
var r = sel.room || [];
var f = sel.faculty || [];
var s = sel.status || [];
if (r.length) { p.room = r.join(','); }
if (f.length) { p.faculty = f.join(','); }
if (s.length) { p.status = s.join(','); }
window.currentFilterParams = p;
if (window.bookitCalendarUpdate) {
window.bookitCalendarUpdate(p);
}
}
// Delegated: works even if the selects are rendered later.
$(document).on('change', '#filter-room, #filter-faculty, #filter-status', pushFilters);
});
");
/* -------- Export modal ------------------------------------------------ */
$calendarreadconfig = [
'methodname' => 'mod_bookit_get_calendar_events',
'cmid' => (int)$cm->id,
];
$PAGE->requires->js_call_amd('mod_bookit/export_modal', 'init', [$calendarreadconfig]);
$capabilities = [
'addevent' => has_capability('mod/bookit:addevent', $modulecontext),
];
// Minor change to main: Handles edge cases better now.
$configcalendar = [];
$tc = get_config('mod_bookit', 'textcolor');
if ($tc !== false && $tc !== null && $tc !== '') {
$configcalendar['textcolor'] = $tc;
}
// Inject allowed weekdays for JS (NEW FEATURE).
$PAGE->requires->js_init_code(
'M.cfg.bookit_allowedweekdays = [' . implode(',', bookit_allowed_weekdays()) . '];'
);
// Log the view event.
$event = course_module_viewed::create([
'objectid' => $moduleinstance->id,
'context' => $modulecontext,
]);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('bookit', $moduleinstance);
$event->trigger();
// Set page settings.
$PAGE->set_url('/mod/bookit/view.php', ['id' => $cm->id]);
$PAGE->set_title(format_string($moduleinstance->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($modulecontext);
// Calendar JS/CSS.
$PAGE->requires->js(new moodle_url('/mod/bookit/thirdpartylibs/event-calendar/event-calendar.min.js'), true);
$PAGE->requires->css(new moodle_url('/mod/bookit/thirdpartylibs/event-calendar/event-calendar.min.css'));
$PAGE->requires->css(new moodle_url('/mod/bookit/thirdpartylibs/event-calendar/custom-calendar.min.css'));
// Page Output.
echo $OUTPUT->header();
// Mustache for Filter Bar + Export Button.
$templatecontext = [
'rooms' => [],
'faculties' => [],
'statuses' => [],
'canfilterstatus' => has_capability('mod/bookit:filterstatus', $modulecontext),
'canexportevents' => !$observerrestricted,
];
foreach ($rooms as $rid => $rname) {
$templatecontext['rooms'][] = [
'value' => (string)$rid,
'label' => format_string($rname),
];
}
foreach ($faculties as $fid => $fname) {
$templatecontext['faculties'][] = [
'value' => (string) $fid,
'label' => format_string($fname),
];
}
foreach ($statusmap as $scode => $label) {
$templatecontext['statuses'][] = [
'value' => (string)$scode,
'label' => (string)$label,
];
}
// Render HTML via mustache templates.
echo $OUTPUT->render_from_template('mod_bookit/view/calendar_view', $templatecontext);
// Initialise AMD calendar (from original file).
$PAGE->requires->js_call_amd(
'mod_bookit/calendar',
'init',
[
$cm->id,
$calendarreadconfig,
$capabilities,
current_language(),
$configcalendar,
]
);
echo $OUTPUT->footer();