PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.14
VikBooking Hotel Booking Engine & PMS v1.8.14
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 / conditionalrules / number_of_guests.php

number_of_guests.php in VikBooking Hotel Booking Engine & PMS 1.8.14, at admin/helpers/conditionalrules/number_of_guests.php

140 lines 4.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 com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Class handler for conditional rule "number of guests".
15 *
16 * @since 1.4.0
17 */
18 class VikBookingConditionalRuleNumberOfGuests extends VikBookingConditionalRule
19 {
20 /**
21 * Class constructor will define the rule name, description and identifier.
22 */
23 public function __construct()
24 {
25 // call parent constructor
26 parent::__construct();
27
28 $this->ruleName = JText::translate('VBOINVTOTGUESTS');
29 $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_NOG_DESCR');
30 $this->ruleId = basename(__FILE__);
31 }
32
33 /**
34 * Displays the rule parameters.
35 *
36 * @return void
37 */
38 public function renderParams()
39 {
40 ?>
41 <div class="vbo-param-container">
42 <div class="vbo-param-label"><?php echo JText::translate('VBNEWROOMADULTS'); ?></div>
43 <div class="vbo-param-setting">
44 <div class="vbo-param-setting-group">
45 <div class="vbplusminuscont">
46 <span><?php echo JText::translate('VBNEWROOMMIN'); ?></span>
47 <input type="number" min="0" name="<?php echo $this->inputName('from_adults'); ?>" value="<?php echo $this->getParam('from_adults', ''); ?>" style="width: 40px;"/>
48 </div>
49 </div>
50 <div class="vbo-param-setting-group">
51 <div class="vbplusminuscont">
52 <span><?php echo JText::translate('VBNEWROOMMAX'); ?></span>
53 <input type="number" min="0" name="<?php echo $this->inputName('to_adults'); ?>" value="<?php echo $this->getParam('to_adults', ''); ?>" style="width: 40px;"/>
54 </div>
55 </div>
56 </div>
57 </div>
58 <div class="vbo-param-container">
59 <div class="vbo-param-label"><?php echo JText::translate('VBNEWROOMCHILDREN'); ?></div>
60 <div class="vbo-param-setting">
61 <div class="vbo-param-setting-group">
62 <div class="vbplusminuscont">
63 <span><?php echo JText::translate('VBNEWROOMMIN'); ?></span>
64 <input type="number" min="0" name="<?php echo $this->inputName('from_children'); ?>" value="<?php echo $this->getParam('from_children', ''); ?>" style="width: 40px;"/>
65 </div>
66 </div>
67 <div class="vbo-param-setting-group">
68 <div class="vbplusminuscont">
69 <span><?php echo JText::translate('VBNEWROOMMAX'); ?></span>
70 <input type="number" min="0" name="<?php echo $this->inputName('to_children'); ?>" value="<?php echo $this->getParam('to_children', ''); ?>" style="width: 40px;"/>
71 </div>
72 </div>
73 </div>
74 </div>
75 <div class="vbo-param-container">
76 <div class="vbo-param-label"><?php echo JText::translate('VBMAXTOTPEOPLE'); ?></div>
77 <div class="vbo-param-setting">
78 <div class="vbo-param-setting-group">
79 <div class="vbplusminuscont">
80 <span><?php echo JText::translate('VBNEWROOMMIN'); ?></span>
81 <input type="number" min="0" name="<?php echo $this->inputName('from_totguests'); ?>" value="<?php echo $this->getParam('from_totguests', ''); ?>" style="width: 40px;"/>
82 </div>
83 </div>
84 <div class="vbo-param-setting-group">
85 <div class="vbplusminuscont">
86 <span><?php echo JText::translate('VBNEWROOMMAX'); ?></span>
87 <input type="number" min="0" name="<?php echo $this->inputName('to_totguests'); ?>" value="<?php echo $this->getParam('to_totguests', ''); ?>" style="width: 40px;"/>
88 </div>
89 </div>
90 </div>
91 </div>
92 <?php
93 }
94
95 /**
96 * Tells whether the rule is compliant.
97 *
98 * @return bool True on success, false otherwise.
99 */
100 public function isCompliant()
101 {
102 $rooms_booked = $this->getProperty('rooms', array());
103 if (!is_array($rooms_booked) || !count($rooms_booked)) {
104 return false;
105 }
106
107 // count total guests booked
108 $booked_adults = 0;
109 $booked_children = 0;
110 foreach ($rooms_booked as $rb) {
111 $booked_adults += (int)$rb['adults'];
112 $booked_children += (int)$rb['children'];
113 }
114 $booked_totguests = $booked_adults + $booked_children;
115
116 $enough = true;
117
118 $from_adults = $this->getParam('from_adults', null);
119 $to_adults = $this->getParam('to_adults', $from_adults);
120 if ($from_adults !== null && ($booked_adults < $from_adults || $booked_adults > $to_adults)) {
121 $enough = false;
122 }
123
124 $from_children = $this->getParam('from_children', null);
125 $to_children = $this->getParam('to_children', $from_children);
126 if ($from_children !== null && ($booked_children < $from_children || $booked_children > $to_children)) {
127 $enough = false;
128 }
129
130 $from_totguests = $this->getParam('from_totguests', null);
131 $to_totguests = $this->getParam('to_totguests', $from_totguests);
132 if ($from_totguests !== null && ($booked_totguests < $from_totguests || $booked_totguests > $to_totguests)) {
133 $enough = false;
134 }
135
136 return $enough;
137 }
138
139 }
140