public static function findByAddressOrCreateWithNewnessIndicator($address) { $geo = GeoCache::getByAddress($address); $cached = false; Log::debug("Found Geocode Object", ["geo_cache" => $geo]); if (!$geo) { Log::debug('Address NOT found in geo_cache'); $resp = Geocode::geocode($address); $status = $resp['status']; if ($status == 'OK') { $id = GeoCache::create(new GeoCache(['address' => $address, 'geocoded_address' => $address, 'lat' => $resp['results'][0]['geometry']['location']['lat'], 'lng' => $resp['results'][0]['geometry']['location']['lng'], 'formatted_address' => $resp['results'][0]['formatted_address'], 'location_type' => $resp['results'][0]['geometry']['location_type'], 'partial_match' => Geocode::getPartialMatchFromResponse($resp)])); $geo = GeoCache::get($id); } else { Log::error('geocoding failed', ['address' => $address, 'response' => $resp]); } } else { Log::debug('Address found in geo_cache'); $cached = true; $status = "LOCALLY_CACHED"; } return [$geo, $cached, $status]; }
/** * Run the database seeds. * * @return void */ public function run() { define('THIS_MANY_ADS', \App\Constants::first()->n_ad_seeds); $faker = Faker\Factory::create('es_ES'); $n_house_categories = DB::table('category_house')->count(); $n_country_house_categories = DB::table('category_country_house')->count(); $n_business_categories = DB::table('category_business')->count(); $n_land_categories = DB::table('category_land')->count(); $n_lodging_categories = DB::table('category_lodging')->count(); $n_room_categories = DB::table('category_room')->count(); $n_energy_certification_options = DB::table('energy_certification')->count(); $n_business_distribution_options = DB::table('business_distribution')->count(); $n_business_facade_options = DB::table('business_facade')->count(); $n_business_location_options = DB::table('business_location')->count(); $n_current_tenants_gender_options = DB::table('current_tenants_gender')->count(); $n_garage_capacity_options = DB::table('garage_capacity')->count(); $n_nearest_town_distance_options = DB::table('nearest_town_distance')->count(); $n_office_distribution_options = DB::table('office_distribution')->count(); $n_payment_day_options = DB::table('payment_day')->count(); $n_surroundings_options = DB::table('surroundings')->count(); $n_tenant_gender_options = DB::table('tenant_gender')->count(); $n_tenant_min_stay_options = DB::table('tenant_min_stay')->count(); $n_tenant_occupation_options = DB::table('tenant_occupation')->count(); $n_tenant_sexual_orientation_options = DB::table('tenant_sexual_orientation')->count(); $performances = ['75', '100', '125', '150', '175', '200', '225', '250']; $certs = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; $blocks = ['A', 'B', 'C', 'D', 'E']; $doors = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', 'Puerta única', 'Izquierda', 'Derecha', 'Exterior', 'Interior', 'Centro', 'Exterior izquierda', 'Exterior derecha', 'Interior izquierda', 'Interior derecha', 'Centro izquierda', 'Centro derecha']; $floors = ['Planta 1º', 'Planta 2º', 'Planta 3º', 'Planta 4º', 'Planta 5º', 'Planta 6º', 'Planta 7º', 'Planta 8º', 'Planta 9º', 'Planta 10º', 'Planta 11º', 'Planta 12º', 'Planta 13º', 'Planta 14º', 'Planta 15º', 'Planta 16º', 'Planta 17º', 'Planta 18º', 'Planta 19º', 'Planta 20º', 'Planta 21º', 'Planta 22º', 'Planta 23º', 'Planta 24º', 'Planta 25º', 'Planta 26º', 'Sótano', 'Semi-sótano', 'Bajo', 'Entreplanta', 'Por debajo de la planta baja (-2)', 'Por debajo de la planta baja (-1)']; $activities = ['Tienda de ropa', 'Frutería', 'Panadería', 'Taller mecánico', 'Bar', 'Restaurante', 'Carnicería', 'Gestión de residuos industriales', 'Copistería', 'Fábrica de papel', 'Acerería', 'Alfarería', 'Fábrica de cemento', 'Fábrica de mezcla bituminosa', 'Tienda de respuestos']; $deposits = ['1 mes', '2 meses', '3 meses', '4 meses', '5 meses', '6 meses o más']; for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newRentHouse = \App\RentHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_house_id' => mt_rand(1, $n_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'has_equipped_kitchen' => mt_rand(0, 1), 'has_furniture' => mt_rand(0, 1), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_house'; $newAd->local_id = $newRentHouse->id; $newAd->save(); $this->command->info('Seeded Rent House (id: ' . $newRentHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 100); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newSellHouse = \App\SellHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_house_id' => mt_rand(1, $n_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_house'; $newAd->local_id = $newSellHouse->id; $newAd->save(); $this->command->info('Seeded Sell House (id: ' . $newSellHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 100); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(300, 2400); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newSellCountryHouse = \App\SellCountryHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_country_house_id' => mt_rand(1, $n_country_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_country_house'; $newAd->local_id = $newSellCountryHouse->id; $newAd->save(); $this->command->info('Seeded Sell Country House (id: ' . $newSellCountryHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(300, 2400); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newRentCountryHouse = \App\RentCountryHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_country_house_id' => mt_rand(1, $n_country_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_country_house'; $newAd->local_id = $newRentCountryHouse->id; $newAd->save(); $this->command->info('Seeded Rent Country House (id: ' . $newRentCountryHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10 * $area_usable); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newRentOffice = \App\RentOffice::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_min_for_sale' => $area_min_for_sale, 'n_floors' => mt_rand(1, 4), 'has_offices_only' => mt_rand(0, 1), 'office_distribution_id' => mt_rand(1, $n_office_distribution_options), 'n_restrooms' => mt_rand(1, 8), 'has_bathrooms' => mt_rand(0, 1), 'has_fire_detectors' => mt_rand(0, 1), 'has_fire_extinguishers' => mt_rand(0, 1), 'has_fire_sprinklers' => mt_rand(0, 1), 'has_fireproof_doors' => mt_rand(0, 1), 'has_emergency_lights' => mt_rand(0, 1), 'has_doorman' => mt_rand(0, 1), 'has_air_conditioning_preinstallation' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_hot_water' => mt_rand(0, 1), 'has_kitchen' => mt_rand(0, 1), 'has_archive' => mt_rand(0, 1), 'has_double_windows' => mt_rand(0, 1), 'has_suspended_ceiling' => mt_rand(0, 1), 'has_suspended_floor' => mt_rand(0, 1), 'is_handicapped_adapted' => mt_rand(0, 1), 'has_bathrooms_inside' => mt_rand(0, 1), 'is_exterior' => mt_rand(0, 1), 'n_elevators' => mt_rand(1, 8), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'n_parking_spaces' => mt_rand(10, 50), 'has_steel_door' => mt_rand(0, 1), 'has_security_system' => mt_rand(0, 1), 'has_access_control' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_office'; $newAd->local_id = $newRentOffice->id; $newAd->save(); $this->command->info('Seeded Rent Office (id: ' . $newRentOffice->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 300); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10 * $area_usable); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newSellOffice = \App\SellOffice::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_min_for_sale' => $area_min_for_sale, 'n_floors' => mt_rand(1, 4), 'has_offices_only' => mt_rand(0, 1), 'office_distribution_id' => mt_rand(1, $n_office_distribution_options), 'n_restrooms' => mt_rand(1, 8), 'has_bathrooms' => mt_rand(0, 1), 'has_fire_detectors' => mt_rand(0, 1), 'has_fire_extinguishers' => mt_rand(0, 1), 'has_fire_sprinklers' => mt_rand(0, 1), 'has_fireproof_doors' => mt_rand(0, 1), 'has_emergency_lights' => mt_rand(0, 1), 'has_doorman' => mt_rand(0, 1), 'has_air_conditioning_preinstallation' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_hot_water' => mt_rand(0, 1), 'has_kitchen' => mt_rand(0, 1), 'has_archive' => mt_rand(0, 1), 'has_double_windows' => mt_rand(0, 1), 'has_suspended_ceiling' => mt_rand(0, 1), 'has_suspended_floor' => mt_rand(0, 1), 'is_handicapped_adapted' => mt_rand(0, 1), 'has_bathrooms_inside' => mt_rand(0, 1), 'is_exterior' => mt_rand(0, 1), 'n_elevators' => mt_rand(1, 8), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'n_parking_spaces' => mt_rand(10, 50), 'has_steel_door' => mt_rand(0, 1), 'has_security_system' => mt_rand(0, 1), 'has_access_control' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_office'; $newAd->local_id = $newSellOffice->id; $newAd->save(); $this->command->info('Seeded Sell Office (id: ' . $newSellOffice->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newRentBusiness = \App\RentBusiness::create(['ad_id' => $newAd->id, 'price' => $price, 'is_transfer' => mt_rand(0, 1), 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'category_business_id' => mt_rand(1, $n_business_categories), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'business_distribution_id' => mt_rand(1, $n_business_distribution_options), 'business_facade_id' => mt_rand(1, $n_business_facade_options), 'n_shop_windows' => mt_rand(1, 4), 'business_location_id' => mt_rand(1, $n_business_location_options), 'n_floors' => mt_rand(1, 3), 'n_restrooms' => mt_rand(1, 4), 'last_activity' => $activities[array_rand($activities)], 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'has_archive' => mt_rand(0, 1), 'has_smoke_extractor' => mt_rand(0, 1), 'has_fully_equipped_kitchen' => mt_rand(0, 1), 'has_steel_door' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'is_corner_located' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_business'; $newAd->local_id = $newRentBusiness->id; $newAd->save(); $this->command->info('Seeded Rent Business (id: ' . $newRentBusiness->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 300); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newSellBusiness = \App\SellBusiness::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'category_business_id' => mt_rand(1, $n_business_categories), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'business_distribution_id' => mt_rand(1, $n_business_distribution_options), 'business_facade_id' => mt_rand(1, $n_business_facade_options), 'n_shop_windows' => mt_rand(1, 4), 'business_location_id' => mt_rand(1, $n_business_location_options), 'n_floors' => mt_rand(1, 3), 'n_restrooms' => mt_rand(1, 4), 'last_activity' => $activities[array_rand($activities)], 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'has_archive' => mt_rand(0, 1), 'has_smoke_extractor' => mt_rand(0, 1), 'has_fully_equipped_kitchen' => mt_rand(0, 1), 'has_steel_door' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'is_corner_located' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_business'; $newAd->local_id = $newSellBusiness->id; $newAd->save(); $this->command->info('Seeded Sell Business (id: ' . $newSellBusiness->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(10000, 100000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 100); $newAd = App\Ad::create(); $newSellGarage = \App\SellGarage::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'garage_capacity_id' => mt_rand(1, $n_garage_capacity_options), 'is_covered' => mt_rand(0, 1), 'has_automatic_door' => mt_rand(0, 1), 'has_lift' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'has_security_guard' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_garage'; $newAd->local_id = $newSellGarage->id; $newAd->save(); $this->command->info('Seeded Sell Garage (id: ' . $newSellGarage->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100, 1000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $newAd = App\Ad::create(); $newRentGarage = \App\RentGarage::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'garage_capacity_id' => mt_rand(1, $n_garage_capacity_options), 'is_covered' => mt_rand(0, 1), 'has_automatic_door' => mt_rand(0, 1), 'has_lift' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'has_security_guard' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_garage'; $newAd->local_id = $newRentGarage->id; $newAd->save(); $this->command->info('Seeded Rent Garage (id: ' . $newRentGarage->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(50000, 500000); $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10) * $area_usable; $newAd = App\Ad::create(); $newSellLand = \App\SellLand::create(['ad_id' => $newAd->id, 'price' => $price, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_land_id' => mt_rand(1, $n_land_categories), 'area_total' => $area_land, 'area_building_land' => $area_constructed, 'area_min_for_sale' => $area_min_for_sale, 'is_classified_residential_block' => mt_rand(0, 1), 'is_classified_residential_house' => mt_rand(0, 1), 'is_classified_office' => mt_rand(0, 1), 'is_classified_commercial' => mt_rand(0, 1), 'is_classified_hotel' => mt_rand(0, 1), 'is_classified_industrial' => mt_rand(0, 1), 'is_classified_public_service' => mt_rand(0, 1), 'is_classified_others' => mt_rand(0, 1), 'max_floors_allowed' => mt_rand(0, 5) ? mt_rand(1, 3) : mt_rand(1, 30), 'has_road_access' => mt_rand(0, 1), 'nearest_town_distance_id' => mt_rand(1, $n_nearest_town_distance_options), 'has_water' => mt_rand(0, 1), 'has_electricity' => mt_rand(0, 1), 'has_sewer_system' => mt_rand(0, 1), 'has_natural_gas' => mt_rand(0, 1), 'has_street_lighting' => mt_rand(0, 1), 'has_sidewalks' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_land'; $newAd->local_id = $newSellLand->id; $newAd->save(); $this->command->info('Seeded Sell Land (id: ' . $newSellLand->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(200, 5000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10 * $area_usable); $newAd = App\Ad::create(); $newRentLand = \App\RentLand::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_land_id' => mt_rand(1, $n_land_categories), 'area_total' => $area_land, 'area_building_land' => $area_constructed, 'area_min_for_sale' => $area_min_for_sale, 'is_classified_residential_block' => mt_rand(0, 1), 'is_classified_residential_house' => mt_rand(0, 1), 'is_classified_office' => mt_rand(0, 1), 'is_classified_commercial' => mt_rand(0, 1), 'is_classified_hotel' => mt_rand(0, 1), 'is_classified_industrial' => mt_rand(0, 1), 'is_classified_public_service' => mt_rand(0, 1), 'is_classified_others' => mt_rand(0, 1), 'max_floors_allowed' => mt_rand(0, 5) ? mt_rand(1, 3) : mt_rand(1, 30), 'has_road_access' => mt_rand(0, 1), 'nearest_town_distance_id' => mt_rand(1, $n_nearest_town_distance_options), 'has_water' => mt_rand(0, 1), 'has_electricity' => mt_rand(0, 1), 'has_sewer_system' => mt_rand(0, 1), 'has_natural_gas' => mt_rand(0, 1), 'has_street_lighting' => mt_rand(0, 1), 'has_sidewalks' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_land'; $newAd->local_id = $newRentLand->id; $newAd->save(); $this->command->info('Seeded Rent Land (id: ' . $newRentLand->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newRentApartment = \App\RentApartment::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'is_regular' => mt_rand(0, 1), 'is_penthouse' => mt_rand(0, 1), 'is_duplex' => mt_rand(0, 1), 'is_studio' => mt_rand(0, 1), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'n_bedrooms' => mt_rand(1, 5), 'n_bathrooms' => mt_rand(1, 3), 'is_exterior' => mt_rand(0, 1), 'has_equipped_kitchen' => mt_rand(0, 1), 'has_furniture' => mt_rand(0, 1), 'has_elevator' => mt_rand(0, 1), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_apartment'; $newAd->local_id = $newRentApartment->id; $newAd->save(); $this->command->info('Seeded Rent Apartment (id: ' . $newRentApartment->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 300); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newSellApartment = \App\SellApartment::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'is_regular' => mt_rand(0, 1), 'is_penthouse' => mt_rand(0, 1), 'is_duplex' => mt_rand(0, 1), 'is_studio' => mt_rand(0, 1), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'n_bedrooms' => mt_rand(1, 5), 'n_bathrooms' => mt_rand(1, 3), 'is_exterior' => mt_rand(0, 1), 'has_elevator' => mt_rand(0, 1), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_apartment'; $newAd->local_id = $newSellApartment->id; $newAd->save(); $this->command->info('Seeded Sell Apartment (id: ' . $newSellApartment->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $n_d_b = mt_rand(0, 2); $n_1_b = mt_rand(0, 2); $n_2_b = mt_rand(0, 2); $n_3_b = mt_rand(0, 1); $n_4_b = mt_rand(0, 1); $min_capacity = $n_d_b * 2 + $n_1_b + $n_2_b * 2 + $n_3_b * 3 + $n_4_b * 4; $n_sb = mt_rand(0, 1); $n_d_sb = mt_rand(0, 1); $n_eb = mt_rand(0, 1); $max_capacity = $min_capacity + $n_sb + $n_d_sb * 2 + $n_eb; $payment_day = mt_rand(1, $n_payment_day_options); $days_before = \App\OptionPaymentDay::find($payment_day)->pluck('name') == 'Días antes de la entrada' ? mt_rand(1, 30) : null; $has_booking = mt_rand(0, 2); $has_deposit = mt_rand(0, 2); $has_cleaning = mt_rand(0, 1); if ($has_booking == 1) { $booking = mt_rand(1, 100); } elseif ($has_booking == 2) { $booking = mt_rand(250, 550); } else { $booking = null; } if ($has_deposit == 1) { $deposit = mt_rand(1, 100); } elseif ($has_deposit == 2) { $deposit = mt_rand(350, 1550); } else { $deposit = null; } $cleaning = !$has_cleaning ? mt_rand(50, 350) : null; $area_total = mt_rand(45, 300); $area_garden = intval(0.4 * $area_total); $area_terrace = intval(0.2 * $area_total); $newAd = App\Ad::create(); $newRentVacation = \App\Lodging::create(['ad_id' => $newAd->id, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'surroundings_id' => mt_rand(1, $n_surroundings_options), 'category_lodging_id' => mt_rand(1, $n_lodging_categories), 'has_multiple_lodgings' => mt_rand(0, 1), 'area_total' => $area_total, 'area_garden' => $area_garden, 'area_terrace' => $area_terrace, 'distance_to_beach' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_town_center' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_ski_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_golf_course' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_airport' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_supermarket' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_river_or_lake' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_marina' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_horse_riding_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_scuba_diving_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_train_station' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_bus_station' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_hospital' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_hiking_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'n_double_bedroom' => $n_d_b, 'n_two_beds_room' => $n_2_b, 'n_single_bed_room' => $n_1_b, 'n_three_beds_room' => $n_3_b, 'n_four_beds_room' => $n_4_b, 'n_sofa_bed' => $n_sb, 'n_double_sofa_bed' => $n_d_sb, 'n_extra_bed' => $n_eb, 'min_capacity' => $min_capacity, 'max_capacity' => $max_capacity, 'payment_day_id' => $payment_day, 'n_days_before' => $days_before, 'has_booking' => $has_booking, 'booking' => $booking, 'has_deposit' => $has_deposit, 'deposit' => $deposit, 'has_cleaning' => $has_cleaning, 'cleaning' => $cleaning, 'has_included_towels' => mt_rand(0, 1), 'has_included_expenses' => mt_rand(0, 1), 'accepts_cash' => mt_rand(0, 1), 'accepts_transfer' => mt_rand(0, 1), 'accepts_credit_card' => mt_rand(0, 1), 'accepts_paypal' => mt_rand(0, 1), 'accepts_check' => mt_rand(0, 1), 'accepts_western_union' => mt_rand(0, 1), 'accepts_money_gram' => mt_rand(0, 1), 'has_barbecue' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_private_swimming_pool' => mt_rand(0, 1), 'has_shared_swimming_pool' => mt_rand(0, 1), 'has_indoor_swimming_pool' => mt_rand(0, 1), 'has_private_garden' => mt_rand(0, 1), 'has_shared_garden' => mt_rand(0, 1), 'has_furnished_garden' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_playground' => mt_rand(0, 1), 'has_mountain_sights' => mt_rand(0, 1), 'has_sea_sights' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_jacuzzi' => mt_rand(0, 1), 'has_tv' => mt_rand(0, 1), 'has_cable_tv' => mt_rand(0, 1), 'has_internet' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_fan' => mt_rand(0, 1), 'has_cradle' => mt_rand(0, 1), 'has_hairdryer' => mt_rand(0, 1), 'has_dishwasher' => mt_rand(0, 1), 'has_fridge' => mt_rand(0, 1), 'has_oven' => mt_rand(0, 1), 'has_microwave' => mt_rand(0, 1), 'has_coffee_maker' => mt_rand(0, 1), 'has_dryer' => mt_rand(0, 1), 'has_washer' => mt_rand(0, 1), 'has_iron' => mt_rand(0, 1), 'is_smoking_allowed' => mt_rand(0, 1), 'is_pet_allowed' => mt_rand(0, 1), 'has_elevator' => mt_rand(0, 1), 'is_car_recommended' => mt_rand(0, 1), 'is_handicapped_adapted' => mt_rand(0, 1), 'is_out_town_center' => mt_rand(0, 1), 'is_isolated' => mt_rand(0, 1), 'is_nudist_area' => mt_rand(0, 1), 'is_bar_area' => mt_rand(0, 1), 'is_gayfriendly_area' => mt_rand(0, 1), 'is_family_tourism_area' => mt_rand(0, 1), 'is_luxury_area' => mt_rand(0, 1), 'is_charming' => mt_rand(0, 1), 'has_bicycle_rental' => mt_rand(0, 1), 'has_car_rental' => mt_rand(0, 1), 'has_adventure_activities' => mt_rand(0, 1), 'has_kindergarten' => mt_rand(0, 1), 'has_sauna' => mt_rand(0, 1), 'has_tennis_court' => mt_rand(0, 1), 'has_paddle_court' => mt_rand(0, 1), 'has_gym' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_vacation'; $newAd->local_id = $newRentVacation->id; $newAd->save(); $this->command->info('Seeded Rent Vacation (id: ' . $newRentVacation->id . ')'); $n_seasons_prices = mt_rand(1, 4); for ($j = 0; $j < $n_seasons_prices; $j++) { $from_date = \Carbon\Carbon::createFromDate(null, mt_rand(1, 12), 1); $to_date = $from_date->addMonths(mt_rand(1, 6)); $newSeasonPrice = \App\SeasonPrice::create(['n_season' => $j, 'from_date' => $j == 0 ? \Carbon\Carbon::createFromFormat('d/m/Y', '1/1/1900') : $from_date, 'to_date' => $j == 0 ? \Carbon\Carbon::createFromFormat('d/m/Y', '1/1/2999') : $to_date, 'p_one_night' => mt_rand(15, 100), 'p_weekend_night' => mt_rand(30, 200), 'p_one_week' => mt_rand(80, 700), 'p_half_month' => mt_rand(150, 1400), 'p_one_month' => mt_rand(300, 2800), 'p_extra_guest_per_night' => mt_rand(7, 50), 'n_min_nights' => mt_rand(1, 60), 'rent_vacation_id' => $newRentVacation->id]); $this->command->info('Seeded Season Price (id: ' . $newSeasonPrice->id . ') for Rent Vacation (id: ' . $newRentVacation->id . ')'); } } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(250, 700); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $n_bedrooms = mt_rand(2, 5); $n_people = intval($n_bedrooms / 2 + 1); $newAd = App\Ad::create(); $newRentRoom = \App\Room::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_room_id' => mt_rand(1, $n_room_categories), 'area_room' => mt_rand(10, 50), 'n_people' => $n_people, 'n_bedrooms' => $n_bedrooms, 'n_bathrooms' => mt_rand(1, 2), 'current_tenants_gender_id' => mt_rand(1, $n_current_tenants_gender_options), 'is_smoking_allowed' => mt_rand(0, 1), 'is_pet_allowed' => mt_rand(0, 1), 'min_current_tenants_age' => mt_rand(18, 23), 'max_current_tenants_age' => mt_rand(23, 35), 'has_elevator' => mt_rand(0, 1), 'has_furniture' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_internet' => mt_rand(0, 1), 'has_house_keeper' => mt_rand(0, 1), 'tenant_gender_id' => mt_rand(1, $n_tenant_gender_options), 'tenant_occupation_id' => mt_rand(1, $n_tenant_occupation_options), 'tenant_sexual_orientation_id' => mt_rand(1, $n_tenant_sexual_orientation_options), 'tenant_min_stay_id' => mt_rand(1, $n_tenant_min_stay_options), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_room'; $newAd->local_id = $newRentRoom->id; $newAd->save(); $this->command->info('Seeded Rent Room (id: ' . $newRentRoom->id . ')'); } foreach (\App\Ad::all() as $ad) { $n_pics = mt_rand(0, 12); for ($i = 0; $i < $n_pics; ++$i) { \App\AdPic::create(['ad_id' => $ad->id, 'filename' => 'http://lorempixel.com/640/480/city/Faker']); $this->command->info('Seeded Pictures for Ad (id: ' . $ad->id . ')'); } } }
/** * @param $id * @param Request $request * @return \Illuminate\View\View */ public function update_geocache($id, Request $request) { $address = $request->input('address'); $hcp_id = $request->input('hcp_id'); $resp = Geocode::geocode($address); if ($resp['status'] == 'OK') { GeoCache::update($id, ['geocoded_address' => $address, 'lat' => $resp['results'][0]['geometry']['location']['lat'], 'lng' => $resp['results'][0]['geometry']['location']['lng'], 'formatted_address' => $resp['results'][0]['formatted_address'], 'location_type' => $resp['results'][0]['geometry']['location_type'], 'partial_match' => Geocode::getPartialMatchFromResponse($resp)]); } else { Log::error('geocoding failed', ['address' => $address, 'response' => $resp]); } return $this->geocode_hcp($hcp_id); }
public function getResults() { /* * Possible search types from HOME/SEARCH: * 0 by locality (locality provided) * 1 by proximity (lat, lng calculated from provided address) * * possible operations from HOME/SEARCH: * 0 Buy * 1 Rent * 2 Share * * possible typologies from HOME/SEARCH: * 0 New development * 1 Houses + country houses + apartments * 2 Vacation * 3 Room * 4 Office * 5 Business * 6 Garage * 7 Land */ $input = \Input::all(); // Input validation if ($input['operation'] == '0') { $allowed_price_values = '1000000,2000000,3000000,950000,900000,850000,750000,700000,650000,600000,550000,' . '500000,450000,400000,380000,360000,340000,320000,300000,280000,260000,240000,220000,200000,180000,' . '160000,140000,120000,100000,80000,60000'; } else { $allowed_price_values = '3000,2700,2400,2100,2000,1900,1800,1700,1600,1500,1400,1300,1200,1100,1000,900,' . '800,700,600,500,400,300,200,100'; } $rules = array('operation' => 'required|digits:1|in:0,1,2', 'typology' => 'required|digits:1', 'search_type' => 'required|digits:1|in:0,1', 'locality' => 'sometimes|string|max:255', 'address' => 'sometimes|string|max:510', 'price-min' => 'sometimes|string|in:' . $allowed_price_values, 'price-max' => 'sometimes|string|in:' . $allowed_price_values); $validator = \Validator::make($input, $rules); if ($validator->fails()) { return \Redirect::route('home'); } // Set default values if (!isset($input['operation'])) { $input['operation'] = '0'; } if (!isset($input['typology'])) { $input['typology'] = '1'; } if (!isset($input['locality'])) { $input['locality'] = 'Barcelona'; } if (!isset($input['search_type'])) { $input['search_type'] = '0'; } if (!isset($input['address']) || $input['address'] == '') { $input['address'] = $input['locality']; } if (!isset($input['price-min']) || $input['price-min'] == '') { $input['price-min'] = 0; } if (!isset($input['price-max']) || $input['price-max'] == '') { $input['price-max'] = 0; } // Set minimum and maximum prices when no price range provided $price_min = $input['price-min'] ? (int) $input['price-min'] : -1; $price_max = $input['price-max'] ? (int) $input['price-max'] : 999999999; // Share a house = Rent a room if ($input['operation'] == '2' && $input['typology'] == '1') { $input['operation'] = '1'; $input['typology'] = '3'; } // Search queries if ($input['search_type'] == '0') { $locality = $input['locality']; switch ($input['operation']) { case '0': //buy switch ($input['typology']) { case '0': //new development $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,has_elevator,description,area,hide_address,`name` as type,ad_id FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,'0' as has_elevator,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id\n FROM sell_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.is_new_development = 1 AND t1.locality = ? AND t1.price >= ? AND t1.price <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,'0' as has_elevator,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id\n FROM sell_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.is_new_development = 1 AND t2.locality = ? AND t2.price >= ? AND t2.price <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_elevator,t3.has_parking_space,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id\n FROM sell_apartment AS t3\n WHERE t3.is_new_development = 1 AND t3.locality = ? AND t3.price >= ? AND t3.price <= ?\n ) AS t4;\n "), [$input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max]); break; case '1': //house + country house + apartment $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,has_elevator,description,area,hide_address,`name` as type,ad_id FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,'0' as has_elevator,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id\n FROM sell_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,'0' as has_elevator,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id\n FROM sell_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.locality = ? AND t2.price >= ? AND t2.price <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_parking_space,t3.has_elevator,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id\n FROM sell_apartment AS t3\n WHERE t3.locality = ? AND t3.price >= ? AND t3.price <= ?\n ) AS t4;\n "), [$input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max]); break; case '4': //office $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,'Oficina' as type,area_constructed as area,hide_address,ad_id\n FROM sell_office AS t1\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '5': //business $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,'Garaje' as type,area_constructed as area,hide_address,ad_id\n FROM sell_business AS t1\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '6': //garage $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,'Garaje' as type,`name` as garage_capacity,hide_address,ad_id\n FROM sell_garage AS t1\n LEFT JOIN garage_capacity AS t2 ON t1.garage_capacity_id = t2.id\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '7': //land $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,area_total as area,'Terreno' as type,`name` as land_category,hide_address,ad_id\n FROM sell_land AS t1\n LEFT JOIN category_land AS t2 ON t1.category_land_id = t2.id\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; } break; case '1': //rent switch ($input['typology']) { case '0': //new development $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,has_elevator,description,area,hide_address,`name` as type,ad_id FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,'0' as has_elevator,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id\n FROM rent_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.is_new_development = 1 AND t1.locality = ? AND t1.price >= ? AND t1.price <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,'0' as has_elevator,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id\n FROM rent_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.is_new_development = 1 AND t2.locality = ? AND t2.price >= ? AND t2.price <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_parking_space,t3.has_elevator,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id\n FROM rent_apartment AS t3\n WHERE t3.is_new_development = 1 AND t3.locality = ? AND t3.price >= ? AND t3.price <= ?\n ) AS t4;\n "), [$input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max]); break; case '1': //house + country house + apartment $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,has_elevator,description,area,hide_address,`name` as type,ad_id FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,'0' as has_elevator,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id\n FROM rent_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,'0' as has_elevator,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id\n FROM rent_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.locality = ? AND t2.price >= ? AND t2.price <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_parking_space,t3.has_elevator,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id\n FROM rent_apartment AS t3\n WHERE t3.locality = ? AND t3.price >= ? AND t3.price <= ?\n ) AS t4;\n "), [$input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max, $input['locality'], $price_min, $price_max]); break; case '2': //vacation/lodge $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,description,t2.`name` as type,t4.`name` as surroundings,area_total as area,min_capacity,max_capacity,hide_address,MIN(p_one_month) as min_price_per_night,ad_id\n FROM rent_vacation AS t1\n LEFT JOIN category_lodging AS t2 ON t1.category_lodging_id = t2.id\n LEFT JOIN vacation_season_price AS t3 ON t1.id = t3.rent_vacation_id\n LEFT JOIN surroundings AS t4 ON t1.surroundings_id = t4.id\n WHERE t1.locality = ?\n HAVING min_price_per_night >= ? AND min_price_per_night <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '3': //room $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,'Habitación' as type,area_room as area,hide_address,ad_id\n FROM rent_room AS t1\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '4': //office $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,'Oficina' as type,area_constructed as area,hide_address,ad_id\n FROM rent_office AS t1\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '5': //business $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,`name` as type,area_constructed as area,hide_address,ad_id\n FROM rent_business AS t1\n LEFT JOIN category_business AS t2 ON t1.category_business_id = t2.id\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '6': //garage $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,'Garaje' as type,`name` as garage_capacity,hide_address,ad_id\n FROM rent_garage AS t1\n LEFT JOIN garage_capacity AS t2 ON t1.garage_capacity_id = t2.id\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; case '7': //land $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,area_total as area,'Terreno' as type,`name` as land_category,hide_address,ad_id\n FROM rent_land AS t1\n LEFT JOIN category_land AS t2 ON t1.category_land_id = t2.id\n WHERE t1.locality = ? AND t1.price >= ? AND t1.price <= ?;\n "), [$input['locality'], $price_min, $price_max]); break; } break; } } else { // Geo-located search queries // Geo-locate address $location = Geocode::geocodeAddress($input['address']); if (!$location) { return \Redirect::back(); } $locality = $location['locality']; // Geo-distance calculations $R = 6371.01; //radio de la tierra promedio (en km) $distance = \App\Constants::first()->search_distance; $r = $distance / $R; //ángulo en radianes que equivale a recorrer $distance sobre un círculo de radio $R $lat_r = deg2rad($location['lat']); //en rads $lng_r = deg2rad($location['lng']); //en rads $min_lat = rad2deg($lat_r - $r); //en sexag $max_lat = rad2deg($lat_r + $r); //en sexag $delta_lng = asin(sin($r) / cos($lat_r)); //en rads $min_lng = rad2deg($lng_r - $delta_lng); //en sexag $max_lng = rad2deg($lng_r + $delta_lng); //en sexag // DB queries switch ($input['operation']) { case '0': //buy switch ($input['typology']) { case '0': //new development $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,description,area,hide_address,`name` as type,ad_id,distance FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM sell_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.is_new_development = 1\n AND t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t2.lat))+COS({$lat_r})*COS(RADIANS(t2.lat))*COS(RADIANS(t2.lng)-{$lng_r}))) AS distance\n FROM sell_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.is_new_development = 1\n AND t2.lat >= ? AND t2.lat <= ? AND t2.lng >= ? AND t2.lng <= ? AND t2.price >= ? AND t2.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_parking_space,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t3.lat))+COS({$lat_r})*COS(RADIANS(t3.lat))*COS(RADIANS(t3.lng)-{$lng_r}))) AS distance\n FROM sell_apartment AS t3\n WHERE t3.is_new_development = 1\n AND t3.lat >= ? AND t3.lat <= ? AND t3.lng >= ? AND t3.lng <= ? AND t3.price >= ? AND t3.price <= ?\n HAVING distance <= ?\n ) AS t4\n ORDER BY t4.distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '1': //house + country house + apartment $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,description,area,hide_address,`name` as type,ad_id,distance FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM sell_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t2.lat))+COS({$lat_r})*COS(RADIANS(t2.lat))*COS(RADIANS(t2.lng)-{$lng_r}))) AS distance\n FROM sell_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.lat >= ? AND t2.lat <= ? AND t2.lng >= ? AND t2.lng <= ? AND t2.price >= ? AND t2.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_parking_space,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t3.lat))+COS({$lat_r})*COS(RADIANS(t3.lat))*COS(RADIANS(t3.lng)-{$lng_r}))) AS distance\n FROM sell_apartment AS t3\n WHERE t3.lat >= ? AND t3.lat <= ? AND t3.lng >= ? AND t3.lng <= ? AND t3.price >= ? AND t3.price <= ?\n HAVING distance <= ?\n ) AS t4\n ORDER BY t4.distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '4': //office $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,'Oficina' as type,area_constructed as area,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM sell_office AS t1\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '5': //business $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,`name` as type,area_constructed as area,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM sell_business AS t1\n LEFT JOIN category_business AS t2 ON t1.category_business_id = t2.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '6': //garage $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,'Garaje' as type,`name` as garage_capacity,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM sell_garage AS t1\n LEFT JOIN garage_capacity AS t2 ON t1.garage_capacity_id = t2.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '7': //land $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,area_total as area,'Terreno' as type,`name` as land_category,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM sell_land AS t1\n LEFT JOIN category_land AS t2 ON t1.category_land_id = t2.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; } break; case '1': //rent switch ($input['typology']) { case '0': //new development $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,description,area,hide_address,`name` as type,ad_id,distance FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.is_new_development = 1\n AND t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t2.lat))+COS({$lat_r})*COS(RADIANS(t2.lat))*COS(RADIANS(t2.lng)-{$lng_r}))) AS distance\n FROM rent_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.is_new_development = 1\n AND t2.lat >= ? AND t2.lat <= ? AND t2.lng >= ? AND t2.lng <= ? AND t2.price >= ? AND t2.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_parking_space,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t3.lat))+COS({$lat_r})*COS(RADIANS(t3.lat))*COS(RADIANS(t3.lng)-{$lng_r}))) AS distance\n FROM rent_apartment AS t3\n WHERE t3.is_new_development = 1\n AND t3.lat >= ? AND t3.lat <= ? AND t3.lng >= ? AND t3.lng <= ? AND t3.price >= ? AND t3.price <= ?\n HAVING distance <= ?\n ) AS t4\n ORDER BY t4.distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '1': //house + country house + apartment $ads = \DB::select(\DB::raw("\n SELECT rooms,floor,locality,route,street_number,price,has_parking_space,description,area,hide_address,`name` as type,ad_id,distance FROM (\n SELECT t1.n_bedrooms as rooms,'0' as floor,t1.locality,t1.route,t1.street_number,t1.price,t1.has_parking_space,t1.description,t1.area_constructed as area,t1.hide_address,t5.name,t1.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_house AS t1\n LEFT JOIN category_house AS t5 ON t1.category_house_id = t5.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t2.n_bedrooms as rooms,'0' as floor,t2.locality,t2.route,t2.street_number,t2.price,t2.has_parking_space,t2.description,t2.area_constructed as area,t2.hide_address,t6.name,t2.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t2.lat))+COS({$lat_r})*COS(RADIANS(t2.lat))*COS(RADIANS(t2.lng)-{$lng_r}))) AS distance\n FROM rent_country_house AS t2\n LEFT JOIN category_country_house AS t6 ON t2.category_country_house_id = t6.id\n WHERE t2.lat >= ? AND t2.lat <= ? AND t2.lng >= ? AND t2.lng <= ? AND t2.price >= ? AND t2.price <= ?\n HAVING distance <= ?\n UNION\n SELECT t3.n_bedrooms as rooms,t3.floor_number as floor,t3.locality,t3.route,t3.street_number,t3.price,t3.has_parking_space,t3.description,t3.area_constructed as area,t3.hide_address,\n IF(is_duplex = 1, 'Dúplex', IF(is_penthouse = 1, 'Ático', IF(is_studio = 1, 'Estudio', 'Piso'))) as `name`,t3.ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t3.lat))+COS({$lat_r})*COS(RADIANS(t3.lat))*COS(RADIANS(t3.lng)-{$lng_r}))) AS distance\n FROM rent_apartment AS t3\n WHERE t3.lat >= ? AND t3.lat <= ? AND t3.lng >= ? AND t3.lng <= ? AND t3.price >= ? AND t3.price <= ?\n HAVING distance <= ?\n ) AS t4\n ORDER BY t4.distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance, $min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '2': //vacation/lodge $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,description,t2.`name` as type,t4.`name` as surroundings,area_total as area,min_capacity,max_capacity,hide_address,MIN(p_one_month) as min_price_per_night,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_vacation AS t1\n LEFT JOIN category_lodging AS t2 ON t1.category_lodging_id = t2.id\n LEFT JOIN vacation_season_price AS t3 ON t1.id = t3.rent_vacation_id\n LEFT JOIN surroundings AS t4 ON t1.surroundings_id = t4.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ?\n HAVING distance <= ? AND min_price_per_night >= ? AND min_price_per_night <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $distance, $price_min, $price_max]); break; case '3': //room $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,'Habitación' as type,area_room as area,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_room AS t1\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '4': //office $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,'Oficina' as type,area_constructed as area,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_office AS t1\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '5': //business $ads = \DB::select(\DB::raw("\n SELECT floor_number as floor,locality,route,street_number,price,description,`name` as type,area_constructed as area,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_business AS t1\n LEFT JOIN category_business AS t2 ON t1.category_business_id = t2.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '6': //garage $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,'Garaje' as type,`name` as garage_capacity,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_garage AS t1\n LEFT JOIN garage_capacity AS t2 ON t1.garage_capacity_id = t2.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; case '7': //land $ads = \DB::select(\DB::raw("\n SELECT locality,route,street_number,price,description,area_total as area,'Terreno' as type,`name` as land_category,hide_address,ad_id,\n ({$R}*ACOS(SIN({$lat_r})*SIN(RADIANS(t1.lat))+COS({$lat_r})*COS(RADIANS(t1.lat))*COS(RADIANS(t1.lng)-{$lng_r}))) AS distance\n FROM rent_land AS t1\n LEFT JOIN category_land AS t2 ON t1.category_land_id = t2.id\n WHERE t1.lat >= ? AND t1.lat <= ? AND t1.lng >= ? AND t1.lng <= ? AND t1.price >= ? AND t1.price <= ?\n HAVING distance <= ?\n ORDER BY distance ASC;\n "), [$min_lat, $max_lat, $min_lng, $max_lng, $price_min, $price_max, $distance]); break; } break; } } // Prepare a human readable typology string for the results view switch ($input['typology']) { case '0': //new development $typology = 'promociones de obra nueva'; break; case '1': //house + country house + apartment $typology = 'casas y pisos'; break; case '2': //vacation/lodge $typology = 'alquileres vacacionales'; break; case '3': //room $typology = 'habitaciones'; break; case '4': //office $typology = 'oficinas'; break; case '5': //business $typology = 'locales o naves'; break; case '6': //garage $typology = 'garajes'; break; case '7': //land $typology = 'terrenos'; break; default: $typology = 'inmueble'; break; } // Search type as a variable, to be sent to the results view $search_type = $input['search_type']; return view('results', compact('ads', 'typology', 'locality', 'search_type', 'input')); }