Example #1
0
 public function dataRefresh(Cafe $client)
 {
     $cafes = \App\Http\Models\Cafe::all();
     foreach ($cafes as $cafe) {
         $foursquareID = $cafe->foursquareID;
         // grab foursquare ID
         $command = $this->{$client}->getCommand('venues', array('venue_id' => $foursquareID));
         // grab foursquare data
         $foursquareData = $command->execute();
         // save to a variable
         $json4sq = json_decode(json_encode($foursquareData));
         // convert to a json object; foursquare object is part of $json4sq->response
         // set the properties of the object we just pulled
         $cafe->lat = $json4sq->response->venue->location->lat;
         $cafe->lng = $json4sq->response->venue->location->lng;
         if (isset($json4sq->response->venue->bestPhoto)) {
             $photoURL = $json4sq->response->venue->bestPhoto->prefix . 'original' . $json4sq->response->venue->bestPhoto->suffix;
         } else {
             $photoURL = null;
         }
         $cafe->photoURL = $photoURL;
         $cafe->street = $json4sq->response->venue->location->address;
         if (isset($json4sq->response->venue->location->crossStreet)) {
             $cafe->crossStreet = $json4sq->response->venue->location->crossStreet;
         }
         $cafe->state = $json4sq->response->venue->location->state;
         $cafe->country = $json4sq->response->venue->location->country;
         if (isset($json4sq->response->venue->contact->postalCode)) {
             $cafe->postcode = $json4sq->response->venue->location->postalCode;
         }
         if (isset($json4sq->response->venue->contact->phone)) {
             $cafe->phone = $json4sq->response->venue->contact->phone;
         }
         if (isset($json4sq->response->venue->contact->twitter)) {
             $cafe->twitter = $json4sq->response->venue->contact->twitter;
         }
         if (isset($json4sq->response->venue->contact->facebookUsername)) {
             $cafe->facebook = $json4sq->response->venue->contact->facebookUsername;
         }
         if (isset($json4sq->response->venue->url)) {
             $cafe->url = $json4sq->response->venue->url;
         }
         if (isset($json4sq->response->venue->location->neighborhood)) {
             $cafe->neighbourhood = $json4sq->response->venue->location->neighborhood;
         } else {
             $lat = $json4sq->response->venue->location->lat;
             $lng = $json4sq->response->venue->location->lng;
             $latlng = $lat . "," . $lng;
             $param = array("latlng" => $latlng);
             $response = \Geocoder::geocode('json', $param);
             $googleJson = json_decode($response);
             $cafe->neighbourhood = $googleJson->results[0]->address_components[2]->long_name;
         }
         $cafe->save();
     }
 }
Example #2
0
 public function store()
 {
     $user = Auth::user();
     $meal = new Meal();
     $meal->name = Input::get('name');
     $meal->description = Input::get('description');
     $meal->street = Input::get('street');
     $meal->city = Input::get('city');
     $meal->zip_code = Input::get('zip_code');
     $meal->seats = Input::get('seats');
     // get long and lat
     $param = array("address" => Input::get('street') . " " . Input::get('city') . " " . Input::get('zip_code'));
     $response = \Geocoder::geocode('json', $param);
     $json = json_decode($response, true);
     $location = $json['results'][0]['geometry']['location'];
     $lat = $location['lat'];
     $lng = $location['lng'];
     $meal->lat = $lat;
     $meal->lng = $lng;
     // get and parse date
     $date = Input::get('meal_date');
     $date_array = explode("/", $date);
     $day = (int) $date_array[0];
     $month = (int) $date_array[1];
     $year = (int) $date_array[2];
     // get and parse time
     $time = Input::get('meal_time');
     $time_array = explode(":", $time);
     $hour = (int) $time_array[0];
     $minutes = (int) $time_array[1];
     // create new dateTime
     $date_time = Carbon::create($year, $month, $day, $hour, $minutes);
     $meal->meal_date_time = $date_time;
     // create ingredients
     $ingredients = Input::get('ingredient');
     $meal_ingredients = array();
     foreach ($ingredients as $ingredient) {
         $meal_ingredients[] = new Ingredient(array('name' => $ingredient['name'], 'unit' => $ingredient['unit'], 'quantity' => $ingredient['quantity']));
     }
     //save  into the DB
     $meal->save();
     $user->meals()->attach($meal);
     $meal->ingredients()->saveMany($meal_ingredients);
     // redirect
     Flash::success('Votre repas a bien été crée !');
     return Redirect::route('meals.show', $meal);
 }
 /**
  * Parses each row of the CSV file and then extracts addresses, groups by category, and GeoCodes address data.
  * Sends GeoCoded coordinates to mapview.blade View where the Maps API v3 places markers at those locations
  * @return View
  */
 public function processHeaders()
 {
     //flash old input to session in case of errors
     Input::flashOnly('filePath');
     //setup holding array for locations ordered by category
     $groupedLocations = array();
     // Create $locations array to hold address + zip of each row
     $locations = array();
     // Check if all values in the input array only appear once
     $data = array_count_values(Input::all());
     foreach ($data as $key => $value) {
         if ($value != 1) {
             return Redirect::to('/')->withInput()->with('errorMsg', 'Multiple headers cannot reference the same column.');
         }
     }
     //our data is now the keys (integers) of each column. This is a 0-based column index
     $inputCSV = Reader::createFromPath(urldecode(Input::get('filePath')));
     $inputCSV->setDelimiter(',');
     $validRows = $inputCSV->addFilter(function ($row, $index) {
         return $index > 0;
         //ignore headers
     })->addFilter(function ($row) {
         return isset($row[Input::get('zip')], $row[Input::get('address')], $row[Input::get('category')]);
         //only get rows where zip, addr, and category are filled
     })->fetchAll();
     // Loop through fetched rows from CSV
     for ($i = 0; $i < sizeof($validRows); $i++) {
         //Add addresses to $locations array formatted as: 555+Address+St+ZIPCODE
         $locations[] = array('addrMarker' => urlencode($validRows[$i][Input::get('address')] . " " . $validRows[$i][Input::get('zip')]), 'category' => $validRows[$i][Input::get('category')]);
     }
     // Get geocoded coordinates for each entry in $location
     foreach ($locations as $location) {
         $geocodedLoc = Geocoder::geocode('json', array('address' => $location['addrMarker']));
         // Hold Geocoded coordinates
         $tempLatLang = json_decode($geocodedLoc, $assoc = true);
         // Build grouped array based on category data
         // Create new subarray for each unique category
         if (!isset($groupedLocations[$location['category']])) {
             $groupedLocations[$location['category']] = array();
         }
         $groupedLocations[$location['category']][] = array('lat' => $tempLatLang['results'][0]['geometry']['location']['lat'], 'lng' => $tempLatLang['results'][0]['geometry']['location']['lng'], 'category' => $location['category']);
     }
     return View::make('mapview')->with('mapDataPts', $groupedLocations);
 }
Example #4
0
 /**
  * Get all lots near address with available spots
  *
  * @param null $address search address
  * @return array all lots with available spots
  */
 public function getAvailableNearAddress($address = null)
 {
     // Get address information from Google Maps API
     $geocode = Geocoder::geocode($address);
     // Get address latitude
     $latitude = $geocode->getLatitude();
     // Get address longitude
     $longitude = $geocode->getLongitude();
     // Check database for nearest locations based on address's latitude and longitude
     $locations = $this->getNearestLocationsFromDB($latitude, $longitude);
     // Check if there are any locations within 5 miles
     if (empty($locations)) {
         return 'There are no parking lots within 5 miles';
     }
     // New lots array
     $lots = array();
     // Index
     $i = 0;
     // Go through each location
     foreach ($locations as $location) {
         // Find lot by id
         $lot = $this->lotRepository->find($location->id, array('regions'));
         // Store the lot's regions
         $regions = $lot->regions;
         // New lot regions array
         $lotRegions = array();
         // Index
         $j = 0;
         // Lot available spots variable
         $lotAvailableSpots = 0;
         if (count($regions)) {
             // Go through each region
             foreach ($regions as $region) {
                 // Check if region capacity is greater than spots occupied
                 if (json_decode($region['capacity']) > json_decode($region['spots_occupied'])) {
                     // Calculate available spots
                     $availableSpots = json_decode($region['capacity']) - json_decode($region['spots_occupied']);
                     // Set filtered region array
                     $filteredRegion = array('id' => $region->id, 'name' => $region->name, 'capacity' => $region->capacity, 'spots_occupied' => $region->spots_occupied, 'spots_available' => json_encode($availableSpots), 'lot_id' => $region->lot_id);
                     // Calculate lot's available spots
                     $lotAvailableSpots += $availableSpots;
                     // Save each filtered region array to the lot regions array
                     $lotRegions[$j] = $filteredRegion;
                     // Increment the index
                     $j++;
                 }
             }
             // Set the lot array
             $lot = array('id' => $lot->id, 'name' => $lot->name, 'address' => $lot->address, 'spots_available' => json_encode($lotAvailableSpots), 'distance' => $location->distance, 'longitude' => $lot->longitude, 'latitude' => $lot->latitude, 'regions' => $lotRegions);
             // Save each lot in the lots array
             $lots[$i] = $lot;
             // Increment the index
             $i++;
         }
     }
     // Return the lots array
     return $lots;
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $param = array("address" => "Warszawa, Mickiewicza", "components" => "country:PL");
     $response = \Geocoder::geocode('json', $param);
     dd($response);
 }