Example #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $unit = new Units();
     if (Input::has("list") && Input::get('list') == 'Last') {
         return Redirect::route('list', Request::all());
     }
     if (Input::has("list") && Input::get('list') == 'First') {
         return Redirect::route('list', Request::all());
     }
     $checkin = Lang::get('lang.CheckIn');
     $checkout = Lang::get('lang.CheckOut');
     $pagination = config('constants.PAGINATION');
     $param_Destination = "";
     $param_Category = "";
     $paramCat = "";
     $param_Price = "";
     $paramSearch = "";
     $paramNrPersons = "";
     $paramOrder = "";
     $checkInDate = "";
     $checkOutDate = "";
     $allParameters = Request::all();
     $allSearchParameters = Request::only('destination', 'start', 'end', 'nr_persons');
     $allMainCategoryParams = array();
     if (isset($allParameters['private'])) {
         $allMainCategoryParams[] = Config::get('constants.MAIN_HOUSE_CATEGORIES.PRIVATE');
     }
     if (isset($allParameters['hotel'])) {
         $allMainCategoryParams[] = Config::get('constants.MAIN_HOUSE_CATEGORIES.HOTEL');
     }
     if (isset($allParameters['hostel'])) {
         $allMainCategoryParams[] = Config::get('constants.MAIN_HOUSE_CATEGORIES.HOSTEL');
     }
     //kreiranje arraya za property type filtere
     $unitCat1 = array();
     $unitCat = array();
     if (isset($allParameters['apartment'])) {
         $unitCat1[] = Config::get('constants.MAIN_UNIT_CATEGORIES.APARTMENT');
     }
     if (isset($allParameters['room'])) {
         $unitCat1[] = Config::get('constants.MAIN_UNIT_CATEGORIES.ROOM');
     }
     if (isset($allParameters['house'])) {
         $unitCat1[] = Config::get('constants.MAIN_UNIT_CATEGORIES.VACATION_HOUSE');
     }
     if (count($unitCat1) != 0) {
         $unitCat = call_user_func_array('array_merge', $unitCat1);
     }
     //pretvara url parametre u pripadajuće kolumne u bazi
     $allUnitParameters = Request::only('acc_type', 'rooms', 'baths', 'seaview', 'parking', 'wifi', 'air', 'tv', 'pets', 'access', 'cot', 'balcony', 'grill', 'dryer', 'wash', 'heating');
     $changedUnitKeysToDB = array("acc_type" => "cat", "rooms" => "rooms", "baths" => "wc", "seview" => "seview", "parking" => "parkinginclude", "wifi" => "dslinclude", "air" => "airinclude", "tv" => "tv", "pets" => "petsinclude", "access" => "handicap", "cot" => "little_bed", "balcony" => "balcony", "grill" => "fireside", "dryer" => "hairdryer", "wash" => "washing", "heating" => "toheat_ufloor");
     $allChangedUnitParameters = getKeyArray($allUnitParameters, $changedUnitKeysToDB);
     $onlyUnitParams = array();
     foreach ($allChangedUnitParameters as $key => $value) {
         if ($value > 0) {
             $onlyUnitParams[$key] = $value;
         }
     }
     $allPrivateAndHotelParameters = Request::only('pool', 'food');
     $pool = 0;
     if (isset($allPrivateAndHotelParameters['pool'])) {
         $pool = $allPrivateAndHotelParameters['pool'];
     }
     $food = 0;
     if (isset($allPrivateAndHotelParameters['food'])) {
         $food = $allPrivateAndHotelParameters['food'];
     }
     $allHouseParameters = Request::only('boat', 'berth');
     $boat = 0;
     if (isset($allHouseParameters['boat'])) {
         $boat = $allHouseParameters['boat'];
     }
     $berth = 0;
     if (isset($allHouseParameters['berth'])) {
         $berth = $allHouseParameters['berth'];
     }
     $allDestinationChildren = array();
     if (Input::has("destination") && Input::get('destination') > 0 && $unit->checkDestinationExist(Input::get('destination')) > 0) {
         $param_Destination = Input::get('destination');
         $houseDestinationDestinations = Destinations::where('jos_estateagent_town_id', $param_Destination)->first();
         if ($houseDestinationDestinations->parent > 0) {
             $param_Destination = Input::get('destination');
             $allDestinationChildren[] = Input::get('destination');
         } elseif ($houseDestinationDestinations->parent == 0) {
             $param_Destination = Input::get('destination');
             $param_AllchildDestinations = Destinations::getAllChildren($param_Destination);
             foreach ($param_AllchildDestinations as $child) {
                 $allDestinationChildren[] = $child->jos_estateagent_town_id;
             }
         }
     }
     if (isset($allParameters['start']) && isset($allParameters['end']) && $allParameters['end'] > $allParameters['start'] && $allParameters['start'] != 'Check+In' && $allParameters['end'] != 'Check+Out') {
         $checkInDate = getDBDate($allParameters['start']);
         $checkOutDate = getDBDate($allParameters['end']);
     }
     if (Input::has("start") && Input::get('end') != '') {
         $paramNrPersons = Input::get('nr_persons');
         $paramOrder = 'nr_persons';
     }
     if (Input::has("nr_persons") && Input::get('nr_persons') != '') {
         $paramNrPersons = Input::get('nr_persons');
         $paramOrder = 'nr_persons';
     }
     if (Input::has("q") && Input::get('q') != '') {
         $paramSearch = Input::get('q');
     }
     if (Input::has("acc_type") && Input::get('acc_type') > 0) {
         $param_Category = Input::get('acc_type');
     }
     if (Input::has("cat") && Input::get('cat') > 0) {
         $paramCat = Input::get('cat');
     }
     if (Input::has("rooms") && Input::get('rooms') > 0) {
         $paramOrder = 'rooms';
     }
     if (Input::has("sort")) {
         $param_Price = Input::get('sort');
     }
     list($meta_title, $meta_description) = $unit->getUnitsSearchMeta($param_Destination, $param_Category, $paramCat);
     //ako ima pretraživanje po searchu (q parametar)
     if ($paramSearch != '') {
         $allUnits = Units::search($paramSearch)->published()->whereHas('house', function ($query2) {
             $query2->published()->statusNot('Izvan pretrage');
         })->whereHas('house', function ($query3s) use($allDestinationChildren, $param_Destination) {
             if ($param_Destination > 0) {
                 $query3s->wherein('town_id', $allDestinationChildren);
             }
         })->with('unitPrice')->groupBy('id')->paginate($pagination);
         $allUnits->setPath('units');
     } else {
         $allUnits = Units::published()->where(function ($query) use($onlyUnitParams, $paramNrPersons) {
             foreach ($onlyUnitParams as $key => $value) {
                 if ($value > 0 && $key != 'rooms' && $key != 'wc') {
                     $query->where($key, $value);
                 } elseif ($value > 0 && ($key == 'rooms' || $key == 'wc')) {
                     $query->where($key, '>=', $value);
                 }
             }
             if ($paramNrPersons > 0) {
                 $query->whereRaw('person_berth + person_adjusts_berths BETWEEN ? AND ?+4', [$paramNrPersons, $paramNrPersons]);
             }
         })->where(function ($query) use($unitCat) {
             if (count($unitCat) > 0) {
                 $query->wherein('cat', $unitCat);
             }
         })->where(function ($query) use($food) {
             if ($food > 0) {
                 $query->hasFood();
             }
         })->where(function ($query) use($pool) {
             if ($pool > 0) {
                 $query->hasPool();
             }
         })->whereHas('house', function ($query2) {
             $query2->published()->statusNot('Izvan pretrage');
         })->whereHas('house', function ($query3s) use($allDestinationChildren, $param_Destination) {
             if ($param_Destination > 0) {
                 $query3s->wherein('town_id', $allDestinationChildren);
             }
         })->whereHas('house', function ($query3s) use($paramCat) {
             if ($paramCat > 0) {
                 $query3s->where('jos_estateagent_house_category_id', $paramCat);
             }
         })->whereHas('house', function ($query) use($boat) {
             if ($boat > 0) {
                 $query->hasBoat();
             }
         })->whereHas('house', function ($query) use($berth) {
             if ($berth > 0) {
                 $query->hasBerth();
             }
         })->whereHas('house', function ($query) use($allMainCategoryParams) {
             if (count($allMainCategoryParams) > 0) {
                 $query->wherein('jos_estateagent_main_categories_id', $allMainCategoryParams);
             }
         })->whereDoesntHave('unitCalendar.unitReservation', function ($query) use($checkInDate, $checkOutDate) {
             $query->where('date_to', '>', $checkInDate)->where('date_from', '<', $checkOutDate)->orWhere('date_to', '<', $checkInDate)->where('date_from', '>', $checkOutDate);
         })->with('unitPrice')->ordered($paramOrder)->paginate($pagination);
         $allUnits->setPath('units');
     }
     return view('accommodation.accommodation', compact('allUnits', 'meta_title', 'meta_description', 'allParameters', 'checkin', 'checkout', 'allSearchParameters'));
 }