-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathoptionview.php
executable file
·139 lines (115 loc) · 5.14 KB
/
optionview.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
<?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/>.
/**
* Add dates to option.
*
* @package mod_booking
* @copyright 2023 Wunderbyte GmbH <info@wunderbyte.at>
* @author Andraž Prinčič
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_booking\output\bookingoption_description;
use mod_booking\singleton_service;
require_once(__DIR__ . '/../../config.php'); // phpcs:ignore moodle.Files.RequireLogin.Missing
require_once($CFG->dirroot . '/mod/booking/locallib.php');
global $DB, $PAGE, $OUTPUT, $USER;
// We do not want to check login here...
// ...as this page should also be available for not logged in users!
$cmid = required_param('cmid', PARAM_INT); // Course Module ID.
$optionid = required_param('optionid', PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$returnto = optional_param('returnto', '', PARAM_ALPHA);
$returnurl = optional_param('returnurl', '', PARAM_URL);
$modcontext = context_module::instance($cmid);
$syscontext = context_system::instance();
// If we have this setting.
if (!get_config('booking', 'showbookingdetailstoall')) {
require_login();
}
// If we have this setting.
if (!get_config('booking', 'bookonlyondetailspage')) {
require_capability('mod/booking:view', $modcontext);
}
$PAGE->set_context($syscontext);
$url = new moodle_url('/mod/booking/optionview.php', ['cmid' => $cmid, 'optionid' => $optionid]);
$PAGE->set_url($url);
// If the user is logged-in, we check if (s)he has accepted the site policy.
if (isloggedin() && !isguestuser()) {
$currentpolicyversionids = \tool_policy\api::get_current_versions_ids();
if (!empty($currentpolicyversionids)) {
foreach ($currentpolicyversionids as $currentpolicyversionid) {
if (\tool_policy\api::get_agreement_optional($currentpolicyversionid)) {
continue;
}
$acceptance = \tool_policy\api::get_user_version_acceptance($USER->id, $currentpolicyversionid);
if (empty($acceptance)) {
// If the user did not yet accept, we redirect to the policy page.
$policyurl = new moodle_url('/admin/tool/policy/index.php', ['returnurl' => $url]);
redirect($policyurl);
}
}
}
}
$booking = singleton_service::get_instance_of_booking_by_cmid($cmid);
// Make sure, we respect module visibility and activity restrictions on the booking instance.
$modinfo = get_fast_modinfo($booking->course);
$cm = $modinfo->get_cm($cmid);
if (!$cm->uservisible && !get_config('booking', 'bookonlyondetailspage')) {
echo $OUTPUT->header();
echo html_writer::div(
get_string('invisibleoption:notallowed', 'mod_booking'),
"alert alert-danger"
);
echo $OUTPUT->footer();
die();
}
$settings = singleton_service::get_instance_of_booking_option_settings($optionid);
if ($settings && !empty($settings->id)) {
if ($userid == $USER->id || $userid == 0) {
$user = $USER;
} else {
$user = singleton_service::get_instance_of_user($userid);
}
$bookinganswer = singleton_service::get_instance_of_booking_answers($settings);
$PAGE->set_title(format_string($settings->get_title_with_prefix()));
$PAGE->set_pagelayout('base');
echo $OUTPUT->header();
// phpcs:ignore moodle.Commenting.TodoComment.MissingInfoInline
// TODO: The following lines change the context of the PAGE object...
// ... and have therefore to be called after printing the header.
// This needs to be fixed.
$output = $PAGE->get_renderer('mod_booking');
$data = new bookingoption_description($settings->id, null, MOD_BOOKING_DESCRIPTION_OPTIONVIEW, true, null, $user, true);
$data->returnurl = $returnurl ?? false;
// The isinvisible check ONLY checks the "real" invisible option, not the "visible only with direct link".
// As the option here is only possible with direct link, we don't need to check this.
if ($data->is_invisible()) {
// If the user does have the capability to see invisible options...
if (has_capability('mod/booking:canseeinvisibleoptions', $modcontext)) {
// ... then show it.
echo $output->render_bookingoption_description_view($data);
} else {
// User is not entitled to see invisible options.
echo get_string('invisibleoption:notallowed', 'mod_booking');
}
} else {
echo $output->render_bookingoption_description_view($data);
}
} else {
$url = new moodle_url('/mod/booking/view.php', ['id' => $cmid]);
redirect($url);
}
echo $OUTPUT->footer();