public function logFoodUnit()
 {
     $user = $this->spawnUser();
     $food = App\Food::SearchByName('apple')[0];
     $user->addToFoodHistory($food, 1, 1);
     return $user;
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $items = $request->get('items');
     $me = \Auth::user();
     $order = new \App\Order();
     $order->client()->associate($me);
     $my_orders = $me->orders;
     if ($my_orders->isEmpty()) {
         foreach ($me->waiters()->online()->get() as $waiter) {
             \App\Notification::add($me->toArray(), 'serve_me', $waiter);
         }
     } else {
         $my_order = $my_orders->first()->toArray();
         if ($my_order['waiter_id']) {
             $waiter = \App\User::find($my_order['waiter_id']);
             $order->waiter()->associate($waiter);
             \App\Notification::add($me->toArray(), 'serve_me_again', $waiter);
         }
     }
     $order->save();
     foreach ($items as $item) {
         $food = \App\Food::find($item['food']);
         if ($food->category->menu->admin_id == $me->admin_id) {
             $item = new \App\OrderItem($item);
             $item->food()->associate($food);
             $item->order()->associate($order);
             $item->save();
         }
     }
     return $order->load('items.food');
 }
Ejemplo n.º 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $timestamp = date('Y-m-d G:i:s');
     $foods = [['name' => 'Rezanci Sicilijana', 'price' => '860', 'type' => 'meal', 'fats' => '500', 'proteins' => '', 'carbs' => '', 'eta' => '15', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Rižota z bučkami in gamberi', 'price' => '1080', 'type' => 'meal', 'fats' => '600', 'proteins' => '', 'carbs' => '', 'eta' => '15', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Ajdovi njoki z jurčki in tartufi', 'price' => '1380', 'type' => 'meal', 'fats' => '600', 'proteins' => '', 'carbs' => '', 'eta' => '15', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Espresso', 'price' => '140', 'type' => 'drink', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Zeleni čaj', 'price' => '180', 'type' => 'drink', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Tiramisu', 'price' => '480', 'type' => 'dessert', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Čokoladni souffle', 'price' => '650', 'type' => 'dessert', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp]];
     \App\Food::insert($foods);
     $tables = [['number' => '1', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '3', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '4', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '5', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '6', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '7', 'created_at' => $timestamp, 'updated_at' => $timestamp]];
     \App\Table::insert($tables);
 }
Ejemplo n.º 4
0
 public function scopeRestrictedBy($query, $restrictions)
 {
     if (!static::$respectRestrictions || count($restrictions) == 0) {
         return $query;
     } else {
         $restrictionIDs = $restrictions->lists('id')->toArray();
         return $query->whereNotIn('id', Food::whereIn('id', DB::table('food_restriction')->whereIn('restriction_id', $restrictionIDs)->lists('food_id'))->lists('id')->toArray());
     }
 }
Ejemplo n.º 5
0
 public function getFoodById($id, $secret = null)
 {
     if ($secret == '12345') {
         $foods = Food::find($id);
     } else {
         $foods = 'nope';
     }
     return response()->json($foods);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $seafoods = ['fish', 'anchovy', 'basa', 'bass', 'cod', 'bream', 'brill', 'eel', 'herring', 'pike', 'pollock', 'salmon', 'sardine', 'shark', 'snapper', 'tilapia', 'trout', 'tuna', 'whiting', 'caviar', 'crab', 'lobster', 'shrimp', 'mollusc', 'conch', 'mussel', 'octopus', 'oyster', 'scallop', 'squid', 'sea'];
     $seaFoodsArray = array();
     //Retrieve all foods with nut in the name. Super rudimentary way to filter, but this will just show that the API works.
     foreach ($seafoods as $seafood) {
         $seaFoodsArray = array_merge($seaFoodsArray, \App\Food::GetNameSimilarTo($seafood)->lists('id')->toArray());
     }
     $seaFoodsArray = array_unique($seaFoodsArray);
     $restriction = App\Restriction::find(2);
     $restriction->restrictedFoods()->attach($seaFoodsArray);
 }
 /**
  * Directs you to either the initial search page or to the search results page depending on get parameters
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $method = $request->get('method');
     $sort = $request->get('sort');
     $query = $request->get('q');
     $useRestrictions = $request->get('restrictions');
     if ($useRestrictions == null) {
         $useRestrictions = 1;
     }
     if ($query == null) {
         return view('food.index')->with(compact('method', 'query', 'useRestrictions', 'sort'));
     } else {
         $foods = null;
         $restrictions = [];
         if ($useRestrictions == 0) {
             Food::ObeyRestrictions(false);
         } else {
             if (Auth::check()) {
                 $user = Auth::user();
                 $restrictions = $user->getRestrictions();
             }
         }
         if ($method == 'similar') {
             $foods = Food::getNameSimilarTo($query, $restrictions);
         } else {
             if ($method == 'search') {
                 $foods = Food::SearchByName($query, $restrictions);
             } else {
                 if ($method == 'name') {
                     $foods = Food::GetByName($query, $restrictions);
                 } else {
                     $foods = Food::SearchByName($query, $restrictions);
                 }
             }
         }
         if ($sort == 'cal') {
             $foods = $foods->sortBy('calories');
         } else {
             if ($sort == 'sugar') {
                 $foods = $foods->sortBy(function ($food) {
                     return $food->getSugar();
                 });
             } else {
                 if ($sort == 'fat') {
                     $foods = $foods->sortBy(function ($food) {
                         return $food->getFat();
                     });
                 }
             }
         }
         return view('food.searchresults')->with(compact('foods', 'method', 'query', 'useRestrictions', 'sort'));
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $dairys = ['milk', 'dairy', 'yogurt', 'butter', 'cheese', 'casein', 'clabber', 'gelato', 'cream', 'custard', 'brick', 'brie', 'camembert', 'cheddar', 'chesire', 'colby', 'coldpack', 'edam', 'feta'];
     $dairysArray = array();
     //Retrieve all foods with nut in the name. Super rudimentary way to filter, but this will just show that the API works.
     foreach ($dairys as $dairy) {
         $dairysArray = array_merge($dairysArray, \App\Food::GetNameSimilarTo($dairy)->lists('id')->toArray());
     }
     $dairysArray = array_unique($dairysArray);
     $restriction = App\Restriction::find(3);
     $restriction->restrictedFoods()->attach($dairysArray);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $nuts = ['acorn', 'cashew', 'pecan', 'nut', 'almond', 'pistachio'];
     $nutFoodsArray = array();
     //Retrieve all foods with nut in the name. Super rudimentary way to filter, but this will just show that the API works.
     foreach ($nuts as $nut) {
         $nutFoodsArray = array_merge($nutFoodsArray, \App\Food::GetNameSimilarTo($nut)->lists('id')->toArray());
     }
     $nutFoodsArray = array_unique($nutFoodsArray);
     $restriction = App\Restriction::find(1);
     $restriction->restrictedFoods()->attach($nutFoodsArray);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $chocolates = ['chocolate', 'cocoa'];
     $chocolatesArray = array();
     //Retrieve all foods with nut in the name. Super rudimentary way to filter, but this will just show that the API works.
     foreach ($chocolates as $chocolate) {
         $chocolatesArray = array_merge($chocolatesArray, \App\Food::GetNameSimilarTo($chocolate)->lists('id')->toArray());
     }
     $chocolatesArray = array_unique($chocolatesArray);
     $restriction = App\Restriction::find(5);
     $restriction->restrictedFoods()->attach($chocolatesArray);
 }
Ejemplo n.º 11
0
 public function createOrder(Request $request)
 {
     Log::info('OrderController.createOrder:');
     $validator = Validator::make($request->all(), ['email' => 'required|email', 'address' => 'required', 'phone' => 'required|size:10', 'delivery_charges' => 'sometimes', 'payment_type' => 'sometimes|in:cod,online', 'items' => 'required']);
     if ($validator->fails()) {
         return response()->json(['response' => 'failure', 'message' => $validator->errors()]);
     }
     $order = Order::create($request->all());
     $order_id = $order->id;
     $total_amount = 0;
     $msg = "";
     if ($request->has('items')) {
         $input = $request->input('items');
         foreach ($input as $i) {
             //Check whether the food item exists
             $food = Food::find($i['food_id']);
             if (!$food || $food->quantity < $i['ordered_quantity']) {
                 $msg .= "Item " . $i['food_id'] . " is not available.";
                 //return response()->json(['response' => 'failure', 'message' => $msg, 'order' => $order]);
             } else {
                 //Add items to the order
                 $i['order_id'] = $order_id;
                 $order_detail = Order_detail::create($i);
                 $total_amount += $food->price * $i['ordered_quantity'];
                 //Update quantity in food table
                 $food->quantity = $food->quantity - $i['ordered_quantity'];
                 $food->save();
             }
         }
     }
     if ($total_amount > 0) {
         $order->item_total = $total_amount;
         $order->status = 'placed';
         $order->save();
         Event::fire(new OrderPlaced($order));
         Log::info('Order placed', ['id' => $order->id]);
         return response()->json(['response' => 'success', 'message' => $msg, 'order' => $order]);
     } else {
         //Delete the order record as none of the items are available
         $order->delete();
         Log::info('Order Deleted as items are not available', ['id' => $order_id]);
         return response()->json(['response' => 'failure', 'message' => $msg]);
     }
 }
 public function addFood()
 {
     if (Auth::check()) {
         $foodid = Request::get('foodid');
         $food = Food::find($foodid);
         if ($food == null) {
             return 'Unprocessable Food.';
         }
         $quantity = Request::get('quantity');
         if ($quantity == null || $quantity == 0) {
             return 'Invalid Quantity.';
         }
         $rating = Request::get('rating');
         $user = Auth::user();
         $user->addToFoodHistory($food, $quantity, $rating);
         return Redirect::route('foodhistory');
     } else {
         return 'Please log in!';
     }
 }
 public function testRestrictions()
 {
     $user = $this->spawnUser();
     $r = App\Restriction::all()[0];
     $user->addRestriction($r);
     $this->assertEquals($user->addRestriction($r), null);
     $this->assertEquals($r->getDisplayName(), "Nut Allergy");
     //Spawns food and detaches + reattaches restriction
     $f = App\Food::GetNameSimilarTo("nuts", [])[0];
     App\Food::ObeyRestrictions($r);
     $this->assertEquals(App\Food::ObeyRestrictions($r), null);
     if ($f->isRestricted($r)) {
         $f->removeRestriction($r);
         $this->assertEquals($f->removeRestriction($r), null);
         $this->assertEquals($f->isRestricted($r), false);
     }
     $f->addRestriction($r);
     $this->assertEquals($user->canEatFood($f), false);
     $this->assertEquals($f->isRestricted($r), true);
     $sample1 = $user->getFoodSuggestion();
     $sample2 = $user->getFoodSuggestion();
     $this->assertNotEquals($sample1, $sample2);
     $this->assertEquals($user->canEatFood($sample1), true);
 }
Ejemplo n.º 14
0
    public function getFoodSuggestion()
    {
        $age = Carbon::Parse($this->bdate)->diffInYears();
        $ageRange = AgeRange::where('min_age', '<=', $age)->where('max_age', '>=', $age)->first();
        $gender = $this->gender == 1 ? 'F' : 'M';
        if ($this->getFoodHistory()->first() == null) {
            $foodSuggestion = \DB::select(\DB::raw('
SELECT 
    foods.*, SUM(fn.amount_in_food / rem_nutr.remaining_val) / (2000 / foods.calories) as score
FROM
    foods
        INNER JOIN
    food_nutrient AS fn ON foods.id = fn.food_id
        INNER JOIN   
    (SELECT 
        users.id, daily_value AS remaining_val, nutrient_id
    FROM
        users
            INNER JOIN 
        recommended_values
    WHERE
        users.id = ' . $this->id . ' 
            AND 
        recommended_values.age_range = ' . $ageRange->id . ' AND recommended_values.sex = \'' . $gender . '\'
    GROUP BY 
        nutrient_id) AS rem_nutr ON rem_nutr.nutrient_id = fn.nutrient_id  
    and foods.id not in 
    (select food_id from food_restriction as fr inner join restriction_user as ru on ru.restriction_id = fr.restriction_id where user_id = ' . $this->id . ')
GROUP BY foods.id order by score DESC, foods.id, fn.nutrient_id;'));
        } else {
            $foodSuggestion = \DB::select(\DB::raw('
SELECT 
    foods.*, SUM(fn.amount_in_food / rem_nutr.remaining_val) / (2000 / foods.calories) as score
FROM
    foods
        INNER JOIN
    food_nutrient AS fn ON foods.id = fn.food_id
        INNER JOIN   
    (SELECT 
        users.id,
            fn.nutrient_id,
            nutr.daily_value - SUM((quantity * amount_in_food / 100)) AS remaining_val
    FROM
        users
            INNER JOIN 
        user_history AS uh ON users.id = uh.user_id
            INNER JOIN 
        food_nutrient AS fn ON fn.food_id = uh.food_id
            INNER JOIN 
        (SELECT nutrient_id, daily_value
         FROM recommended_values
         WHERE age_range = ' . $ageRange->id . ' AND sex = \'' . $gender . '\') AS nutr ON nutr.nutrient_id = fn.nutrient_id
    WHERE
        timestamp > DATE_SUB(NOW(), INTERVAL 24 HOUR)
            AND 
        users.id = ' . $this->id . '
    GROUP BY 
        nutrient_id) AS rem_nutr ON rem_nutr.nutrient_id = fn.nutrient_id  
    and foods.id not in 
    (select food_id from food_restriction as fr inner join restriction_user as ru on ru.restriction_id = fr.restriction_id where user_id = ' . $this->id . ')
GROUP BY foods.id order by score DESC, foods.id, fn.nutrient_id;'));
        }
        $random = rand(0, 200);
        $foodReturn = Food::where('name', $foodSuggestion[$random]->name)->first();
        return $foodReturn;
    }
Ejemplo n.º 15
0
 /**
  * Delete id model and redirect
  *
  * @param type $id current number
  *
  * @return main page
  */
 public function destroy($id)
 {
     $object = Food::find($id);
     $object->delete();
     \Session::flash('flash_message', 'This position has been deleted :(');
     return redirect('food');
 }
Ejemplo n.º 16
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(\App\Menu $menu, \App\Category $category, \App\Food $food)
 {
     if ($food->accessable($menu, $category)) {
         return (string) $food->delete();
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $foods = Food::where('category_id', $id)->get();
     $category = $this->category->find($id);
     return view('foods.category', compact('foods', 'category'));
 }
 public function testFoodCreation()
 {
     $food = Food::GetNameSimilarTo("apple")[0];
     $this->assertEquals("Babyfood, apples, dices, toddler", $food->getName());
     $this->assertEquals("3115", $food->getId());
     // 51 calories
     $this->assertEquals("51", $food->getCalories());
     // 0.0 caffiene
     $this->assertEquals("0.0", $food->getCaffeine());
     $this->assertEquals("mg", $food->getCaffieneUnits());
     // 0.02 mg copper
     $this->assertEquals("0.02", $food->getCopper());
     $this->assertEquals("mg", $food->getCopperUnits());
     // 0.1 g fat
     $this->assertEquals("0.1", $food->getFat());
     $this->assertEquals("g", $food->getFatUnits());
     // 0.9 g fiber
     $this->assertEquals("0.9", $food->getFiber());
     $this->assertEquals("g", $food->getFiberUnits());
     // 0.2 mg iron
     $this->assertEquals("0.2", $food->getIron());
     $this->assertEquals("mg", $food->getIronUnits());
     // 6.0 mg magnesium
     $this->assertEquals("6.0", $food->getMagnesium());
     $this->assertEquals("mg", $food->getMagnesiumUnits());
     // 13.0 mg phosphorus
     $this->assertEquals("13.0", $food->getPhosphorus());
     $this->assertEquals("mg", $food->getPhosphorusUnits());
     // 0.04 mg manganese
     $this->assertEquals("0.04", $food->getManganese());
     $this->assertEquals("mg", $food->getManganeseUnits());
     // 0 mg potassium
     $this->assertEquals("0", $food->getPotassium());
     $this->assertEquals("mg", $food->getPotassiumUnits());
     // 0 mg sodium
     $this->assertEquals("0", $food->getSodium());
     $this->assertEquals("mg", $food->getSodiumUnits());
     // 10.0 calcium
     $this->assertEquals("10.0", $food->getCalcium());
     // Calcium unit: mg
     $this->assertEquals("mg", $food->getCalciumUnits());
     // 12.1 carbohydrates
     $this->assertEquals("12.1", $food->getCarbohydrates());
     // Carbohydrates units: g
     $this->assertEquals("g", $food->getCarbohydratesUnits());
     // 0.2g protein
     $this->assertEquals("0.2", $food->getProtein());
     $this->assertEquals("g", $food->getProteinUnits());
     // 10.83g sugar
     $this->assertEquals("10.83", $food->getSugar());
     $this->assertEquals("g", $food->getSugarUnits());
     // 2.0 ug vitamin a
     $this->assertEquals("2.0", $food->getVitaminA());
     $this->assertEquals("ug", $food->getVitaminAUnits());
     // 0.0 ug vitamin b12
     $this->assertEquals("0.0", $food->getVitaminB12());
     $this->assertEquals("ug", $food->getVitaminB12Units());
     // 0.05 mg vitamin b6
     $this->assertEquals("0.05", $food->getVitaminB6());
     $this->assertEquals("mg", $food->getVitaminB6Units());
     // 31.3 mg vitamin c
     $this->assertEquals("31.3", $food->getVitaminC());
     $this->assertEquals("mg", $food->getVitaminCUnits());
     // 0.0 ug vitamin d
     $this->assertEquals("0.0", $food->getVitaminD());
     $this->assertEquals("ug", $food->getVitaminDUnits());
     // 0.23 mg vitamin e
     $this->assertEquals("0.23", $food->getVitaminE());
     $this->assertEquals("mg", $food->getVitaminEUnits());
     // 0.6 ug vitamin k
     $this->assertEquals("0.6", $food->getVitaminK());
     $this->assertEquals("ug", $food->getVitaminKUnits());
     // 0.04 mg zinc
     $this->assertEquals("0.04", $food->getZinc());
     $this->assertEquals("mg", $food->getZincUnits());
 }
Ejemplo n.º 19
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Request $request, $id)
 {
     $brand = Brand::where('id', $id)->first();
     $brand_foods = Food::where('brand_id', $id)->get();
     return view('brands.show')->with('brand', $brand)->with('brand_foods', $brand_foods);
 }
Ejemplo n.º 20
0
 /**
  * Return page for updating
  *
  * @param type $id current number
  *
  * @return edit page
  */
 public function edit($id)
 {
     $foods = Food::lists('name', 'id');
     $whale = Whale::find($id);
     return view('whale.edit', compact('whale', 'foods'));
 }
Ejemplo n.º 21
0
 public function getFood($id)
 {
     $food = Food::find($id);
     return response()->json($food);
 }
Ejemplo n.º 22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     $food = Food::find($id);
     if ($food && ($food->user_id == $request->user()->id || $request->user()->is_admin())) {
         $food->delete();
         $data['message'] = 'Food deleted successfully';
     } else {
         $data['errors'] = 'Invalid Operation. You have not sufficient permissions';
     }
     return redirect('/food/index')->with($data);
 }
Ejemplo n.º 23
0
 public function all()
 {
     if (!Auth::check()) {
         // The user is logged in...
         return redirect('auth/login');
     }
     $foods = Food::all();
     return response()->json(array('success' => true, 'data' => $foods));
 }
Ejemplo n.º 24
0
 /**
  * Display basic order page.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function welcomeToGo($id)
 {
     $meals = Food::where('type', 'meal')->get();
     $desserts = Food::where('type', 'dessert')->get();
     $drinks = Food::where('type', 'drink')->get();
     return view('tables.welcomeToGo', ['id' => $id, 'meals' => $meals, 'desserts' => $desserts, 'drinks' => $drinks]);
 }
Ejemplo n.º 25
0
 public function getNextFood($currfood)
 {
     $food = new Food();
     $nextFood = $food->where('id', '>', $currfood->id)->orderBy('id', 'asc')->first();
     if (!$nextFood) {
         $nextFood = $food->where('id', '<', $currfood->id)->orderBy('id', 'asc')->first();
     }
     return $nextFood->toArray();
 }
Ejemplo n.º 26
0
 public function userHome()
 {
     $food = \App\Food::all();
     return view('user')->with('food', $food);
 }