Ejemplo n.º 1
0
 /**
  * @param array $data
  * @return array
  */
 public function searchApartmentList($data, $getAll = false)
 {
     /**
      * @var \DDD\Dao\Currency\Currency $currencyDao
      */
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $filterData = $this->filterSearchData($data);
     $apartelList = $apartels = $options = [];
     $error = false;
     $totalPages = 1;
     $queryString = '';
     if ($filterData) {
         return ['status' => 'error', 'msg' => $filterData];
     }
     $correcrData = $this->correctData($data);
     $bedrooms = $this->defineBedrooms($data);
     $guest = $correcrData['guest'];
     $page = $correcrData['page'];
     $arrival = $correcrData['arrival'];
     $departure = $correcrData['departure'];
     $apartelGeneralDao = $this->getApartelGeneralDao();
     $pageItemCount = WebSite::PAGINTAION_ITEM_COUNT;
     $offset = (int) ($page - 1) * $pageItemCount;
     if (isset($data['city'])) {
         $city = $data['city'];
         // Has date
         if ($arrival && $departure) {
             $apartelsResult = $apartelGeneralDao->getApartmentsByCityDate($city, $arrival, $departure, $guest, $pageItemCount, $offset, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1210);
         } else {
             $apartelsResult = $apartelGeneralDao->getApartmentsCity($city, $guest, $pageItemCount, $offset, $getAll, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1333);
         }
     } elseif (isset($data['apartel'])) {
         $apartel = $data['apartel'];
         // Has date
         if ($arrival && $departure) {
             $apartelsResult = $apartelGeneralDao->getApartmentsByApartelDate($apartel, $arrival, $departure, $guest, $pageItemCount, $offset, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1210);
         } else {
             $apartelsResult = $apartelGeneralDao->getApartmentsApartel($apartel, $guest, $pageItemCount, $offset, $getAll, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1333);
         }
     } else {
         return ['status' => 'error'];
     }
     $apartmentList = $apartelsResult['result'];
     $total = $apartelsResult['total'];
     $totalPages = $total > 0 ? ceil($total / $pageItemCount) : 1;
     if (!$apartmentList->count()) {
         return ['status' => 'no_av', 'msg' => $this->getTextLineSite(1218)];
     }
     $visitorLoc = $this->getVisitorCountry();
     // Change currency
     $userCurrency = $this->getCurrencySite();
     $currencySymbol = WebSite::DEFAULT_CURRENCY;
     $currencyResult = $currencyDao->fetchOne(['code' => $userCurrency]);
     if ($currencyResult) {
         $currencySymbol = $currencyResult->getSymbol();
     }
     $currencyUtility = new Currency($currencyDao);
     $query_array = [];
     if ($arrival && $departure) {
         array_push($query_array, 'arrival=' . Helper::dateForUrl($arrival));
         array_push($query_array, 'departure=' . Helper::dateForUrl($departure));
         array_push($query_array, 'guest=' . $guest);
         $queryString = '?' . implode('&', $query_array);
     } elseif ($guest >= 1) {
         $queryString = '?guest=' . $guest;
     } elseif ($getAll) {
         $queryString = '?show=reviews';
     }
     $apartmentList = iterator_to_array($apartmentList);
     // add apartel id if apartel reservation
     if (isset($data['apartel'])) {
         $queryString .= ($queryString ? '&' : '?') . 'apartel_id=' . current($apartmentList)['apartment_group_id'];
     }
     foreach ($apartmentList as $al) {
         // Generate image
         $noImg = false;
         if ($al['img1']) {
             if ($img = Helper::getImgByWith($al['img1'], WebSite::IMG_WIDTH_SEARCH)) {
                 $noImg = true;
                 $al['image'] = $img;
             }
         }
         if (!$noImg) {
             $al['image'] = Constants::VERSION . 'img/no_image.png';
         }
         // Calculate percent
         if ($arrival && $departure) {
             $al['percent'] = round(($al['price_max'] - $al['price_min']) / $al['price_max'] * 100);
         } else {
             $al['percent'] = rand(10, 13);
             $al['rate_name'] = 'Non refundable';
         }
         // User currency price
         if ($userCurrency != $al['code']) {
             $price = $currencyUtility->convert($al['price_min'], $al['code'], $userCurrency);
             $al['price_min'] = $price;
             $al['symbol'] = $currencySymbol;
         }
         $al['url_to_search'] = 'apartment/' . $al['url'] . '--' . $al['slug'] . $queryString;
         // Sale percent
         array_push($apartels, $al);
     }
     // Pagination view
     $paginatinView = $this->paginationViewItem($total, $page, $pageItemCount);
     return ['apartelList' => $apartels, 'totalPages' => $totalPages, 'status' => 'success', 'paginatinView' => $paginatinView, 'options' => $options, 'visitorLoc' => $visitorLoc];
 }
Ejemplo n.º 2
0
 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $domain = '//' . DomainConstants::WS_DOMAIN_NAME;
     try {
         if (!isset($_SERVER['HTTPS'])) {
             return $this->redirect()->toUrl($domain);
         }
         // Data for reservation
         $data = $request->getQuery();
         /**
          * @var \DDD\Service\Website\Booking $bookingService
          * @var \DDD\Service\Website\Apartment $apartmentService
          */
         $bookingService = $this->getServiceLocator()->get('service_website_booking');
         $apartmentService = $this->getServiceLocator()->get('service_website_apartment');
         $result = $bookingService->bookingReservationData($data);
         if ($result['status'] != 'success') {
             $query = ['city=' . $data['city'], 'guest=' . $data['guest'], 'arrival=' . Helper::dateForUrl($data['arrival']), 'departure=' . Helper::dateForUrl($data['departure'])];
             if ($result['status'] == 'not_av') {
                 $query[] = 'no_av=yes';
             }
             $redirectUrl = $domain . '/search?' . implode('&', $query);
             return $this->redirect()->toUrl($redirectUrl);
         }
         if ($result['status'] == 'success' && !$result['result']) {
             return $this->redirect()->toUrl($domain);
         }
         $options = $bookingService->getOptions();
         $form = new BookingForm($options);
         $apartels = $apartmentService->getApartelsByApartmentId($data['apartment_id']);
         $apartelId = isset($data['apartel_id']) && (int) $data['apartel_id'] > 0 ? (int) $data['apartel_id'] : 0;
         // Post data
         $error = $messages = '';
         if ($request->isPost()) {
             $data = $request->getPost();
             $form->setInputFilter(new BookingFilter($data, $form->getPostalCodeStatus($data['country'], $options['countris'])));
             $form->setData($data);
             if ($form->isValid()) {
                 $vData = $form->getData();
                 $resultUserPay = $bookingService->bookingProcess($vData);
                 if ($resultUserPay['status'] != 'success') {
                     return $this->redirect()->toUrl($domain);
                 }
                 return $this->redirect()->toRoute('booking', ['action' => 'thank-you']);
             } else {
                 $errors = $form->getMessages();
                 foreach ($errors as $key => $row) {
                     if (!empty($row)) {
                         $messages .= ucfirst($key) . ' ';
                         $messages_sub = '';
                         foreach ($row as $keyer => $rower) {
                             $messages_sub .= $rower;
                         }
                         $messages .= $messages_sub . '<br>';
                     }
                 }
                 $error = $messages;
             }
         }
         $checkDiscountUrl = $this->url()->fromRoute('booking', ['action' => 'ajax-check-discount']);
         $this->layout()->setVariable('footerVisibility', 'visible');
         $isAffiliateChooser = false;
         if (isset($_COOKIE['backoffice_user'])) {
             $backofficeUserId = $_COOKIE['backoffice_user'];
             /**
              * @var UserManager $userManagerDao
              */
             $userManagerDao = $this->getServiceLocator()->get('dao_user_user_manager');
             $userData = $userManagerDao->getUserById($backofficeUserId);
             $backofficeUserDepartmentId = $userData->getDepartmentId();
             if (in_array($backofficeUserDepartmentId, TeamService::$teamsThatAllowedToChooseAffiliateForWebsiteReservations)) {
                 $isAffiliateChooser = true;
             }
             $userName = $userData->getFirstname() . ' ' . $userData->getLastname();
         } else {
             $userName = false;
         }
         return new ViewModel(['general' => $result['result'], 'options' => $options, 'bookingForm' => $form, 'error' => $error, 'apartels' => $apartels, 'zipCodeStatusJson' => json_encode($form->getCountryPostalCodes($options['countris'])), 'checkDiscountUrl' => $checkDiscountUrl, 'ginosikDiscountId' => PartnersService::GINOSI_EMPLOYEE, 'backofficeUserName' => $userName, 'isAffiliateChooser' => $isAffiliateChooser, 'apartelId' => $apartelId]);
     } catch (\Exception $e) {
         return $this->redirect()->toUrl($domain);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param array $data
  * @return array
  */
 public function apartmentSearch($data)
 {
     $filter = $this->filterSearchData($data);
     $result = ['status' => '', 'result' => []];
     $rateList = [];
     $apartment = $data['apartment'];
     $city = $data['city'];
     $guest = $data['guest'] > 0 ? (int) $data['guest'] : 1;
     $arrival = date('Y-m-d', strtotime($data['arrival']));
     $departure = date('Y-m-d', strtotime($data['departure']));
     $nightCount = Helper::getDaysFromTwoDate($arrival, $departure);
     $no_av_status = 'no_av';
     $no_av_result = ['arrival' => Helper::dateForUrl($arrival), 'departure' => Helper::dateForUrl($departure), 'guest' => $guest, 'city' => $city];
     if ($filter) {
         $rateDao = $this->getInventoryDao();
         $response = $rateDao->getAvailableRates($apartment, Helper::urlForSearch($city), $guest, $arrival, $departure);
         $i = 1;
         if ($response->count() > 0) {
             $currencySymbol = WebSite::DEFAULT_CURRENCY;
             $userCurrency = $this->getCurrencySite();
             $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
             $currencyResult = $currencyDao->fetchOne(['code' => $userCurrency]);
             if ($currencyResult) {
                 $currencySymbol = $currencyResult->getSymbol();
             }
             $currencyUtility = new Currency($currencyDao);
             foreach ($response as $row) {
                 //check user currency and apartment currency
                 if ($userCurrency != $row['code']) {
                     $price = $currencyUtility->convert($row['price'], $row['code'], $userCurrency);
                 } else {
                     $price = $row['price'];
                 }
                 //cancelation policy
                 $cancelationData = $row;
                 $cancelationData['night_count'] = $nightCount;
                 $cancelation = $this->cancelationPolicy($cancelationData);
                 $discountPrice = 0;
                 $visitor = new Container('visitor');
                 if (!is_null($visitor->partnerId) && (int) $visitor->partnerId) {
                     $partnerDao = new \DDD\Dao\Partners\Partners($this->getServiceLocator());
                     $partnerInfo = $partnerDao->fetchOne(['gid' => (int) $visitor->partnerId]);
                     $discountPrice = 0;
                     if ($partnerInfo && ceil($partnerInfo->getDiscount())) {
                         $discountPrice = number_format($price * (100 - $partnerInfo->getDiscount()) * 0.01, 2, '.', '');
                     }
                 }
                 //rateList
                 $rateList[] = ['primary' => $i === 1 ? true : false, 'rate' => ['id' => $row['id'], 'name' => $row['name']], 'capacity' => $row['capacity'], 'price' => number_format($price, 2, '.', ''), 'total_price' => number_format($nightCount * $price, 2, '.', ''), 'currency' => ['name' => $userCurrency, 'sign' => $currencySymbol], 'policy' => ['name' => $cancelation['type'], 'description' => $cancelation['description']], 'discount' => ['price' => $discountPrice, 'total' => number_format($nightCount * $discountPrice, 2, '.', '')]];
                 $i++;
             }
             $result['status'] = 'success';
             $result['result'] = $rateList;
         } else {
             $result['status'] = $no_av_status;
             $result['result'] = $no_av_result;
         }
         return $result;
     }
     return ['status' => $no_av_status, 'result' => $no_av_result];
 }