/** * Get the hotel data */ public function getPromo() { // determine hotel $hotel_id = $this->getHotelId(); // get the vars @(list($type_id, $slug) = explode('-', CHLib::input()->getString('id'), 2)); @(list($type, $promo_id) = explode(':', $type_id)); // check vars if (!$type || !$slug || !$hotel_id || !$promo_id) { throw new Exception(CHClient::string('error_bad_request'), 404); } // check type if (!in_array($type, ['discount', 'extra', 'pack'])) { throw new Exception(CHClient::string('error_bad_request'), 404); } // get the hotel $hotel = parent::getHotel($hotel_id); if (!$hotel) { throw new Exception(CHClient::string('error_resource_not_found'), 404); } // promo type array $type_array = $type . 's'; $promo = CHLibData::getObjectFromList($hotel->{$type_array}, $promo_id, 'id'); $promo->promo_type = $type; return $promo; }
/** * Get the hotel */ public static function getHotel($hotel_id) { // check cache $app = JFactory::getApplication(); $user = JFactory::getUser(); $cache = JFactory::getCache('mod_jkit_item', ''); // cache key $menu = $app->getMenu(); $active = $menu->getActive() ? $menu->getActive() : $menu->getDefault(); $levels = $user->getAuthorisedViewLevels(); asort($levels); $key = 'menu_item' . $hotel_id . implode(',', $levels) . '.' . $active->id; // try to get item from cache $hotel = $cache->get($key); // no cache found, query for item if (!$hotel) { // require model $model = new CHClientModelBase(); $hotel = $model->getHotel($hotel_id); if (!$hotel) { $cache->store(false, $key); return; } // store item to cache $cache->store($hotel, $key); } return $hotel; }
/** * Get the hotel data */ public function getRoom() { // get the vars $hotel_id = $this->getHotelId(); $id = CHLib::input()->getInt('id'); // check vars if (!$hotel_id || !$id) { throw new Exception(CHClient::string('error_bad_request'), 404); } // get the hotel $hotel = parent::getHotel($hotel_id); if (!$hotel) { throw new Exception(CHClient::string('error_resource_not_found'), 404); } // promo type array $room = CHLibData::getObjectFromList($hotel->rooms, $id, 'id'); return $room; }