| @@ -1,0 +1,89 @@ | ||
| 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 "booking dates". | |
| 15 | + * | |
| 16 | + * @since 1.4.0 | |
| 17 | + */ | |
| 18 | +class VikBookingConditionalRuleBookingDates 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_BOOKDATES'); | |
| 29 | + $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_BOOKDATES_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 | + $book_time = $this->getPropVal('booking', 'ts'); | |
| 75 | + | |
| 76 | + if (!$book_time) { | |
| 77 | + return false; | |
| 78 | + } | |
| 79 | + | |
| 80 | + $from_date = $this->getParam('from_date', ''); | |
| 81 | + | |
| 82 | + // return true if booking date is inside the dates interval | |
| 83 | + return ( | |
| 84 | + $book_time >= VikBooking::getDateTimestamp($from_date, 0, 0, 0) && | |
| 85 | + $book_time <= VikBooking::getDateTimestamp($this->getParam('to_date', $from_date), 23, 59, 59) | |
| 86 | + ); | |
| 87 | + } | |
| 88 | + | |
| 89 | +} | |