/**
  *
  * @param Request $request
  * @return mixed
  */
 public function index(Request $request)
 {
     if ($request->get('typing')) {
         $exercises = Exercise::forCurrentUser()->where('name', 'LIKE', '%' . $request->get('typing') . '%')->get();
         return $this->transform($this->createCollection($exercises, new ExerciseTransformer()));
     }
     return $this->exercisesRepository->getExercises();
 }
 /**
  * Create a few exercise entries for each of the last 5 days
  */
 private function createEntriesForTheLastFiveDays()
 {
     foreach (range(0, 4) as $index) {
         $today = Carbon::today();
         $this->date = $today->subDays($index);
         if ($this->date == Carbon::today()) {
             $this->createEntriesForToday();
         } else {
             if ($this->date == Carbon::today()->subdays(1)) {
                 //Add assisted squat entries for 1 day ago
                 $this->insertExerciseSet(Exercise::forCurrentUser()->where('name', 'assisted squats')->first(), Carbon::today()->subDays(1));
             } else {
                 if ($this->date == Carbon::today()->subdays(2)) {
                     //Add back lever entries for 2 days ago
                     $this->insertExerciseSet(Exercise::forCurrentUser()->where('name', 'back lever')->first(), Carbon::today()->subDays(2));
                 } else {
                     $this->createEntriesForOneDay();
                 }
             }
         }
     }
 }
 /**
  * Get all exercises for the current user,
  * along with their tags, default unit name
  * and the name of the series each exercise belongs to.
  * Order first by series name, then by step number.
  * @return mixed
  */
 public function getExercises()
 {
     $exercises = Exercise::forCurrentUser('exercises')->with('defaultUnit')->orderBy('step_number')->with('series')->with('tags')->get();
     return transform(createCollection($exercises, new ExerciseTransformer()))['data'];
 }
Пример #4
0
 /**
  * @test
  * @return void
  */
 public function it_can_update_an_exercise_default_quantity()
 {
     $this->logInUser();
     $exercise = Exercise::forCurrentUser()->first();
     $response = $this->call('PUT', '/api/exercises/' . $exercise->id, ['default_quantity' => 7]);
     $content = json_decode($response->getContent(), true)['data'];
     //        dd($content);
     $this->checkExerciseKeysExist($content);
     $this->assertEquals(1, $content['id']);
     $this->assertEquals('kneeling pushups', $content['name']);
     $this->assertEquals(1, $content['stepNumber']);
     $this->assertEquals(7, $content['defaultQuantity']);
     $this->assertEquals(['id' => 1, 'name' => 'pushup'], $content['series']);
     $this->assertEquals(1, $content['defaultUnit']['data']['id']);
     $this->assertEquals('reps', $content['defaultUnit']['data']['name']);
     $this->assertEquals(200, $response->getStatusCode());
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     Route::bind('exercises', function ($id) {
         return Exercise::forCurrentUser()->findOrFail($id);
     });
     Route::bind('exerciseEntries', function ($id) {
         return ExerciseEntry::forCurrentUser()->findOrFail($id);
     });
     Route::bind('menuEntries', function ($id) {
         return MenuEntry::forCurrentUser()->findOrFail($id);
     });
     Route::bind('exerciseSeries', function ($id) {
         return ExerciseSeries::forCurrentUser()->findOrFail($id);
     });
     Route::bind('foods', function ($id) {
         return Food::forCurrentUser()->findOrFail($id);
     });
     Route::bind('recipes', function ($id) {
         return Recipe::forCurrentUser()->findOrFail($id);
     });
     Route::bind('exerciseTags', function ($id) {
         return Tag::forCurrentUser()->where('for', 'exercise')->findOrFail($id);
     });
     Route::bind('recipeTags', function ($id) {
         return Tag::forCurrentUser()->where('for', 'recipe')->findOrFail($id);
     });
     Route::bind('foodUnits', function ($id) {
         return Unit::forCurrentUser()->where('for', 'food')->findOrFail($id);
     });
     Route::bind('exerciseUnits', function ($id) {
         return Unit::forCurrentUser()->where('for', 'exercise')->findOrFail($id);
     });
     Route::bind('timers', function ($id) {
         return Timer::forCurrentUser()->findOrFail($id);
     });
     Route::bind('activities', function ($id) {
         return Activity::forCurrentUser()->findOrFail($id);
     });
     Route::bind('weights', function ($idOrDate) {
         if (strrpos($idOrDate, '-')) {
             //parameter is the date of the entry
             $weight = Weight::forCurrentUser()->where('date', $idOrDate)->first();
         } else {
             //parameter is the id of the entry
             $weight = Weight::forCurrentUser()->findOrFail($idOrDate);
         }
         return $weight;
     });
     /**
      * $parameter is either the id or the date
      */
     Route::bind('journal', function ($parameter) {
         /**
          * @VP:
          * Is there a better way to check if the $parameter is an
          * id or a date? When I tried using Carbon to create an object from
          * the parameter, it threw an exception when the $parameter was the id,
          * whereas I just wanted a boolean.
          */
         if (strrpos($parameter, '-')) {
             //$parameter is the date of the entry
             $journal = Journal::forCurrentUser()->where('date', $parameter)->first();
         } else {
             //$parameter is the id of the entry
             $journal = Journal::forCurrentUser()->findOrFail($parameter);
         }
         return $journal;
     });
 }