Esempio n. 1
0
 public function actionInfo($eventId)
 {
     $event = Event::model()->findByPk($eventId);
     $defaultCityId = 4466;
     $pricesData = array();
     $this->layout = 'static';
     foreach ($event->prices as $price) {
         $pricesData[$price->city->id] = array('price' => floor($price->bestPrice), 'cityName' => $price->city->localRu, 'cityId' => $price->city->id, 'updateTime' => str_replace(' ', 'T', $price->updated));
     }
     $tours = array();
     $dataProvider = new TripDataProvider();
     $cities = array();
     foreach ($event->tours as $tour) {
         $tours[$tour->startCityId] = array();
         $dataProvider->restoreFromDb($tour->orderId);
         //echo $tour->orderId.'dsf';
         //print_r($dataProvider->getSortedCartItemsOnePerGroup(false));//die();
         $items = $dataProvider->getWithAdditionalInfo($dataProvider->getSortedCartItemsOnePerGroup(false));
         //print_r($items);die();
         $tours[$tour->startCityId] = $items;
         $tours[$tour->startCityId]['city'] = City::getCityByPk($tour->startCityId)->getAttributes();
         $eventPrice = EventPrice::model()->findByAttributes(array('eventId' => $eventId, 'cityId' => $tour->startCityId));
         if ($eventPrice) {
             $tours[$tour->startCityId]['price'] = ceil($eventPrice->bestPrice);
         }
         $cities[$tour->startCityId] = City::getCityByPk($tour->startCityId)->getAttributes();
     }
     //die();
     if (!isset($cities[$defaultCityId])) {
         foreach ($cities as $defaultCityId => $city) {
             break;
         }
     }
     //need search params
     $twoCities = array();
     $twoCities[$defaultCityId] = $cities[$defaultCityId];
     foreach ($cities as $cityId => $city) {
         if (!isset($twoCities[$cityId])) {
             $twoCities[$cityId] = $city;
             break;
         }
     }
     $pictures = array();
     foreach ($event->pictures as $picture) {
         $pictures[] = array('url' => $picture->getUrl());
     }
     $this->render('info', array('event' => $event, 'priceData' => $pricesData, 'defaultCity' => $defaultCityId, 'tours' => $tours, 'cities' => $cities, 'twoCities' => $twoCities, 'pictures' => $pictures));
 }
 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');
 }
Esempio n. 3
0
 public function actionPdf($id)
 {
     $pdf = Yii::app()->pdfGenerator;
     $tsp = new TripDataProvider();
     $items = $tsp->getSortedCartItemsOnePerGroup();
     foreach ($items as $item) {
         if ($item instanceof HotelTripElement) {
             if ($item->getId() == $id) {
                 $fileNameInfo = $pdf->forHotelItem($item);
                 Yii::app()->request->sendFile($fileNameInfo['visibleName'], file_get_contents($fileNameInfo['realName']));
                 @unlink($fileNameInfo['realName']);
                 break;
             }
         } elseif ($item instanceof FlightTripElement) {
             if ($item->getId() == $id) {
                 $fileNameInfo = $pdf->forFlightItem($item);
                 Yii::app()->request->sendFile($fileNameInfo['visibleName'], file_get_contents($fileNameInfo['realName']));
                 @unlink($fileNameInfo['realName']);
                 break;
             }
         }
     }
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 public function initByOrderBookingId($orderId)
 {
     $this->currentOrderId = $orderId;
     $dataProvider = new TripDataProvider($orderId);
     $this->itemsOnePerGroup = $dataProvider->getSortedCartItemsOnePerGroup();
 }
Esempio n. 6
0
 public function actionShow($orderId = false)
 {
     $this->orderId = $orderId;
     $this->prepareData();
     $dataProvider = new TripDataProvider();
     echo $dataProvider->getSortedCartItemsOnePerGroupAsJson();
 }
Esempio n. 7
0
 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++;
     }
 }
Esempio n. 8
0
 public function init()
 {
     $dataProvider = new TripDataProvider();
     $this->tripElements = $dataProvider->getSortedCartItems();
     $this->fillTabs();
 }
Esempio n. 9
0
 public function __construct()
 {
     $dataProvider = new TripDataProvider();
     $this->items = $dataProvider->getSortedCartItems();
     $this->itemsOnePerGroup = $dataProvider->getSortedCartItemsOnePerGroup();
 }
Esempio n. 10
0
 public function getWithAdditionalInfo($items)
 {
     $out = array();
     foreach ($items as $item) {
         $prepared = $item->getJsonObject();
         //print_r($prepared);die();
         $prepared['isLinked'] = $item->isLinked();
         $prepared['searchParams'] = $item->getJsonObjectForSearchParams();
         TripDataProvider::injectAdditionalInfo($prepared);
         $out['items'][] = $prepared;
     }
     return $out;
 }