Example #1
0
 public function getPointsOnMap()
 {
     $locations = racelocation::all();
     $mapPoints = [];
     foreach ($locations as $location) {
         $feature = ['type' => 'Feature', 'properties' => ['title' => $location->location_name, 'id' => $location->location_id], 'geometry' => ['type' => 'Point', 'coordinates' => [floatval($location->latitude), floatval($location->longitude)]]];
         $mapPoints[] = $feature;
         // $locationGeoJson['features'][$i] = $feature;
     }
     $locationsGeoJson = ['type' => 'FeatureCollection', 'features' => $mapPoints];
     return $locationsGeoJson;
 }
 public function getMapLocationRaces(RaceMapContract $map)
 {
     $locationID = Request::input('locationID');
     $locationRaces = racelocation::where('location_id', '=', $locationID)->first()->getRaces()->get();
     return json_encode($locationRaces);
 }
Example #3
0
 /**
  * @param $input
  * @param $FISArray
  * @param $USSAArray
  *
  * @return string
  *
  * Saves race, points, and racer when called. Returns string with status of save
  */
 public function SaveRace($input, $FISArray, $USSAArray)
 {
     /*
      * Check to see if race already exists in the database. If it does set the saveStatus
      */
     //Set Variables for the options
     $season = Option::where('option_name', '=', 'season')->first()->value;
     $USSA_list = Option::where('option_name', '=', 'USSA_list')->first()->value;
     $FIS_list = Option::where('option_name', '=', 'FIS_list')->first()->value;
     //Save location to database
     $saveLocation = new racelocation();
     $latitude = round($input['hidden-lat'], 3);
     $longitude = round($input['hidden-long'], 3);
     //Check for location already existing
     $checkForLocation = $saveLocation->where('latitude', '=', $latitude)->where('longitude', '=', $longitude)->first();
     if ($checkForLocation == null) {
         $saveLocation->location_name = $input['race-location'];
         $saveLocation->latitude = $latitude;
         $saveLocation->longitude = $longitude;
         $saveLocation->save();
         $locationID = $saveLocation->location_id;
     } else {
         $locationID = $checkForLocation->location_id;
     }
     //Save race to datbase
     $saveRace = new savedrace();
     $saveRace->status = 'not approved';
     $saveRace->race_name = $input['race-name'];
     $saveRace->gender = $input['gender'];
     $saveRace->clicks = 0;
     $saveRace->USSA_list = $season . " " . $USSA_list;
     $saveRace->FIS_list = $season . " " . $FIS_list;
     $saveRace->distance = $input['distance'];
     $saveRace->format = $input['format'];
     $saveRace->winners_time = $input['winners-time'];
     $saveRace->technique = $input['technique'];
     $saveRace->distance_km = $input['distance-km'];
     $saveRace->savedLocation()->associate($locationID);
     $saveRace->save();
     //Hold race that was just saved in a variable
     $savedRace = savedrace::where('savedrace_id', '=', $saveRace->savedrace_id)->first();
     //Loop through racers and save them to the database
     $savedRacers = [];
     $iter = 1;
     foreach ($FISArray['Racers'] as $racer) {
         //Check to see if the racer already exists in our database
         $checkForSavedRacer = savedracer::where('last', 'LIKE', '%' . trim($racer['LastName']) . '%')->where('first', 'LIKE', '%' . trim($racer['FirstName']) . '%')->first();
         if ($checkForSavedRacer != NULL) {
             $savedRacers[$iter] = $checkForSavedRacer;
         } else {
             $saveRacer = new savedracer();
             $saveRacer->last = $racer['LastName'];
             $saveRacer->first = $racer['FirstName'];
             $saveRacer->save();
             $savedRacers[$iter] = savedracer::where('savedracer_id', '=', $saveRacer->id)->first();
         }
         $iter++;
     }
     //Loop through and save all the points from the race
     for ($i = 1; $i < 6; $i++) {
         $savePoints = new savedpoint();
         $savePoints->place = $i;
         $savePoints->USSA_points = $USSAArray['Racers'][$i - 1]['Points'];
         $savePoints->FIS_points = $FISArray['Racers'][$i - 1]['Points'];
         if (array_key_exists('Note', $USSAArray['Racers'][$i - 1])) {
             $savePoints->USSA_note = $USSAArray['Racers'][$i - 1]['Note'];
         } else {
             $savePoints->USSA_note = null;
         }
         if (array_key_exists('Note', $FISArray['Racers'][$i - 1])) {
             $savePoints->FIS_note = $FISArray['Racers'][$i - 1]['Note'];
         } else {
             $savePoints->FIS_note = null;
         }
         //Associate race and racer with the points
         $savePoints->savedrace()->associate($savedRace);
         $savePoints->savedracer()->associate($savedRacers[$i]);
         $savePoints->save();
     }
     $saveStatus = 'Race Successfully Saved, Waiting To Be Approved By Admin';
     mail('*****@*****.**', 'Race Waiting to be approved', $input['race-name']);
     return $saveStatus;
 }