/**
  *
  */
 private function createPrograms()
 {
     foreach (Config::get('programs') as $tempProgram) {
         $program = new ExerciseProgram(['name' => $tempProgram]);
         $program->user()->associate($this->user);
         $program->save();
     }
 }
 /**
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $exerciseProgram = new ExerciseProgram($request->only(['name']));
     $exerciseProgram->user()->associate(Auth::user());
     $exerciseProgram->save();
     $exerciseProgram = $this->transform($this->createItem($exerciseProgram, new ExerciseProgramTransformer()))['data'];
     return response($exerciseProgram, Response::HTTP_CREATED);
 }
 /**
  *
  * @param $exercises
  * @param Unit $unit
  * @param Series $series
  */
 private function insertExercisesInSeries($exercises, Unit $unit, Series $series)
 {
     $index = 0;
     //        $series_ids = Series::where('user_id', $this->user->id)->lists('id')->all();
     foreach ($exercises as $exercise) {
         $index++;
         $stretch = isset($exercise['stretch']) ? 1 : 0;
         $temp = new Exercise(['name' => $exercise['name'], 'description' => $exercise['description'], 'default_quantity' => $exercise['defaultQuantity'], 'step_number' => $index, 'target' => '3 * 10', 'priority' => $exercise['priority'], 'stretch' => $stretch]);
         if (isset($exercise['frequency'])) {
             $temp['frequency'] = $exercise['frequency'];
         }
         $temp->user()->associate($this->user);
         $temp->defaultUnit()->associate($unit);
         $temp->program()->associate(ExerciseProgram::first());
         $temp->series()->associate($series);
         $temp->save();
     }
 }
 /**
  *
  * @param Request $request
  * @param Exercise $exercise
  * @return mixed
  */
 public function update(Request $request, Exercise $exercise)
 {
     // Create an array with the new fields merged
     $data = array_compare($exercise->toArray(), $request->only(['name', 'step_number', 'default_quantity', 'description', 'target', 'priority', 'frequency']));
     $exercise->update($data);
     if ($request->has('stretch')) {
         $exercise->stretch = $request->get('stretch');
         $exercise->save();
     }
     if ($request->has('series_id')) {
         $series = Series::findOrFail($request->get('series_id'));
         $exercise->series()->associate($series);
         $exercise->save();
     }
     if ($request->has('program_id')) {
         $program = ExerciseProgram::findOrFail($request->get('program_id'));
         $exercise->program()->associate($program);
         $exercise->save();
     }
     if ($request->has('default_unit_id')) {
         $unit = Unit::where('for', 'exercise')->findOrFail($request->get('default_unit_id'));
         $exercise->defaultUnit()->associate($unit);
         $exercise->save();
     }
     return $this->responseOkWithTransformer($exercise, new ExerciseTransformer());
 }