Example #1
0
 public static function getMealsWithTotals($selectedDate, $user_id)
 {
     $meals = Meal::select(\DB::raw('*, meals.id as meal_id'))->leftJoin('foods', 'meals.food_id', '=', 'foods.id')->where('planed_food', '0')->where('date', $selectedDate)->where('meals.user_id', $user_id)->orderBy('meals.created_at', 'desc')->paginate(100);
     $meals_planed = Meal::select(\DB::raw('*, meals.id as meal_id'))->leftJoin('foods', 'meals.food_id', '=', 'foods.id')->where('planed_food', '1')->where('date', $selectedDate)->where('meals.user_id', $user_id)->orderBy('meals.created_at', 'desc')->paginate(100);
     $totals = ['sum_weight' => 0, 'sum_kcal' => 0, 'sum_proteins' => 0, 'sum_carbs' => 0, 'sum_fibre' => 0, 'sum_fats' => 0];
     $totals_planed = ['sum_weight' => 0, 'sum_kcal' => 0, 'sum_proteins' => 0, 'sum_carbs' => 0, 'sum_fibre' => 0, 'sum_fats' => 0];
     foreach ($meals as $meal) {
         $totals['sum_weight'] += $meal['weight'];
         $totals['sum_kcal'] += $meal['kcal'] * $meal['weight'] / 100;
         $totals['sum_proteins'] += $meal['proteins'] * $meal['weight'] / 100;
         $totals['sum_carbs'] += $meal['carbs'] * $meal['weight'] / 100;
         $totals['sum_fats'] += $meal['fats'] * $meal['weight'] / 100;
         $totals['sum_fibre'] += $meal['fibre'] * $meal['weight'] / 100;
     }
     foreach ($meals_planed as $meal) {
         $totals_planed['sum_weight'] += $meal['weight'];
         $totals_planed['sum_kcal'] += $meal['kcal'] * $meal['weight'] / 100;
         $totals_planed['sum_proteins'] += $meal['proteins'] * $meal['weight'] / 100;
         $totals_planed['sum_carbs'] += $meal['carbs'] * $meal['weight'] / 100;
         $totals_planed['sum_fats'] += $meal['fats'] * $meal['weight'] / 100;
         $totals_planed['sum_fibre'] += $meal['fibre'] * $meal['weight'] / 100;
     }
     //TODO calculate totals above.
     //$totals = [];
     return ['meals' => $meals, 'meals_planed' => $meals_planed, 'totals' => $totals, 'totals_planed' => $totals_planed];
 }
 public function getData($table, $id)
 {
     $result = '';
     try {
         switch ($table) {
             case 'feeds':
                 $result = Feed::findOrFail($id);
                 break;
             case 'meals':
                 $result = Meal::findOrFail($id);
                 break;
             case 'videos':
                 $result = Video::findOrFail($id);
                 break;
         }
         return $result;
     } catch (ModelNotFoundException $ex) {
         return false;
     }
 }
Example #3
0
 /**
  * Inserts new entry into Client Table and 
  * checks for validation on form submission
  * Authorization is checked for privilages
  * 
  * @param  	CreateClientRequest $request
  * @return 	Response
  */
 public function store(ClientRequest $request)
 {
     $input = $request->all();
     $client = Client::create($input);
     $program = Program::where('id', '=', $request->input('programs'))->first();
     $agent = Auth::user();
     $client->program()->associate($program);
     $client->agent()->associate($agent);
     $client->save();
     $temp = Temp::where('fname', '=', $request->fname)->where('lname', '=', $request->lname)->first();
     if ($temp != null) {
         $temp->delete();
     }
     $meal = new Meal();
     $meal->date_fed = date('Y-m-d');
     $meal->client()->associate($client);
     $meal->breakfast = 0;
     $meal->lunch = 0;
     $meal->dinner = 0;
     $meal->save();
     return redirect('client');
 }
Example #4
0
 public function btnClickDinner($id)
 {
     $client = Client::findOrFail($id);
     $meal = Meal::where('date_fed', '=', date('Y-m-d'))->where('client_id', '=', $client->id)->first();
     if ($meal->dinner == 1) {
         \DB::table('meals')->where('client_id', '=', $client->id)->where('date_fed', '=', date('Y-m-d'))->update(['dinner' => 0, 'client_id' => $client->id]);
     } else {
         \DB::table('meals')->where('client_id', '=', $client->id)->where('date_fed', '=', date('Y-m-d'))->update(['dinner' => 1, 'client_id' => $client->id]);
     }
     return redirect(action('MealController@mealRosterDinner'));
 }
 /**
  * User meal removal ajax processor
  *
  * @return Json response
  */
 public function getDelete(Request $request, $id)
 {
     try {
         $meal = Meal::findOrFail($id);
         $meal->delete();
         return response()->json(['status' => 'success']);
     } catch (ModelNotFoundException $e) {
         abort(404, 'Item not found.');
     }
 }
 /**
  * @return mixed
  */
 public function getLastSortOrder()
 {
     $meal = Meal::orderBy('sort_order', 'DESC')->first();
     return ++$meal->sort_order;
 }
Example #7
0
 public function planed(Request $request)
 {
     $meal_id = $request->id;
     $meal = Meal::find($meal_id);
     if ($meal && ($meal->user_id == $request->user()->id || $request->user()->is_admin())) {
         $meal->planed_food = 0;
         $meal->id = $meal_id;
         $meal->save();
         return redirect('/meal/index');
     } else {
         return redirect('/meal/index')->withErrors('You do not have sufficient permissions');
     }
 }
Example #8
0
 public function destroy($id)
 {
     // delete
     $meal = Meal::find($id);
     $meal->delete();
     // redirect
     Flash::success('Votre repas a bien été supprimée !');
     return Redirect::to('/meals');
 }
Example #9
0
 /**
  * Test getRecommendation() method signature throws error exception
  *
  * @return void
  */
 public function testGetRecommendationMethodSignatureThrowsErrorExceptionWithNonIntValue()
 {
     $mealModel = new Meal();
     $this->setExpectedException('ErrorException');
     $recommendedDish = $mealModel->getRecommendation($user, '12');
 }
Example #10
0
 public function getMeals()
 {
     $meals = Meal::all();
     return response()->json($meals);
 }
 public function index()
 {
     $meals = Meal::all();
     JavaScript::put(['meals' => $meals]);
     return view('landing');
 }