-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathview.php
More file actions
executable file
·217 lines (184 loc) · 7.51 KB
/
Copy pathview.php
File metadata and controls
executable file
·217 lines (184 loc) · 7.51 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?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/>.
/**
* This is the main entrance point for the booking plugin showing a table of all booking options.
*
* Completely rebuilt in January 2023.
*
* @package mod_booking
* @copyright 2023 Wunderbyte GmbH <info@wunderbyte.at>
* @author David Bogner, Georg Maißer, Bernhard Fischer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_booking\customfield\booking_handler;
use mod_booking\output\business_card;
use mod_booking\output\view;
use mod_booking\local\htmlcomponents;
use mod_booking\singleton_service;
require_once(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/comment/lib.php');
// No guest autologin.
require_login(0, false);
global $DB, $PAGE, $OUTPUT, $USER, $CFG;
$cmid = required_param('id', PARAM_INT); // Course Module ID.
$optionid = optional_param('optionid', 0, PARAM_INT);
$download = optional_param('download', '', PARAM_ALPHA);
$whichview = optional_param('whichview', '', PARAM_ALPHA);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'booking');
require_course_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/booking:view', $context);
// Block site admins if legacy mail templates are still enabled but the removal has not been acknowledged.
// This can be removed in a future release once legacy mails have been removed completely.
if (
is_siteadmin()
&& !empty(get_config('booking', 'uselegacymailtemplates'))
&& empty(get_config('booking', 'legacymailremovalacknowledged'))
&& !defined('BEHAT_SITE_RUNNING') // Do not block in Behat tests.
) {
$settingsurl = new moodle_url(
'/admin/settings.php',
['section' => 'modsettingbooking'],
'admin-uselegacymailtemplates'
);
$PAGE->set_url(new moodle_url('/mod/booking/view.php', ['id' => $cmid]));
$PAGE->set_context($context);
$PAGE->set_title(get_string('modulename', 'mod_booking'));
$PAGE->set_heading(get_string('modulename', 'mod_booking'));
echo $OUTPUT->header();
echo $OUTPUT->notification(
get_string('upgrade:legacymailacknowledgementrequired', 'mod_booking', $settingsurl->out()),
\core\output\notification::NOTIFY_WARNING,
false
);
echo $OUTPUT->footer();
exit;
}
// URL params.
$urlparams = [
'id' => $cmid,
];
// SQL params.
$params = [];
$booking = singleton_service::get_instance_of_booking_by_cmid($cmid);
$booking->checkautocreate();
$PAGE->set_context($context);
// Trigger course_module_viewed event.
$event = \mod_booking\event\course_module_viewed::create(
['objectid' => $cm->instance, 'context' => $context]
);
$event->add_record_snapshot('course', $course);
$event->trigger();
// Get the booking instance settings by cmid.
$bookingsettings = singleton_service::get_instance_of_booking_settings_by_cmid($cmid);
$title = $bookingsettings->name;
$baseurl = new moodle_url('/mod/booking/view.php', $urlparams);
$PAGE->set_url($baseurl);
$PAGE->navbar->add($title);
$PAGE->set_title(format_string($title));
$PAGE->set_heading($title);
$PAGE->set_pagelayout('incourse');
$PAGE->add_body_class('mod_booking-view');
// Get the renderer.
/** @var \mod_booking\output\renderer $output */
$output = $PAGE->get_renderer('mod_booking');
echo $OUTPUT->header();
// Show a clear message if the instance references customfields that are missing on this
// platform, e.g. after restoring a course backup from another Moodle site.
echo booking_handler::create()->check_for_missing_customfields_and_return_warning($bookingsettings, $context);
// If we have specified a teacher as organizer, we show a "busines_card" with photo, else legacy organizer description.
$organizerhtml = '';
if (
!empty($bookingsettings->organizatorname)
&& ($organizerid = (int)$bookingsettings->organizatorname)
) {
$data = new business_card($bookingsettings, $organizerid);
$organizerhtml = $output->render_business_card($data);
}
// Attachments.
$out = [];
$fs = get_file_storage();
$files = $fs->get_area_files(
$context->id,
'mod_booking',
'myfilemanager',
$bookingsettings->id
);
if (count($files) > 1) {
echo html_writer::start_tag('div');
echo html_writer::tag('label', '<i class="fa fa-paperclip" aria-hidden="true"></i> ' .
get_string('attachedfiles', 'mod_booking') . ': ', ['class' => 'ms-3 mt-1 mb-3 bold']);
foreach ($files as $file) {
if ($file->get_filesize() > 0) {
$filename = $file->get_filename();
$url = moodle_url::make_pluginfile_url(
$file->get_contextid(),
$file->get_component(),
$file->get_filearea(),
$file->get_itemid(),
$file->get_filepath(),
$file->get_filename(),
true
);
$out[] = html_writer::link($url, $filename);
}
}
echo html_writer::tag('span', implode(', ', $out), ['class' => 'ms-2']);
echo html_writer::end_tag('div');
}
// Booking instance tags (default Moodle tags).
if (!empty($CFG->usetags)) {
$tags = core_tag_tag::get_item_tags('mod_booking', 'booking', $bookingsettings->id);
echo $OUTPUT->tag_list($tags, null, 'booking-tags ms-3 mb-3');
}
// As of Moodle 4.0 activity description will be shown automatically in module header.
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
/* else {
$data = new instance_description($bookingsettings);
echo $output->render_instance_description($data);
} */
// Now we show the actual view.
$view = new view($cmid, $whichview, $optionid);
$classicview = $organizerhtml . $output->render_view($view);
$enginecomponent = \mod_booking\local\wizard\engine_component::active();
$aireadyclass = \mod_booking\local\wizard\engine_component::aiready_class();
$hasoptions = $booking->get_all_options_count() > 0;
$tabs = [
[
'title' => '<i class="fa fa-list" aria-hidden="true"></i>',
'label' => get_string('classicview', 'mod_booking'),
'body' => $classicview,
'active' => $hasoptions,
],
];
if (!empty($aireadyclass)) {
$aitemplatedata = (new $aireadyclass((int)$context->id, $USER->id))->export_for_template();
$tabs[] = [
'title' => '<i class="fa fa-magic" aria-hidden="true"></i>',
'label' => get_string('aiinstructions', $enginecomponent),
'body' => $OUTPUT->render_from_template($enginecomponent . '/aiinstructions', $aitemplatedata),
'active' => !$hasoptions,
];
}
echo htmlcomponents::render_bootstrap_earmarks($tabs, 'booking-view-tabs-' . $cmid);
if (!get_config('booking', 'turnoffwunderbytelogo')) {
// Wunderbyte info and footer.
$logourl = new moodle_url('/mod/booking/pix/wb-logo.png');
echo $OUTPUT->box('<a href="https://www.wunderbyte.at" target="_blank"><img src="' .
$logourl . '" width="200px" alt="Wunderbyte logo"><br>' .
get_string('createdbywunderbyte', 'mod_booking') . "</a>", 'box mdl-align');
}
echo $OUTPUT->footer();