Beispiel #1
0
 /**
  * Constructor
  */
 public function __construct($config = array())
 {
     // get app & config
     $this->app = CHClient::getApp();
     $this->config = CHClient::getConfig();
     $this->search = CHClient::getSearch();
     // construct
     parent::__construct($config);
 }
 /**
  * Display
  */
 public function display($tpl = null)
 {
     // load app
     $this->app = CHClient::getApp();
     // get the booking info
     $this->booking = $this->get('Booking');
     // no booking found
     if (!$this->booking) {
         $this->setLayout('errors');
         parent::display($tpl);
         return;
     }
     // processing booking
     if ($this->booking->booking_status >= 40) {
         return $this->displayProcessing();
     }
     // new booking analytics tracking
     $this->new_booking = false;
     if ($this->app->getUserState('chclient.new_booking', false)) {
         $this->new_booking = (object) ['booking_id' => $this->booking->booking_id, 'hotel' => $this->booking->hotel->title, 'total' => $this->booking->amounts->total, 'currency' => $this->booking->currency];
         $this->new_booking->rooms = [];
         foreach ($this->booking->rooms as $room) {
             $new_booking_room = (object) ['title' => $room->title, 'reference' => $room->reference, 'total' => $room->amounts->total];
             $this->new_booking->rooms[] = $new_booking_room;
         }
         $this->app->setUserState('chclient.new_booking', null);
     }
     // determine free cancellation
     $this->data = (object) [];
     $this->data->free_cancellation = 1;
     $this->data->deadline = '';
     $deadline = 00;
     foreach ($this->booking->rooms as $room) {
         $rate_deadline = CHLIbdate::sqlToInt($room->rate->deadline);
         if ($rate_deadline > $deadline) {
             $this->data->deadline = $room->rate->deadline;
         }
         if (!in_array($room->rate->conditions, ['pay_at_hotel', 'deposit_refundable', 'prepay_refundable'])) {
             $this->data->free_cancellation = 0;
         }
     }
     if ($this->data->free_cancellation) {
         $this->data->free_cancellation = CHLibDate::isGreater($this->data->deadline, CHLibDate::dateToSql(false));
     }
     // print voucher ?
     if ($this->booking && CHLib::input()->get('print')) {
         return $this->printVoucher();
     }
     // set document title
     $this->document->setTitle(CHClient::string('your_booking') . ' - ' . $this->booking->booking_id);
     // display
     parent::display($tpl);
 }
 /**
  * Display
  */
 public function display($tpl = null)
 {
     // load the app
     $app = CHClient::getApp();
     // check if guest user
     $this->user = CHClient::getUser();
     if (!$this->user) {
         $this->setLayout('access');
     }
     // my booking error
     $this->my_booking_error = $app->getUserState('chclient.my_booking_error', false);
     $app->setUserState('chclient.my_booking_error', null);
     // prepare document
     $this->prepareDocument();
     // display
     parent::display($tpl);
 }
 /**
  * Amend a booking
  */
 public function amendBooking()
 {
     // load app
     $app = CHClient::getApp();
     // get the booking_id
     $booking_id = CHLib::input()->post->getUInt('booking_id');
     if (!$booking_id) {
         return false;
     }
     // reset user booking info
     $app->setUserState('chclient.booking', null);
     // perform api request
     $request = (object) ['booking_id' => $booking_id, 'confirm' => CHLib::input()->post->get('confirm')];
     $api_request = $this->apiRequest('booking_amend', $request);
     // check for errors
     if ($api_request->errors->errors) {
         return false;
     }
     // todo check booking is ok
     $new_booking = $api_request->response;
     // reload booking data
     $app->setUserState('chclient.booking', $new_booking);
     // submit confirmation method
     $app->setUserState('chclient.submit_confirm', true);
     // return true
     return true;
 }
 /**
  * Determine view and hotels_ids
  */
 static function checkView()
 {
     // get the app
     $app = CHClient::getApp();
     $jinput = JFactory::getApplication()->input;
     // check for hotel_id in request
     if ($jinput->getInt('hotel_id')) {
         // set hotels_ids
         $app->chclient->hotels_ids = [$jinput->getInt('hotel_id')];
         return;
     }
     // determine hotels ids from the menu item
     $menu = $app->getMenu()->getActive();
     if ($menu->query['view'] == 'engine') {
         // get hotels_ids from menu item params
         $hotels_ids = $menu->params->get('hotels_ids');
         // no hotels ids provided, get hotels from inventory
         if (!$hotels_ids) {
             $hotels_ids = JFactory::getDbo()->setQuery("SELECT id FROM #__chclient_inventory ORDER BY title")->loadColumn();
         }
         // set hotels_ids
         $app->chclient->hotels_ids = $hotels_ids;
         // set the engine view
         if ($jinput->get('view') == 'engine' && $jinput->get('start_date')) {
             if (count($hotels_ids) > 1) {
                 $jinput->set('view', 'search');
             } else {
                 $jinput->set('view', 'availability');
             }
         }
     }
     // single hotel views
     if (in_array($menu->query['view'], ['hotel', 'rooms', 'promos', 'calendar'])) {
         $hotel_id = $menu->params->get('hotel_id');
         if (!$hotel_id) {
             $hotel_id = (int) JFactory::getDbo()->setQuery("SELECT id FROM #__chclient_inventory ORDER BY title")->loadResult();
         }
         $app->chclient->hotels_ids = [$hotel_id];
     }
 }