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 / conditionalrules / options.php

options.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/conditionalrules/options.php

133 lines 3.2 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 "options".
15 *
16 * @since 1.4.0
17 */
18 class VikBookingConditionalRuleOptions 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('VBOREPORTOPTIONSEXTRAS');
29 $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_OPTS_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 $options = $this->loadOptions();
42 $current_options = $this->getParam('options', array());
43 ?>
44 <div class="vbo-param-container">
45 <div class="vbo-param-label"><?php echo JText::translate('VBOREPORTOPTIONSEXTRAS'); ?></div>
46 <div class="vbo-param-setting">
47 <select name="<?php echo $this->inputName('options', true); ?>" id="<?php echo $this->inputID('options'); ?>" multiple="multiple">
48 <?php
49 foreach ($options as $odata) {
50 ?>
51 <option value="<?php echo $odata['id']; ?>"<?php echo is_array($current_options) && in_array($odata['id'], $current_options) ? ' selected="selected"' : ''; ?>><?php echo $odata['name']; ?></option>
52 <?php
53 }
54 ?>
55 </select>
56 </div>
57 </div>
58
59 <script type="text/javascript">
60 jQuery(function() {
61 jQuery('#<?php echo $this->inputID('options'); ?>').select2();
62 });
63 </script>
64 <?php
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 $opt_booked = $this->getProperty('rooms', array());
75 if (!is_array($opt_booked) || !count($opt_booked)) {
76 return false;
77 }
78
79 $all_opt_ids = array();
80 foreach ($opt_booked as $book) {
81 if (empty($book['optionals'])) {
82 continue;
83 }
84 $parts = explode(';', $book['optionals']);
85 foreach ($parts as $optvals) {
86 if (empty($optvals)) {
87 continue;
88 }
89 $parts_two = explode(':', $optvals);
90 array_push($all_opt_ids, (int)$parts_two[0]);
91 }
92 }
93
94 if (!count($all_opt_ids)) {
95 return false;
96 }
97
98 $allowed_options = $this->getParam('options', array());
99
100 $one_found = false;
101 foreach ($all_opt_ids as $idopt) {
102 if (in_array($idopt, $allowed_options)) {
103 $one_found = true;
104 break;
105 }
106 }
107
108 // return true if at least one option booked is in the parameters
109 return $one_found;
110 }
111
112 /**
113 * Internal function for this rule only.
114 *
115 * @return array
116 */
117 protected function loadOptions()
118 {
119 $options = array();
120
121 $dbo = JFactory::getDbo();
122 $q = "SELECT `id`, `name` FROM `#__vikbooking_optionals` ORDER BY `name` ASC;";
123 $dbo->setQuery($q);
124 $dbo->execute();
125 if ($dbo->getNumRows()) {
126 $options = $dbo->loadAssocList();
127 }
128
129 return $options;
130 }
131
132 }
133