PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
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 1.7.3 All 36 releases
vikbooking / admin / helpers / src / task / driver / params / scheduling.php

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

170 lines 5.8 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 // check if we are dealing with a RtB where previous booking was "pending"
110 $changedToConfirmed = $booking->getPrevious() && $booking->getPreviousProperty('status') === 'standby';
111
112 if (!$booking->detectAlterations() && !$changedToConfirmed) {
113 // do nothing when no significant changes were made to the booking
114 return;
115 }
116
117 // re-scheduling tasks during a booking modification for nights and/or listings
118 // requires a cancellation and a re-creation of all tasks for better accuracy
119
120 // delete all previously scheduled tasks within the current project/area and driver
121 $this->scheduleBookingCancellation($booking);
122
123 // re-schedule the proper tasks as new
124 $this->scheduleBookingConfirmation($booking);
125 }
126
127 /**
128 * @inheritDoc
129 *
130 * This driver will always cancel its previously scheduled cleaning tasks for a booking.
131 *
132 * @see VBOTaskDriverinterface::scheduleBookingCancellation()
133 */
134 public function scheduleBookingCancellation(VBOTaskBooking $booking)
135 {
136 if ($booking->isClosure() || (!$booking->isCancelled() && !$booking->getPrevious())) {
137 // do nothing when we're not dealing with a real booking cancellation or modification
138 return;
139 }
140
141 // access the task model
142 $model = VBOTaskModelTask::getInstance();
143
144 // get all records that belong to this project/area and booking ID
145 $records = $model->getItems([
146 'id_area' => [
147 'value' => $this->getAreaID(),
148 ],
149 'id_order' => [
150 'value' => $booking->getID(),
151 ],
152 ]);
153
154 $taskIds = array_column($records, 'id');
155 if (!$taskIds) {
156 // no tasks to delete
157 return;
158 }
159
160 // delete all the involved tasks
161 if ($model->delete($taskIds)) {
162 // some records were deleted
163 foreach ($records as $record) {
164 // register the deleted task within the collector
165 $this->getCollector()->register((array) $record, 'cancelled');
166 }
167 }
168 }
169 }
170