Пример #1
0
 public function postDeleteRun()
 {
     // First verify we own the run (for safety)
     // And then Delete
     $run_id = $_POST['run_id'];
     $run = Run::where('id', '=', $run_id)->first();
     if ($run->user_id == Auth::user()->id) {
         $run->delete();
         return 1;
     } else {
         return 0;
     }
 }
Пример #2
0
 /**
  *  Gather all relevant data for passing into the All Shoes View
  *  @return array of all relevant data
  */
 public function prepareUserShoeData($name, $include_hidden = false)
 {
     /**
      * Get All of a User's Relevant Data
      */
     $shoe_array = array();
     $user = User::where('name', '=', $name)->first();
     // Sort so that newest shoes show up first
     $shoes = Shoe::where('user_id', '=', $user->id)->orderBy('created_at', 'DESC')->get();
     /**
      *  Now Map It All
      */
     $array = array('username' => $user->name, 'email' => $user->email);
     /**
      * Loops through all shoes and matches all runs to the appropriate shoe
      * Also totals up the number of miles based off of the runs
      * And calculates miles remianing
      * Ignores shoes that are hidden unless $include_hidden is set to 'true'
      */
     foreach ($shoes as $shoe) {
         if ($shoe->show || $include_hidden) {
             $shoe->runs = Run::where('shoe_id', '=', $shoe->id)->orderBy('run_date', 'DESC')->get();
             $shoe->miles_run = 0;
             foreach ($shoe->runs as $run) {
                 $shoe->miles_run += $run->miles;
                 $run->run_date = date("M d, Y", strtotime($run->run_date));
                 // Only one decimal for miles
                 $run->miles = number_format_clean($run->miles, 1);
                 // Add a string version for printing
                 if ($run->miles == 1) {
                     $run->miles_string = "1 Mile";
                 } else {
                     $run->miles_string = $run->miles . " Miles";
                 }
             }
             // Don't let @var miles_remaining this value go below zero
             $shoe->miles_remaining = $shoe->miles_cap - $shoe->miles_run;
             if ($shoe->miles_remaining < 0) {
                 $shoe->miles_remaining = 0;
             }
             $shoe->percent_remaining = $shoe->miles_run / $shoe->miles_cap * 100;
             array_push($shoe_array, $shoe);
         }
     }
     $array['shoes'] = $shoe_array;
     return $array;
 }