ruleName = JText::translate('VBPVIEWORDERSTHREE'); $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_ROOMS_DESCR'); $this->ruleId = basename(__FILE__); } /** * Displays the rule parameters. * * @return void * * @since 1.15.0 (J) - 1.5.0 (WP) added support for sub-units. */ public function renderParams() { $this->vbo_app->loadSelect2(); $rooms = $this->loadRooms(); $current_rooms = $this->getParam('rooms', array()); $current_rooms = !is_array($current_rooms) ? array() : $current_rooms; // check if we've got rooms with sub-units defined $sub_units = []; foreach ($rooms as $rdata) { if ($rdata['units'] < 2) { continue; } $room_features = VikBooking::getRoomParam('features', $rdata['params']); if (is_array($room_features) && count($room_features)) { $sub_units[$rdata['id']] = [ 'name' => $rdata['name'], 'units' => $rdata['units'], 'features' => $room_features, ]; } } ?>
vbo_app->printYesNoButtons($this->inputName('use_sub_units'), JText::translate('VBYES'), JText::translate('VBNO'), (int)$this->getParam('use_sub_units', 0), 1, 0, 'vboToggleUseSubUnits();'); ?>
getParam('use_sub_units', 0); foreach ($sub_units as $rid => $rdata) { $display_runits = ($init_display && in_array($rid, $current_rooms)); ?>
getProperty('rooms', array()); if (!is_array($rooms_booked) || !count($rooms_booked)) { return false; } $allowed_rooms = $this->getParam('rooms', array()); $one_found = false; foreach ($rooms_booked as $rb) { if (!isset($rb['idroom'])) { continue; } if (in_array($rb['idroom'], $allowed_rooms)) { $one_found = true; break; } } // check sub-units $use_sub_units = (int)$this->getParam('use_sub_units', 0); if ($use_sub_units) { $sub_unit_matched = false; // parse again the rooms booked foreach ($rooms_booked as $rb) { // grab the sub-unit index for this room id $room_sub_unit_filt = (int)$this->getParam('sub_unit_' . $rb['idroom'], 0); if (empty($room_sub_unit_filt)) { // no sub-unit defined for this room ID continue; } if ($rb['roomindex'] == $room_sub_unit_filt) { // the index of the room booked matched the one in the params $sub_unit_matched = true; } } return $one_found && $sub_unit_matched; } // return true if at least one room booked is in the parameters return $one_found; } /** * Internal function for this rule only. * * @return array */ protected function loadRooms() { $rooms = array(); $dbo = JFactory::getDbo(); $q = "SELECT `id`, `name`, `units`, `params` FROM `#__vikbooking_rooms` ORDER BY `name` ASC;"; $dbo->setQuery($q); $dbo->execute(); if ($dbo->getNumRows()) { $rooms = $dbo->loadAssocList(); } return $rooms; } /** * Internal function for this rule only. * * @param int $i the room unit index to get. * @param array $features the list of room features. * * @return array */ protected function getFirstFeature($i, $features = []) { if (!is_array($features) || !isset($features[$i])) { return $i; } foreach ($features[$i] as $fkey => $fval) { if (!empty($fkey) && !empty($fval)) { return "#$i - " . JText::translate($fkey) . ': ' . $fval; } } return "#$i"; } }