Exemple #1
0
 /**
  * @param HotelAvail $hotelAvailRS
  * @param Rate $rate
  * @return bool|RoomRate
  */
 public function isRateAvailable($hotelAvailRS, Rate $rate)
 {
     if ($hotelAvailRS) {
         /** @var RoomStay $roomStay */
         foreach ($hotelAvailRS->getRoomStays() as $roomStay) {
             /** @var RoomRate $roomRate */
             foreach ($roomStay->getRoomRates() as $roomRate) {
                 if (in_array($roomRate->getPlanCode(), array($rate->getReservitId(), '51-' . $rate->getReservitId(), '232-' . $rate->getReservitId()))) {
                     return $roomRate;
                 }
             }
         }
     }
     return false;
 }
Exemple #2
0
 /**
  * @param array $line
  * @return array|bool
  * @throws \Exception
  */
 public function importLine(array $line = array())
 {
     $processed = false;
     $em = $this->entityManager;
     /** @var RateRepository $rateRepo */
     $rateRepo = $em->getRepository('SehBundle:Reservit\\Rate');
     $rateTypeRepo = $em->getRepository('SehBundle:Reservit\\RateType');
     /** @var HotelRepository $rateTypeRepo */
     $hotelRepo = $em->getRepository('SehBundle:Hotel');
     /** @var BrandRepository $brandRepo */
     $brandRepo = $em->getRepository('SehBundle:Brand');
     /** @var TranslationRepository $transRepo */
     $transRepo = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     if (54 != ($nbColumns = count($line))) {
         throw new \Exception(sprintf('Invalid number of columns (found %s, expected %s)', $nbColumns, 54));
     }
     $pricingTypes = Rate::getPricingTypes();
     $freeNightsOrderValues = Rate::getFreeNightsOrderValues();
     $freeNightsAllowedValues = Rate::getFreeNightsAllowedValues();
     $validityPeriodTypeValues = Rate::getValidityPeriodTypeValues();
     $bookingPeriodTypeValues = Rate::getBookingPeriodTypeValues();
     $allowsOptionsValues = Rate::getOptionsValues();
     $availableForValues = Rate::getAvailableForValues();
     list($hotelId, $hotelName, $rateId, $rateTypeName, $rateTypeId, $restriction, $name_fr, $description_fr, $name_en, $description_en, $name_es, $description_es, $name_it, $description_it, $name_de, $description_de, $name_nl, $description_nl, $allowMixed, $salesConditions, $salesConditionsName, $salesConditionsDefault, $displayCrossedPrice, $displayRackPrice, $pricingType, $pricingValue, $freeNightsNb, $freeNightsRequired, $freeNightsReduction, $freeNightsOrder, $freeNightsAllowed, $chainRate, $validityPeriodType, $start, $end, $validityPeriodStart, $validityPeriodEnd, $arrivalDayAllowed, $dayAllowed, $stayLengthRoom, $bookingPeriodType, $bookingPeriodStart, $bookingPeriodEnd, $alwaysDisplay, $minNights, $maxNights, $allowsOptions, $promotionalCode, $availableFor, $seh, $ih, $rds, $qys, $pdj) = $line;
     /** @var Hotel $hotel */
     if ($start != 'PASSE' && $end != 'PASSE' && ($hotel = $hotelRepo->findOneBy(array('reservitId' => $hotelId)))) {
         /** @var RateType $rateType */
         if (!($rateType = $rateTypeRepo->findOneBy(array('reservitId' => $rateTypeId)))) {
             $rateType = new RateType();
             $rateType->setTitle($rateTypeName);
         }
         $rateType->setName($rateTypeName);
         $rateType->setReservitId($rateTypeId);
         /** @var Rate $rate */
         if (!($rate = $rateRepo->findOneBy(array('reservitId' => $rateId)))) {
             $rate = new Rate();
             $rate->setReservitId($rateId);
             $rate->setTitle($this->sanitizeString($name_en));
             $rate->setDescription($this->sanitizeString($this->sanitizeString($description_en)));
         }
         foreach ($this->languages as $lang) {
             $name = sprintf('name_%s', $lang);
             $description = sprintf('description_%s', $lang);
             $transRepo->translate($rate, 'title', $lang, $this->sanitizeString(${$name}));
             $transRepo->translate($rate, 'description', $lang, $this->sanitizeString(${$description}));
         }
         $rate->setType($rateType);
         $rate->setRestriction($restriction);
         $rate->setName($this->sanitizeString($name_en));
         $rate->setReservitDescription($this->sanitizeString($description_en));
         $rate->setAllowMixed($allowMixed == Rate::MIXED_RATES_TRUE);
         $rate->setDefaultSalesConditions($salesConditions == Rate::DEFAULT_SALES_CONDITIONS_TRUE);
         $rate->setSalesConditionsName($salesConditionsName);
         $rate->setUseDefaultSalesConditions($salesConditionsDefault == Rate::USE_DEFAULT_SALES_CONDITIONS_TRUE);
         $rate->setDisplayCrossedPrice($displayCrossedPrice == Rate::DISPLAY_CROSSED_PRICE_TRUE);
         $rate->setDisplayRackPrice($displayRackPrice == Rate::DISPLAY_RACK_PRICE_TRUE);
         $rate->setPricingType(isset($pricingTypes[$pricingType]) ? $pricingTypes[$pricingType] : null);
         $rate->setPricingValue($pricingValue);
         $rate->setFreeNightsNb($freeNightsNb);
         $rate->setFreeNightsMin($freeNightsRequired);
         $rate->setFreeNightsPercent($freeNightsReduction);
         $rate->setFreeNightsOrder(isset($freeNightsOrderValues[$freeNightsOrder]) ? $freeNightsOrderValues[$freeNightsOrder] : null);
         $rate->setFreeNightsAllowed(isset($freeNightsAllowedValues[$freeNightsAllowed]) ? $freeNightsAllowedValues[$freeNightsAllowed] : null);
         $rate->setChainRate($chainRate == Rate::CHAIN_RATE_TRUE);
         $rate->setValidityPeriodType(isset($validityPeriodTypeValues[$validityPeriodType]) ? $validityPeriodTypeValues[$validityPeriodType] : null);
         // Si grille de validité, alors on prend en compte $start et $end comme dates de début et fin de validité
         if (isset($validityPeriodTypeValues[$validityPeriodType]) && $validityPeriodTypeValues[$validityPeriodType] == Rate::VALIDITY_PERIOD_TYPE_SPECIFIC && ($start || $end) && !($validityPeriodStart || $validityPeriodEnd) && $start != 'PASSE' && $end != 'PASSE') {
             $rate->setValidityPeriodStart($start ? \DateTime::createFromFormat('d/m/Y', $start) : null);
             $rate->setValidityPeriodEnd($end ? \DateTime::createFromFormat('d/m/Y', $end) : null);
         } else {
             $rate->setValidityPeriodStart($validityPeriodStart ? \DateTime::createFromFormat('d/m/Y', $validityPeriodStart) : null);
             $rate->setValidityPeriodEnd($validityPeriodEnd ? \DateTime::createFromFormat('d/m/Y', $validityPeriodEnd) : null);
         }
         $rate->setDaysArrival($this->getDaysAsArray($arrivalDayAllowed));
         $rate->setDaysAllowed($this->getDaysAsArray($dayAllowed));
         $rate->setLengthFromRoom($stayLengthRoom == Rate::LENGTH_FROM_ROOM_TRUE);
         $rate->setBookingPeriodType(isset($bookingPeriodTypeValues[$bookingPeriodType]) ? $bookingPeriodTypeValues[$bookingPeriodType] : null);
         $rate->setBookingPeriodStart($bookingPeriodStart ? \DateTime::createFromFormat('d/m/Y', $bookingPeriodStart) : null);
         $rate->setBookingPeriodEnd($bookingPeriodEnd ? \DateTime::createFromFormat('d/m/Y', $bookingPeriodEnd) : null);
         $rate->setAlwaysDisplay($alwaysDisplay != Rate::ALWAYS_DISPLAY_FALSE);
         $rate->setNbNightsMin($minNights);
         $rate->setNbNightsMax($maxNights);
         $rate->setAvailableForOptions(isset($allowsOptionsValues[$allowsOptions]) ? $allowsOptionsValues[$allowsOptions] : false);
         $rate->setPromotionalCode($promotionalCode);
         $rate->setRateAvailableFor(isset($availableForValues[$availableFor]) ? $availableForValues[$availableFor] : null);
         $rate->setActive(true);
         foreach ($this->languages as $lang) {
             $name = sprintf('name_%s', $lang);
             $description = sprintf('description_%s', $lang);
             $transRepo->translate($rate, 'name', $lang, $this->sanitizeString(${$name}));
             $transRepo->translate($rate, 'reservitDescription', $lang, $this->sanitizeString(${$description}));
         }
         $brands = new ArrayCollection();
         if ($seh == Rate::BRAND_TRUE and $brand = $brandRepo->findOneBy(array('artsysID' => 'SEH'))) {
             $brands->add($brand);
         }
         if ($ih == Rate::BRAND_TRUE and $brand = $brandRepo->findOneBy(array('artsysID' => 'IH'))) {
             $brands->add($brand);
         }
         if ($rds == Rate::BRAND_TRUE and $brand = $brandRepo->findOneBy(array('artsysID' => 'RDS'))) {
             $brands->add($brand);
         }
         if ($qys == Rate::BRAND_TRUE and $brand = $brandRepo->findOneBy(array('artsysID' => 'QYS'))) {
             $brands->add($brand);
         }
         if ($pdj == Rate::BRAND_TRUE and $brand = $brandRepo->findOneBy(array('artsysID' => 'PDJ'))) {
             $brands->add($brand);
         }
         $rate->setBrands($brands);
         $rate->addHotel($hotel);
         $em->persist($rate);
         $em->persist($hotel);
         $em->flush();
         $hotelId = $hotel->getId();
         $rateId = $rate->getId();
         $em->clear();
         $processed = true;
     }
     return $processed ? array('hotel' => $hotelId, 'rate' => $rateId) : false;
 }