public function run() { $this->index = intval($_GET['index']); $this->passportForms = Yii::app()->user->getState('passportForms'); $this->bookingForm = Yii::app()->user->getState('bookingForm'); $dataProvider = new TripDataProvider(); $this->tripItems = $dataProvider->getSortedCartItems(); if ($this->areNotAllItemsLinked()) { throw new CHttpException(500, 'There are exists element inside trip that are not linked. You cannot continue booking'); } if ($this->weGotPassportsAndBooking()) { $tripElementsWorkflow = Yii::app()->order->bookAndReturnTripElementWorkflowItem($this->index); $bookerId = $tripElementsWorkflow[0]->getBookerId(); header("Content-type: application/json"); echo '{"status":"success", "bookerId":"' . $bookerId . '"}'; exit; } throw new CHttpException(500, 'Error while booking ' . $this->index . '-th segment'); }
public function run() { $this->getController()->layout = 'static'; $dataProvider = new TripDataProvider(); $this->tripItems = $dataProvider->getSortedCartItems(); if ($this->areNotAllItemsLinked()) { throw new CHttpException(500, 'There are exists element inside trip that are not linked. You cannot continue booking'); } $passportManager = new PassportManager(); $passportManager->tripItems = $this->tripItems; $orderBookingId = $this->createNewOrderBooking(); $ambigousPassports = $passportManager->generatePassportForms(); $this->passportForms = $passportManager->passportForms; if ($this->weGotPassportsAndBooking()) { $flag1 = $this->fillOutBookingForm(); $flag2 = $this->fillOutPassports($ambigousPassports); if ($flag1 && $flag2) { Yii::app()->user->setState('passportForms', $this->passportForms); Yii::app()->user->setState('bookingForm', $this->bookingForm); //$tripElementsWorkflow = Yii::app()->order->bookAndReturnTripElementWorkflowItems(); // FIXME return status here header("Content-type: application/json"); echo '{"status":"success"}'; Yii::app()->end(); } else { header("Content-type: application/json"); echo json_encode(array('status' => 'error', 'message' => $this->validationErrors)); Yii::app()->end(); } } $this->bookingForm = new BookingForm(); $tripStorage = new TripDataProvider(); $trip = $tripStorage->getSortedCartItemsOnePerGroupAsJson(); list($icon, $header) = $tripStorage->getIconAndTextForPassports(); $viewData = array('passportForms' => $this->passportForms, 'ambigousPassports' => $ambigousPassports, 'bookingForm' => $this->bookingForm, 'trip' => $trip, 'orderId' => $orderBookingId, 'icon' => $icon, 'header' => $header, 'headersForAmbigous' => $tripStorage->getHeadersForPassportDataPage(), 'roomCounters' => sizeof($passportManager->roomCounters) > 0 ? $passportManager->roomCounters : false); $this->controller->render('makeBooking', $viewData); }
public function actionFillCartElement($cartElementId, $type, $key, $searchId = '', $searchId2 = '', $pCacheId = '') { $dataProvider = new TripDataProvider(); $allPositions = $dataProvider->getSortedCartItems(); $needPosition = null; foreach ($allPositions as $item) { if ($item->getId() == $cartElementId) { $needPosition = $item; break; } } if ($needPosition) { switch ($type) { case FlightVoyage::TYPE: $needPositions = array(); $groupId = $needPosition->getGroupId(); foreach ($allPositions as $item) { if ($item->getGroupId()) { if ($item->getGroupId() == $groupId) { $needPositions[] = $item; } } } /** @var $flight FlightVoyage */ $flight = FlightVoyage::getFromCache($searchId, $key); if ($flight) { //updating all cartElements foreach ($needPositions as $item) { $flightSearchParams = @Yii::app()->pCache->get('flightSearchParams' . $pCacheId); $item->fillFromSearchParams($flightSearchParams); $item->flightVoyage = $flight; Yii::app()->shoppingCart->update($item, 1); } $json = CJSON::encode($flight->getJsonObject()); if (isset($_GET['callback'])) { echo $_GET['callback'] . ' (' . $json . ');'; } else { echo $json; } } else { throw new CHttpException(404, 'Can\'t found item inside cache key:' . $key . ' searchId:' . $searchId); } break; case Hotel::TYPE: /** @var $hotel Hotel */ $hotel = Hotel::getFromCache($searchId, null, $key); if ($hotel) { $hotelSearchParams = @Yii::app()->pCache->get('hotelSearchParams' . $pCacheId); $needPosition->fillFromSearchParams($hotelSearchParams); $needPosition->hotel = $hotel; Yii::app()->shoppingCart->update($needPosition, 1); $json = CJSON::encode($hotel->getJsonObject()); if (isset($_GET['callback'])) { echo $_GET['callback'] . ' (' . $json . ');'; } else { echo $json; } } else { throw new CHttpException(404, 'Can\'t found item inside cache'); } break; } } }
private function getAllTourVariants() { $asyncExecutor = new AsyncCurl(); $dataProvider = new TripDataProvider(); $items = $dataProvider->getSortedCartItems(); $grouped = array(); foreach ($items as $item) { if ($item instanceof FlightTripElement) { $grouped[$item->getGroupId()][] = $item; } else { $grouped[$item->getGroupId()][] = $item; } } foreach ($grouped as $group) { if ($group[0] instanceof FlightTripElement) { $url = FlightTripElement::getUrlToAllVariants($group); $asyncExecutor->add($url); } else { if ($group[0] instanceof HotelTripElement) { $itemVariantsUrl = $group[0]->getUrlToAllVariants(); $asyncExecutor->add($itemVariantsUrl); } } } $responses = $asyncExecutor->send(); $this->errors = array(); $i = 0; foreach ($responses as $response) { if ($httpCode = $response->headers['http_code'] == 200) { $this->variants[$i] = CJSON::decode($response->body); $this->errors[$i] = false; } else { $this->variants[$i] = array(); $this->errors[$i] = 'Error ' . $httpCode; } $i++; } }
public function init() { $dataProvider = new TripDataProvider(); $this->tripElements = $dataProvider->getSortedCartItems(); $this->fillTabs(); }
public function __construct() { $dataProvider = new TripDataProvider(); $this->items = $dataProvider->getSortedCartItems(); $this->itemsOnePerGroup = $dataProvider->getSortedCartItemsOnePerGroup(); }