PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / site / layouts / taskmanager / calendar / day.php

day.php in VikBooking Hotel Booking Engine & PMS 1.8.16, at site/layouts/taskmanager/calendar/day.php

293 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2025 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Obtain vars from arguments received in the layout file.
16 *
17 * @var string $tool The operator tool identifier calling this layout file.
18 * @var array $operator The operator record accessing the tool.
19 * @var object $permissions The operator-tool permissions registry.
20 * @var string $tool_uri The base URI for rendering this tool.
21 * @var array $data The data for rendering the tasks of a given month within a calendar.
22 * @var int $no_tasks True for just displaying the day with no tasks, can be undefined.
23 */
24 extract($displayData);
25
26 if (!$operator || empty($operator['id'])) {
27 throw new Exception('Missing operator details', 400);
28 }
29
30 // check no-loading flag
31 $no_loading = (bool) ($no_tasks ?? 0);
32
33 // get the filters for rendering the calendar tasks
34 $filters = (array) ($data['filters'] ?? []);
35
36 // get the current operator permissions
37 $accept_tasks = (bool) ($permissions ? $permissions->get('accept_tasks', 0) : 0);
38
39 // determine the day to load
40 $dayYmd = $filters['calendar_day'] ?? date('Y-m-d');
41 if (($filters['dates'] ?? null) && !($filters['calendar_day'] ?? null)) {
42 // when no calendar day filter set, use the current dates filter
43 list($fromDt, $toDt) = VBOTaskModelTask::getInstance()->getFilterDatesInterval((string) $filters['dates'], $local = true, $sql = false);
44 if ($fromDt) {
45 $dayYmd = date('Y-m-d', strtotime($fromDt));
46 }
47 }
48
49 // build the pool of day tasks
50 $dayTasks = [];
51
52 if (!$no_loading) {
53 // save current filters in the user state
54 JFactory::getApplication()->setUserState('vbo.tm.filters', $filters);
55
56 // check from the permissions whether tasks can be accepted by the operator,
57 // hence null assigness should be included - use a different filter otherwise
58 $operatorTasksFilterName = $accept_tasks ? 'operator' : 'assignee';
59
60 // build filter options for fetching the tasks
61 $fetchOptions = array_merge($filters, [
62 $operatorTasksFilterName => $operator['id'],
63 'dates' => $dayYmd . ':' . $dayYmd,
64 'calendar' => true,
65 ]);
66
67 // load tasks according to filters, by always forcing/injecting the dates and the assignee/operator filter
68 foreach (VBOTaskModelTask::getInstance()->filterItems($fetchOptions, 0, 0) as $taskRecord) {
69 // push task registry
70 $dayTasks[] = VBOTaskTaskregistry::getInstance((array) $taskRecord);
71 }
72 }
73
74 // obtain the current day information
75 $dayDate = getdate(strtotime($dayYmd));
76
77 // get navigation dates
78 $todayYmd = date('Y-m-d');
79 $dayBack = date('Y-m-d', strtotime('-1 day', $dayDate[0]));
80 $dayNext = date('Y-m-d', strtotime('+1 day', $dayDate[0]));
81
82 // build the task objects, if any, for JS positioning
83 $taskObjects = [];
84 foreach ($dayTasks as $dayTask) {
85 $duration = $dayTask->getDuration();
86
87 $start = $dayTask->getDueDate(true, 'Y-m-d\TH:i:s');
88 $begin = $dayTask->getBeginDate(true, 'Y-m-d\TH:i:s');
89
90 if ($begin) {
91 $start = $begin;
92 }
93
94 $startDate = JFactory::getDate($start);
95
96 // get selected date at midnight
97 $dateMidnight = JFactory::getDate($dayYmd . ' 00:00:00');
98
99 // check whether the event starts on a previous date
100 if ($startDate < $dateMidnight) {
101 // decrease duration by the difference between today and the real start date
102 $diff = $startDate->diff($dateMidnight);
103 $duration -= $diff->days * 1440 + $diff->h * 60 + $diff->i;
104
105 // use today at midnight
106 $startDate = clone $dateMidnight;
107 }
108
109 if ($duration <= 0) {
110 // ignore the event in case of invalid duration
111 continue;
112 }
113
114 $endDate = clone $startDate;
115 $endDate->modify('+' . $duration . ' minutes');
116
117 // extract hours and minutes
118 list($hour, $min) = explode(':', $startDate->format('G:i'));
119
120 $taskObjects[] = [
121 'id' => $dayTask->getID(),
122 'start' => $startDate->format('Y-m-d\TH:i:s'),
123 'end' => $endDate->format('Y-m-d\TH:i:s'),
124 'hour' => (int) $hour,
125 'min' => (int) $min,
126 'duration' => (int) $duration,
127 'html' => JLayoutHelper::render('taskmanager.calendar.day.task', ['task' => $dayTask], null, [
128 'component' => 'com_vikbooking',
129 'client' => 'site',
130 ]),
131 ];
132 }
133
134 ?>
135
136 <div class="vbo-tm-calendar-wrap">
137 <div class="vbo-tm-calendar-head">
138 <div class="vbo-tm-calendar-info">
139 <a href="javascript:void(0)" class="vbo-tm-calendar-day-back" data-month="<?php echo date('Y-m-01', $dayDate[0]); ?>">
140 <?php echo VikBookingIcons::e('chevron-left'); ?>
141 </a>
142 <span class="vbo-tm-calendar-day-day"><?php echo VikBooking::sayWeekDay($dayDate['wday']) . ', ' . $dayDate['mday']; ?></span>
143 <span class="vbo-tm-calendar-day-month"><?php echo VikBooking::sayMonth($dayDate['mon']); ?></span>
144 <span class="vbo-tm-calendar-day-year"><?php echo $dayDate['year']; ?></span>
145 </div>
146
147 <div class="vbo-tm-calendar-nav">
148 <div class="vbo-tm-calendar-nav-btns">
149 <span class="vbo-tm-calendar-nav-btn vbo-tm-calendar-nav-back" data-day="<?php echo $dayBack; ?>"><?php VikBookingIcons::e('chevron-left'); ?></span>
150 <span class="vbo-tm-calendar-nav-btn vbo-tm-calendar-nav-today" data-day="<?php echo $todayYmd; ?>"><?php echo JText::translate('VBTODAY'); ?></span>
151 <span class="vbo-tm-calendar-nav-btn vbo-tm-calendar-nav-next" data-day="<?php echo $dayNext; ?>"><?php VikBookingIcons::e('chevron-right'); ?></span>
152 </div>
153 </div>
154 </div>
155
156 <div class="vbo-tm-calendar-day-timeline">
157 <div class="vbo-tm-calendar-day-timeline-week">
158
159 <?php
160 // display up to 3 week-days in the past
161 for ($d = 3; $d > 0; $d--) {
162 $timeline_date = getdate(strtotime(sprintf('-%d %s', $d, ($d == 1 ? 'day' : 'days')), $dayDate[0]));
163 ?>
164 <div class="vbo-tm-calendar-day-timeline-week-day">
165 <span class="vbo-tm-calendar-nav-btn vbo-tm-calendar-day-timeline-week-nav" data-day="<?php echo date('Y-m-d', $timeline_date[0]); ?>">
166 <span class="vbo-tm-calendar-day-timeline-week-nav-mday"><?php echo $timeline_date['mday']; ?></span>
167 <span class="vbo-tm-calendar-day-timeline-week-nav-wday"><?php echo VikBooking::sayWeekDay($timeline_date['wday'], true); ?></span>
168 </span>
169 </div>
170 <?php
171 }
172 ?>
173 <div class="vbo-tm-calendar-day-timeline-week-day">
174 <span class="vbo-tm-calendar-nav-btn vbo-tm-calendar-day-timeline-week-nav vbo-tm-calendar-day-timeline-week-today" data-day="<?php echo $todayYmd; ?>">
175 <span class="vbo-tm-calendar-day-timeline-week-nav-mday"><?php echo $dayDate['mday']; ?></span>
176 <span class="vbo-tm-calendar-day-timeline-week-nav-wday"><?php echo VikBooking::sayWeekDay($dayDate['wday'], true); ?></span>
177 </span>
178 </div>
179 <?php
180 // display up to 3 week-days ahead
181 for ($d = 1; $d < 4; $d++) {
182 $timeline_date = getdate(strtotime(sprintf('+%d %s', $d, ($d == 1 ? 'day' : 'days')), $dayDate[0]));
183 ?>
184 <div class="vbo-tm-calendar-day-timeline-week-day">
185 <span class="vbo-tm-calendar-nav-btn vbo-tm-calendar-day-timeline-week-nav" data-day="<?php echo date('Y-m-d', $timeline_date[0]); ?>">
186 <span class="vbo-tm-calendar-day-timeline-week-nav-mday"><?php echo $timeline_date['mday']; ?></span>
187 <span class="vbo-tm-calendar-day-timeline-week-nav-wday"><?php echo VikBooking::sayWeekDay($timeline_date['wday'], true); ?></span>
188 </span>
189 </div>
190 <?php
191 }
192 ?>
193 </div>
194 <div class="vbo-tm-calendar-day-timeline-rows">
195 <?php
196 for ($h = 0; $h < 24; $h++) {
197 ?>
198 <div class="vbo-tm-calendar-day-timeline-row" data-hour="<?php echo $h; ?>">
199 <div class="vbo-tm-calendar-day-hour">
200 <strong><?php echo str_pad($h, 2, '0', STR_PAD_LEFT) . ':' . '00'; ?></strong>
201 </div>
202 <div class="vbo-tm-calendar-day-tasks"></div>
203 </div>
204 <?php
205 }
206 ?>
207 </div>
208 </div>
209 </div>
210
211 <script type="text/javascript">
212 jQuery(function($) {
213 // setup the task (events) within the calendar daily layout
214 window.taskManagerSetupCalendar(<?php echo json_encode($taskObjects); ?>);
215
216 /**
217 * Register listeners for day navigation buttons.
218 */
219 document
220 .querySelectorAll('.vbo-tm-calendar-nav-btn')
221 .forEach((nav) => {
222 // get the navigation day
223 const day = nav.getAttribute('data-day');
224
225 nav.addEventListener('click', () => {
226 VBOCore.emitEvent('vbo-tm-apply-filters', {
227 filters: {
228 calendar_day: day,
229 },
230 });
231 });
232 });
233
234 /**
235 * Register listeners for month calendar type.
236 */
237 document
238 .querySelectorAll('.vbo-tm-calendar-day-back')
239 .forEach((mname) => {
240 // get the navigation month
241 const month = mname.getAttribute('data-month');
242
243 mname.addEventListener('click', () => {
244 VBOCore.emitEvent('vbo-tm-apply-filters', {
245 filters: {
246 calendar_type: 'month',
247 calendar_month: month,
248 calendar_day: '',
249 },
250 });
251 });
252 });
253
254 /**
255 * Register listeners for viewing an existing task.
256 */
257 document
258 .querySelectorAll('.vbo-tm-calendar-day-task[data-task-id]')
259 .forEach((taskElement) => {
260 if (taskElement.clickListener) {
261 // listener added already
262 return;
263 }
264
265 // get the clicked task and area IDs
266 const taskId = taskElement.getAttribute('data-task-id');
267 const areaId = taskElement.getAttribute('data-area-id');
268
269 if (!taskId || !areaId) {
270 // missing task details
271 return;
272 }
273
274 taskElement.addEventListener('click', (event) => {
275 event.preventDefault();
276 event.stopPropagation();
277
278 VBOCore.emitEvent('vbo-tm-apply-filters', {
279 filters: {
280 calendar_back_type: 'day',
281 calendar_back_day: '<?php echo $dayYmd; ?>',
282 calendar_type: 'taskdetails',
283 task_id: taskId,
284 },
285 });
286 });
287
288 // turn flag on for listener set
289 taskElement.clickListener = true;
290 });
291
292 });
293 </script>