Beispiel #1
0
 protected function generateXml()
 {
     $hotelAvail = new \C2is\OTA\Model\HotelAvail\Request\HotelAvail();
     $hotelAvail->setEchoToken($this->generateEcho());
     $hotelAvail->setTimestamp($this->getTimestamp());
     $hotelAvail->setRequestorId($this->getParam('requestor.id'));
     $hotelAvail->setRequestorType($this->getParam('requestor.type'));
     $hotelAvail->setCompanyName($this->getParam('company_name'));
     $hotelAvail->setVersion($this->getParam('ota.version'));
     $hotelAvail->setXmlns($this->getParam('ota.namespace'));
     $hotelAvail->setLang($this->getParam('lang', 'en'));
     $hotelAvail->setTarget($this->getParam('target', 'Test'));
     $hotelAvail->setBestOnly($this->getParam('best_only', false));
     $hotelAvail->setRateRangeOnly($rateRangeOnly = $this->getParam('rate_range_only', false));
     $hotelAvail->setSummaryOnly($this->getParam('summary_only', false));
     foreach ($this->getParam('requests', array()) as $request) {
         $hotelAvail->addAvailRequestSegment($availRequestSegment = new AvailRequestSegment());
         $type = empty($request['type']) ? 'Room' : $request['type'];
         $availRequestSegment->setAvailReqType($type);
         $duration = null;
         if (isset($request['date_range']) and (isset($request['date_range']['start_date']) and $startDate = $request['date_range']['start_date'] and (isset($request['date_range']['end_date']) and $endDate = $request['date_range']['end_date'] or isset($request['date_range']['duration']) and $duration = $request['date_range']['duration']))) {
             $availRequestSegment->setStayDateRange($stayDateRange = new StayDateRange());
             $stayDateRange->setStart($startDate);
             if ($endDate) {
                 $stayDateRange->setEnd($endDate);
             }
             if ($duration) {
                 $stayDateRange->setDuration($duration);
             }
             $stayDateRange->setRange(date('Y-m-d', strtotime($startDate)));
         }
         if ($rateRangeOnly and isset($request['rate_range']) and isset($request['rate_range']['max']) and $rateRangeMax = $request['rate_range']['max']) {
             $availRequestSegment->setRateRange($rateRange = new RateRange());
             $min = isset($request['rate_range']['min']) ? $request['rate_range']['min'] : 0;
             $rateRange->setMin($min);
             $rateRange->setMax($request['rate_range']['max']);
             $currency = isset($request['rate_range']['currency']) ? $request['rate_range']['currency'] : 'EUR';
             $rateRange->setCurrency($currency);
         }
         if (isset($request['rooms']) and $rooms = $request['rooms'] and is_array($rooms)) {
             foreach ($rooms as $room) {
                 $availRequestSegment->addRoomStayCandidate($roomStayCandidate = new RoomStayCandidate());
                 $roomStayCandidate->setQuantity($room['quantity']);
                 foreach ($room['guests'] as $guest) {
                     $roomStayCandidate->addGuestCount($guestCount = new GuestCount());
                     $category = isset($guest['category']) ? $guest['category'] : 10;
                     $count = isset($guest['count']) ? $guest['count'] : 1;
                     $guestCount->setAgeCode($category);
                     $guestCount->setCount($count);
                     if (isset($guest['age'])) {
                         $guestCount->setAge($guest['age']);
                     }
                 }
             }
         }
         if (isset($request['hotel'])) {
             $availRequestSegment->setCriteria($hotelSearchCriteria = new Criteria());
             foreach ($request['hotel']['codes'] as $hotelCode) {
                 $criterion = new HotelRef();
                 $criterion->setChainCode($request['hotel']['chain_code']);
                 $criterion->setHotelCode($hotelCode);
                 $hotelSearchCriteria->addCriterion($criterion);
             }
         }
         if (isset($request['formatters']) || isset($request['promoCode'])) {
             $availRequestSegment->setExtensions($extensions = new Extensions());
             if (isset($request['formatters'])) {
                 $extensions->setFilter($fitler = new Filter());
                 foreach ($request['formatters'] as $type => $value) {
                     $formatter = new TextDelimiter();
                     $formatter->setOn($type);
                     $formatter->setValue($value);
                     $fitler->addResponseFormatter($formatter);
                 }
             }
             if ($promoCode = $this->getParam('promoCode')) {
                 $extensions->setDiscountCodes($discountCodes = new DiscountCodes());
                 if (isset($promoCode['exclusive'])) {
                     $discountCodes->setExclusive($promoCode['exclusive']);
                 }
                 if (isset($promoCode['code'])) {
                     $discountCodes->setCode($promoCode['code']);
                 }
             }
         }
     }
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $this->xml = $serializer->serialize($hotelAvail, 'xml');
     return $serializer->serialize($hotelAvail, 'xml');
 }
Beispiel #2
0
 protected function generateXml()
 {
     $hotelSearch = new \C2is\OTA\Model\HotelSearch\Request\HotelSearch();
     $hotelSearch->setEchoToken($this->generateEcho());
     $hotelSearch->setTimestamp($this->getTimestamp());
     $hotelSearch->setRequestorId($this->getParam('requestor.id'));
     $hotelSearch->setRequestorType($this->getParam('requestor.type'));
     $hotelSearch->setCompanyName($this->getParam('company_name'));
     $hotelSearch->setVersion($this->getParam('ota.version'));
     $hotelSearch->setXmlns($this->getParam('ota.namespace'));
     $hotelSearch->setMaxResponses($this->getParam('max_responses'));
     $hotelSearch->setLang($this->getParam('lang', 'en'));
     $hotelSearch->setCriteria($criteria = new Criteria());
     $hotelSearch->setTarget($this->getParam('target', 'Test'));
     if ($hotel = $this->getParam('hotel') and is_array($hotel)) {
         if ($codes = $this->getParam('hotel.codes')) {
             foreach ($codes as $code) {
                 $criterion = new HotelRef();
                 $criterion->setChainCode($this->getParam('hotel.chain_code'));
                 $criterion->setHotelCode($code);
                 $criteria->addCriterion($criterion);
             }
         } else {
             $criterion = new HotelRef();
             $criterion->setChainCode($this->getParam('hotel.chain_code'));
             if ($area = $this->getParam('hotel.area')) {
                 $criterion->setArea($area);
             }
             if ($name = $this->getParam('hotel.name')) {
                 $criterion->setHotelName($name);
             }
             if ($brand = $this->getParam('hotel.brand')) {
                 $criterion->setBrandCode($brand);
                 $criterion->setBrandName('Pegasus');
             }
             $criteria->addCriterion($criterion);
         }
     }
     if ($rooms = $this->getParam('rooms') and is_array($rooms)) {
         $criteria->addCriterion($criterion = new RoomStayCandidates());
         foreach ($rooms as $room) {
             $criterion->addRoomStayCandidate($roomStayCandidate = new RoomStayCandidate());
             $roomStayCandidate->setGuestCounts($guestCounts = new GuestCounts());
             foreach ($room as $guest) {
                 $guestCounts->addGuestCount($guestCount = new GuestCount());
                 $category = isset($guest['category']) ? $guest['category'] : 10;
                 $count = isset($guest['count']) ? $guest['count'] : 1;
                 $guestCount->setAgeCode($category);
                 $guestCount->setCount($count);
                 if (isset($guest['age'])) {
                     $guestCount->setAge($guest['age']);
                 }
             }
         }
     }
     if ($dateRange = $this->getParam('date_range') and is_array($dateRange)) {
         $criteria->addCriterion($criterion = new StayDateRange());
         $criterion->setStart($this->getParam('date_range.start_date'));
         $criterion->setEnd($this->getParam('date_range.end_date'));
     }
     if ($address = $this->getParam('address') and is_array($address)) {
         $criteria->addCriterion($criterion = new Address());
         if ($cityName = $this->getParam('address.city_name')) {
             $criterion->setCityName($cityName);
         }
         if ($countryName = $this->getParam('address.country_name')) {
             $criterion->setCountryName($countryName);
         }
     }
     if ($position = $this->getParam('position') and is_array($position)) {
         $criteria->addCriterion($criterion = new Position());
         $criterion->setLongitude($this->getParam('position.longitude'));
         $criterion->setLatitude($this->getParam('position.latitude'));
     }
     if ($radius = $this->getParam('radius') and is_array($radius)) {
         $criteria->addCriterion($criterion = new Radius());
         $criterion->setDistance($this->getParam('radius.distance'));
         $criterion->setDistanceMeasure($this->getParam('radius.measure', 'km'));
     }
     if ($this->getParam('keyword')) {
         $criteria->addCriterion($criterion = new Keyword());
         $criterion->setKeyword($this->getParam('keyword'));
     }
     if ($filter = $this->getParam('filter') and is_array($filter)) {
         $criteria->addCriterion(new FilterExtension($criterion = new Filter()));
         if (isset($filter['bpromo'])) {
             $criterion->setPromo($filter['bpromo'] === true or $filter['bpromo'] === 'true');
         }
         if (isset($filter['bpackage'])) {
             $criterion->setPackage($filter['bpackage'] === true or $filter['bpackage'] === 'true');
         }
         if (isset($filter['bstay'])) {
             $criterion->setStay($filter['bstay'] === true or $filter['bstay'] === 'true');
         }
         if (isset($filter['rate_range'])) {
             $criterion->setRateRangeReq($filter['rate_range'] === true or $filter['rate_range'] === 'true');
         }
         if (isset($filter['rate_range_name'])) {
             $criterion->setRateRangeNameReq($filter['rate_range_name'] === true or $filter['rate_range_name'] === 'true');
         }
     }
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $this->xml = $serializer->serialize($hotelSearch, 'xml');
     return $serializer->serialize($hotelSearch, 'xml');
 }