Example #1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Name $name)
 {
     // Delete name of $id
     $name->delete();
     flash()->success('Name has been deleted!');
     return redirect('names');
 }
Example #2
0
 public function save(CreateNameRequest $request, Name $names)
 {
     $names->create($request->all());
     return redirect()->route('show_names');
 }
Example #3
0
 /**
  * Searches through database of FIS racers and returns their points, penalty of race, and users points
  *
  * @param $input
  *
  * @return array
  *
  * ['Racers'] => array of the 5 racers
  *      [0-4] => ['Points'] => Racer's current points, ['LastName'] => Racer's last name, ['FirstName'] => Racer's first name
  * ['Penalty'] => penalty
  * ['RacePoints'] => Race Points
  * ['FinalPoints'] => users FIS points
  */
 public function getFISpoints($input)
 {
     /*
      * Set variables
      */
     extract($this->setVariables($input));
     /*
      * Convert time to seconds
      */
     $usersTime = time_to_sec($input['your-time']);
     $winnersTime = time_to_sec($input['winners-time']);
     /*
      * Loop through racers and grab points from database
      */
     for ($i = 0; $i < 5; $i++) {
         $nameResult = Name::where('Lastname', 'LIKE', '%' . trim($input["last-{$i}"]) . '%')->where('Firstname', 'LIKE', '%' . trim($input["first-{$i}"]) . '%')->first();
         if ($nameResult == NULL) {
             $output['Racers'][$i] = ['Points' => 990, 'LastName' => trim($input["last-{$i}"]), 'FirstName' => trim($input["first-{$i}"]), 'Note' => 'Racer does not have a FIS license, 990 used'];
             $racersPoints[$i] = 990;
         } else {
             $pointResult = $nameResult->getPoints()->where('Disciplinecode', 'LIKE', "%{$FISDistance}%")->first();
             if ($pointResult == NULL) {
                 $pointResult['Fispoints'] = 990;
             } else {
                 $pointResult->toArray();
             }
             $nameResult->toArray();
             $output['Racers'][$i] = ['Points' => $pointResult['Fispoints'], 'LastName' => $nameResult['Lastname'], 'FirstName' => $nameResult['Firstname']];
             $racersPoints[$i] = $pointResult['Fispoints'];
         }
     }
     /*
      * Calculate penalty
      * Sum of three lowest points divided by 3.75
      */
     $sortResult = sort($racersPoints);
     $topThree = array_slice($racersPoints, 0, 3, true);
     $penalty = array_sum($topThree) / 3.75;
     $penalty = round($penalty, 2, PHP_ROUND_HALF_UP);
     $output['Penalty'] = $penalty;
     /*
      * Calculate race points
      *
      * Page 20
      * http://www.fis-ski.com/mm/Document/documentlibrary/Cross-Country/04/26/74/FISpointsrules2015-2016_inclattachments_English.pdf
      *
      */
     $racePoints = $usersTime * $fFactor / $winnersTime - $fFactor;
     $racePoints = round($racePoints, 2, PHP_ROUND_HALF_UP);
     $output['RacePoints'] = $racePoints;
     /*
      * Calculate final FIS Points
      */
     $finalPoints = $penalty + $racePoints;
     $output['FinalPoints'] = $finalPoints;
     return $output;
 }
Example #4
0
 public function getSearchResults($input)
 {
     $nameResults = Name::where('Lastname', 'LIKE', "%{$input}%")->take(5)->get()->toArray();
     return $nameResults;
 }