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
← All changes | admin/helpers/conditionalrules/stay_dates.php +95 -0 1.6.2 → 1.8.16 View file →
@@ -1,0 +1,95 @@
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 "stay dates".
15 + *
16 + * @since 1.4.0
17 + */
18 +class VikBookingConditionalRuleStayDates 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('VBO_CONDTEXT_RULE_STAYDATES');
29 + $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_STAYDATES_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('VBNEWRESTRICTIONDFROMRANGE'); ?></div>
43 + <div class="vbo-param-setting">
44 + <?php echo $this->vbo_app->getCalendar($this->getParam('from_date', ''), $this->inputName('from_date'), $this->inputID('from_date'), $this->wdf, array('class'=>'', 'size'=>'10', 'maxlength'=>'19', 'todayBtn' => 'true')); ?>
45 + </div>
46 + </div>
47 + <div class="vbo-param-container">
48 + <div class="vbo-param-label"><?php echo JText::translate('VBNEWRESTRICTIONDTORANGE'); ?></div>
49 + <div class="vbo-param-setting">
50 + <?php echo $this->vbo_app->getCalendar($this->getParam('to_date', ''), $this->inputName('to_date'), $this->inputID('to_date'), $this->wdf, array('class'=>'', 'size'=>'10', 'maxlength'=>'19', 'todayBtn' => 'true')); ?>
51 + </div>
52 + </div>
53 + <?php
54 + if ($this->getParams() !== null) {
55 + // some date-picker calendars may need to have their default value populated when the document is ready
56 + ?>
57 + <script type="text/javascript">
58 + jQuery(function() {
59 + jQuery('#<?php echo $this->inputID('from_date'); ?>').val('<?php echo $this->getParam('from_date', ''); ?>').attr('data-alt-value', '<?php echo $this->getParam('from_date', ''); ?>');
60 + jQuery('#<?php echo $this->inputID('to_date'); ?>').val('<?php echo $this->getParam('to_date', ''); ?>').attr('data-alt-value', '<?php echo $this->getParam('to_date', ''); ?>');
61 + });
62 + </script>
63 + <?php
64 + }
65 + }
66 +
67 + /**
68 + * Tells whether the rule is compliant.
69 + *
70 + * @return bool True on success, false otherwise.
71 + */
72 + public function isCompliant()
73 + {
74 + $checkin = $this->getPropVal('booking', 'checkin');
75 + $checkout = $this->getPropVal('booking', 'checkout');
76 +
77 + if (!$checkin || !$checkout) {
78 + return false;
79 + }
80 +
81 + $from_date = $this->getParam('from_date', '');
82 + $from_ts = VikBooking::getDateTimestamp($from_date, 0, 0, 0);
83 + $to_ts = VikBooking::getDateTimestamp($this->getParam('to_date', $from_date), 23, 59, 59);
84 +
85 + // return true if check-in or check-out dates are inside the dates interval
86 + return (
87 + $checkin >= $from_ts &&
88 + $checkin <= $to_ts
89 + ) || (
90 + $checkout >= $from_ts &&
91 + $checkout <= $to_ts
92 + );
93 + }
94 +
95 +}