PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.13
VikBooking Hotel Booking Engine & PMS v1.8.13
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 / admin / helpers / src / task / driver / params / scheduling.php

scheduling.php in VikBooking Hotel Booking Engine & PMS 1.8.13, at admin/helpers/src/task/driver/params/scheduling.php

167 lines 5.6 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 * Task driver scheduling params trait.
16 *
17 * @since 1.18.0 (J) - 1.8.0 (WP)
18 */
19 trait VBOTaskDriverParamsScheduling
20 {
21 /**
22 * Returns the scheduling params:
23 *
24 * - auto schedule
25 * - scheduling frequency
26 * - auto assignment
27 *
28 * @return array
29 *
30 * @see VBOTaskDriverinterface::getParams()
31 */
32 public function useSchedulingParams()
33 {
34 return [
35 'autoschedule' => [
36 'type' => 'checkbox',
37 'default' => 1,
38 'label' => JText::translate('VBO_AUTO_SCHEDULING'),
39 'help' => JText::translate('VBO_AUTO_SCHEDULING_BOOKINGS_HELP'),
40 ],
41 'scheduling' => [
42 'type' => 'select',
43 'label' => JText::translate('VBO_SCHEDULING') . ' / ' . JText::translate('VBO_FREQUENCY'),
44 'options' => [
45 'turnover' => JText::translate('VBO_TURNOVER') . ' (' . JText::translate('VBRELEASEAT') . ')',
46 'prearrival' => JText::translate('VBPICKUPAT'),
47 'daily' => JText::translate('VBO_DAILY'),
48 'every2' => JText::translate('VBO_EVERY_2_DAYS'),
49 'every3' => JText::translate('VBO_EVERY_3_DAYS'),
50 'weekly' => JText::translate('VBO_WEEKLY'),
51 'monthly' => JText::translate('VBO_MONTHLY'),
52 ],
53 'default' => ['turnover'],
54 'multiple' => true,
55 'assets' => true,
56 'asset_options' => [
57 'allowClear' => true,
58 ],
59 ],
60 'autoassignment' => [
61 'type' => 'checkbox',
62 'default' => 1,
63 'label' => JText::translate('VBO_AUTO_ASSIGNMENT'),
64 'help' => JText::translate('VBO_AUTO_ASSIGNMENT_HELP'),
65 ],
66 ];
67 }
68
69 /**
70 * @inheritDoc
71 *
72 * @see VBOTaskDriverinterface::scheduleBookingConfirmation()
73 */
74 public function scheduleBookingConfirmation(VBOTaskBooking $booking)
75 {
76 if ($booking->isClosure() || $booking->isOverbooking() || !$booking->isConfirmed()) {
77 // do nothing when we're not dealing with a real confirmed and accepted reservation
78 return;
79 }
80
81 // get task scheduling and assignment settings
82 $scheduling = (array) $this->getSetting('scheduling');
83 $autoassignment = (bool) $this->getSetting('autoassignment');
84
85 if (!((bool) $this->getSetting('autoschedule')) || !$scheduling) {
86 // automatic scheduling is disabled, or no scheduling intervals defined
87 return;
88 }
89
90 // schedule tasks upon booking confirmation
91 $created = $this->createBookingConfirmationTasks($booking, [
92 'scheduling' => $scheduling,
93 'autoassignment' => $autoassignment,
94 ]);
95 }
96
97 /**
98 * @inheritDoc
99 *
100 * @see VBOTaskDriverinterface::scheduleBookingAlteration()
101 */
102 public function scheduleBookingAlteration(VBOTaskBooking $booking)
103 {
104 if ($booking->isClosure() || $booking->isOverbooking() || !$booking->isConfirmed()) {
105 // do nothing when we're not dealing with a real confirmed and accepted reservation
106 return;
107 }
108
109 if (!$booking->detectAlterations()) {
110 // do nothing when no significant changes were made to the booking
111 return;
112 }
113
114 // re-scheduling tasks during a booking modification for nights and/or listings
115 // requires a cancellation and a re-creation of all tasks for better accuracy
116
117 // delete all previously scheduled tasks within the current project/area and driver
118 $this->scheduleBookingCancellation($booking);
119
120 // re-schedule the proper tasks as new
121 $this->scheduleBookingConfirmation($booking);
122 }
123
124 /**
125 * @inheritDoc
126 *
127 * This driver will always cancel its previously scheduled cleaning tasks for a booking.
128 *
129 * @see VBOTaskDriverinterface::scheduleBookingCancellation()
130 */
131 public function scheduleBookingCancellation(VBOTaskBooking $booking)
132 {
133 if ($booking->isClosure() || (!$booking->isCancelled() && !$booking->getPrevious())) {
134 // do nothing when we're not dealing with a real booking cancellation or modification
135 return;
136 }
137
138 // access the task model
139 $model = VBOTaskModelTask::getInstance();
140
141 // get all records that belong to this project/area and booking ID
142 $records = $model->getItems([
143 'id_area' => [
144 'value' => $this->getAreaID(),
145 ],
146 'id_order' => [
147 'value' => $booking->getID(),
148 ],
149 ]);
150
151 $taskIds = array_column($records, 'id');
152 if (!$taskIds) {
153 // no tasks to delete
154 return;
155 }
156
157 // delete all the involved tasks
158 if ($model->delete($taskIds)) {
159 // some records were deleted
160 foreach ($records as $record) {
161 // register the deleted task within the collector
162 $this->getCollector()->register((array) $record, 'cancelled');
163 }
164 }
165 }
166 }
167