/** * Get Availability */ public function getAvailability() { // init request $search = $this->search; $search->hotels_ids = $this->getHotelsIds(); $api_request = $this->apiRequest('search_results', $search); if (!$api_request) { return false; } // prepare availability object $availability = (object) []; $availability->errors = $api_request->errors; $availability->request = $api_request->request->data; // prepare hotels info $availability->hotels = []; if (isset($api_request->response->inventory)) { foreach ($api_request->response->inventory as $inventory_item) { $availability->hotels[] = CHInventory::prepare($inventory_item); } } // check for errors if ($api_request->errors->errors) { return $availability; } // add the results info $availability->results = $api_request->response->results; return $availability; }
/** * Get Availability */ public function getAvailability() { // init request $search = $this->search; $search->hotels_ids = $this->getHotelsIds(); $api_request = $this->apiRequest('search_results', $search); if (!$api_request) { return false; } // prepare availability object $availability = (object) []; $availability->errors = $api_request->errors; $availability->request = $api_request->request->data; if (isset($api_request->app)) { $availability->app = $api_request->app; $availability->app->voucher_text_html = CHLibDisplay::convertMarkdownToHtml($availability->app->voucher_text); } // inventory tasks if (isset($api_request->response->inventory)) { // prepare hotel info $availability->hotel = CHInventory::prepare($api_request->response->inventory[0]); // update inventory db foreach ($api_request->response->inventory as $inventory) { $this->_db->setQuery("DELETE FROM `#__chclient_inventory` WHERE id = {$inventory->id}")->execute(); $insert = (object) ['id' => $inventory->id, 'title' => $inventory->title, 'slug' => $inventory->slug, 'data' => json_encode($inventory)]; $this->_db->insertObject('#__chclient_inventory', $insert, 'id'); } } // check for errors if ($api_request->errors->errors) { // init calendar object if (isset($api_request->response->month_ari)) { $calendar = new stdClass(); $calendar->month = CHLibDate::getMonth(substr($search->start_date, 0, -3)); $calendar->months_list = CHLibDate::getMonthsList(); $calendar->ari = $api_request->response->month_ari; $availability->calendar = $calendar; } return $availability; } // prepare the info $availability->results = $api_request->response->results[0]; $availability->month_ari = $api_request->response->month_ari; return $availability; }
/** * Get the hotel data */ public function getHotel($hotel_id = 0) { // check if hotel already loaded if (isset($this->hotel)) { return $this->hotel; } // check hotel $id = $hotel_id ? $hotel_id : $this->getHotelId(); if (!$id && !$hotel_id) { throw new Exception(CHClient::string('error_resource_not_found'), 404); } // get the hotel data form inventory table $data = $this->_db->setQuery("SELECT data FROM `#__chclient_inventory` WHERE id = {$id}")->loadResult(); if (!$data) { if (!$hotel_id) { throw new Exception(CHClient::string('error_resource_not_found'), 404); } else { return false; } } // get the data ready to display $this->hotel = CHInventory::prepare(json_decode($data)); return $this->hotel; }