/** * Execute the console command. * * @return mixed */ public function handle() { $data = file_get_contents(self::$URL); $e = new VTMISExtractor(); $e->input($data); foreach ($e->output() as $name => $data) { $spot = $this->spots->getOrCreateByName($name); $measurement = new Measurement(); $measurement->spot_id = $spot->id; foreach ($data as $key => $value) { $measurement->{$key} = $value; } $measurement->save(); } }
public function profile(Request $request) { $sessionId = $request->user()->id; $now = Carbon::now(); $now = $now->format('Y-m-d'); $userData = User::where('id', $sessionId)->first(); $userMeasure = Measurement::where('user_id', $sessionId)->orderBy('date', 'desc')->get(); $lastMeasure = json_encode($userMeasure); $age = $userData->getUserAge(); $today_tasks = Task::where('user_id', $sessionId)->where('date_to_do', $now)->orderBy('created_at', 'desc')->get(); $not_done_tasks = Task::where('user_id', $sessionId)->where('date_to_do', '!=', $now)->get(); $measurment_available = $userMeasure->count() > 0; if ($measurment_available) { $userMeasureData = $userMeasure->toArray(); $numberOfMeasurements = count($userMeasureData); for ($i = 0; $i < $numberOfMeasurements - 1; $i++) { foreach ($userMeasureData[$i] as $key => $value) { if ($value > $userMeasureData[$i + 1][$key]) { $userMeasureData[$i][$key . '_class'] = 'up'; } elseif ($value == $userMeasureData[$i + 1][$key]) { $userMeasureData[$i][$key . '_class'] = 'same'; } else { $userMeasureData[$i][$key . '_class'] = 'down'; } } } $currentMeasurements = User::getCurMeasurements(); $userWeight = $currentMeasurements['weight']; $userHeight = $currentMeasurements['height']; $userBodyFat = $currentMeasurements['body_fat']; $userBMI = $userWeight / ($userHeight / 100 * ($userHeight / 100)); $userBMI = number_format($userBMI, 2); $userBMIrange = User::getUserBMIrange($userBMI); //function from User Model $userData->userWeight = $userWeight; $userData->userHeight = $userHeight; $userData->userMeasure = $userMeasure; $userData->userMeasureData = $userMeasureData; $userData->userBodyFat = $userBodyFat; $userData->userBMI = $userBMI; $userData->userBMIrange = $userBMIrange; $userData->lastMeasure = $lastMeasure; } if ($userData) { // 'userWeight', 'userHeight', 'userMeasure', 'userMeasureData', 'userBodyFat', 'userBMI', 'userBMIrange','lastMeasure' return view('users.profile')->with(compact(array('userData', 'age', 'today_tasks', 'not_done_tasks', 'now', 'measurment_available'))); } return redirect('/food/index')->withErrors('You do not have sufficient permissions'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Request $request, $id) { $measure = Measurement::find($id); if ($measure && ($measure->user_id == $request->user()->id || $request->user()->is_admin())) { $measure->delete(); $data['message'] = 'Deleted successfully'; } else { $data['errors'] = 'Invalid Operation. You do not have sufficient permissions'; } return redirect('user/profile/' . $request->user()->id)->with($data); }
public static function getCurMeasurements() { $sessionId = Auth::user()->id; $currentMeasurements = Measurement::where('user_id', $sessionId)->orderBy('date', 'desc')->select('height', 'weight', 'body_fat')->first(); return $currentMeasurements; }