| @@ -1,0 +1,117 @@ | ||
| 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 "week days". | |
| 15 | + * | |
| 16 | + * @since 1.4.3 | |
| 17 | + */ | |
| 18 | +class VikBookingConditionalRuleWeekDays 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('VBSEASONDAYS'); | |
| 29 | + $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_WDAYS_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 | + $this->vbo_app->loadSelect2(); | |
| 41 | + $wdays = array( | |
| 42 | + JText::translate('VBSUNDAY'), | |
| 43 | + JText::translate('VBMONDAY'), | |
| 44 | + JText::translate('VBTUESDAY'), | |
| 45 | + JText::translate('VBWEDNESDAY'), | |
| 46 | + JText::translate('VBTHURSDAY'), | |
| 47 | + JText::translate('VBFRIDAY'), | |
| 48 | + JText::translate('VBSATURDAY'), | |
| 49 | + ); | |
| 50 | + $current_wdays = $this->getParam('wdays', array()); | |
| 51 | + ?> | |
| 52 | + <div class="vbo-param-container"> | |
| 53 | + <div class="vbo-param-label"><?php echo JText::translate('VBWEEKDAYS'); ?></div> | |
| 54 | + <div class="vbo-param-setting"> | |
| 55 | + <select name="<?php echo $this->inputName('wdays', true); ?>" id="<?php echo $this->inputID('wdays'); ?>" multiple="multiple"> | |
| 56 | + <?php | |
| 57 | + foreach ($wdays as $wdk => $wdv) { | |
| 58 | + ?> | |
| 59 | + <option value="<?php echo $wdk; ?>"<?php echo is_array($current_wdays) && in_array($wdk, $current_wdays) ? ' selected="selected"' : ''; ?>><?php echo $wdv; ?></option> | |
| 60 | + <?php | |
| 61 | + } | |
| 62 | + ?> | |
| 63 | + </select> | |
| 64 | + </div> | |
| 65 | + </div> | |
| 66 | + <div class="vbo-param-container"> | |
| 67 | + <div class="vbo-param-label"><?php echo JText::translate('VBPVIEWCUSTOMFTWO'); ?></div> | |
| 68 | + <div class="vbo-param-setting"> | |
| 69 | + <select name="<?php echo $this->inputName('type'); ?>" id="<?php echo $this->inputID('type'); ?>"> | |
| 70 | + <option value=""></option> | |
| 71 | + <option value="checkin"<?php echo $this->getParam('type', '') == 'checkin' ? ' selected="selected"' : ''; ?>><?php echo JText::translate('VBPICKUPAT'); ?></option> | |
| 72 | + <option value="checkout"<?php echo $this->getParam('type', '') == 'checkout' ? ' selected="selected"' : ''; ?>><?php echo JText::translate('VBRELEASEAT'); ?></option> | |
| 73 | + <option value="both"<?php echo $this->getParam('type', '') == 'both' ? ' selected="selected"' : ''; ?>><?php echo JText::translate('VBPICKUPAT') . ' | ' . JText::translate('VBRELEASEAT'); ?></option> | |
| 74 | + </select> | |
| 75 | + </div> | |
| 76 | + </div> | |
| 77 | + | |
| 78 | + <script type="text/javascript"> | |
| 79 | + jQuery(function() { | |
| 80 | + jQuery('#<?php echo $this->inputID('wdays'); ?>').select2(); | |
| 81 | + }); | |
| 82 | + </script> | |
| 83 | + <?php | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Tells whether the rule is compliant. | |
| 88 | + * | |
| 89 | + * @return bool True on success, false otherwise. | |
| 90 | + */ | |
| 91 | + public function isCompliant() | |
| 92 | + { | |
| 93 | + $book_in = $this->getPropVal('booking', 'checkin', 0); | |
| 94 | + $book_out = $this->getPropVal('booking', 'checkout', 0); | |
| 95 | + | |
| 96 | + if (empty($book_in) || empty($book_out)) { | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + $info_in = getdate($book_in); | |
| 101 | + $info_out = getdate($book_out); | |
| 102 | + | |
| 103 | + $involved_wdays = $this->getParam('wdays', array()); | |
| 104 | + $involved_type = $this->getParam('type', 'checkin'); | |
| 105 | + | |
| 106 | + if ($involved_type == 'checkin') { | |
| 107 | + return (in_array($info_in['wday'], $involved_wdays)); | |
| 108 | + } | |
| 109 | + | |
| 110 | + if ($involved_type == 'checkout') { | |
| 111 | + return (in_array($info_out['wday'], $involved_wdays)); | |
| 112 | + } | |
| 113 | + | |
| 114 | + return (in_array($info_in['wday'], $involved_wdays) || in_array($info_out['wday'], $involved_wdays)); | |
| 115 | + } | |
| 116 | + | |
| 117 | +} | |