示例#1
0
 /**
  * Handle the event.
  *
  * @param  Events  $event
  * @return void
  */
 public function handle(AdminSentCateringEmail $event)
 {
     // dd($event);
     $email = $event->email;
     $data = Menu::getCateringEmailData($event->week);
     \Mail::send('emails.catering-order', ['data' => $data], function ($m) use($email, $data) {
         $m->to($email)->subject('Narudzbina za ' . $data->keys()->first() . ' - ' . $data->keys()->last());
     });
 }
示例#2
0
 public static function getCateringEmailData($week)
 {
     $users = \Hungry\Models\User::get();
     $allEatenFoodWeek = $users->map(function ($user) use($week) {
         return $user->eatenFoodForWeek($week);
     })->collapse();
     $allEatenFoodWeek = $allEatenFoodWeek->sortBy(function ($menuFood) {
         return $menuFood['menu']['date'];
     });
     $menuFoodsByDate = $allEatenFoodWeek->groupBy(function ($menuFood) {
         if (isset($menuFood->menu)) {
             return $menuFood->menu->date->format('d.m.Y');
         } else {
             return Menu::find($menuFood['menu']['id'])->date->format('d.m.Y');
         }
     });
     // Group by food name
     $menuFoodsByDate = $menuFoodsByDate->map(function ($menuFoods) {
         return $menuFoods->groupBy(function ($mf) {
             if (isset($mf->food)) {
                 return $mf->food->description;
             } else {
                 return $mf['food']['description'];
             }
         });
     });
     // Calculate counts for each food
     $menuFoodsByDate = $menuFoodsByDate->map(function ($differentMenuFoods) {
         return $differentMenuFoods->map(function ($menuFoods) {
             return $menuFoods->count();
         })->sortByDesc(function ($count) {
             return $count;
         });
     });
     // dd($menuFoodsByDate);
     return $menuFoodsByDate;
 }
示例#3
0
 /**
  * @Delete("/food/{id}")
  * @Middleware("admin")
  *
  * Admin removes menuFood from the menu.
  *
  * @param  $id - id of the MenuFood to remove
  */
 public function removeMenuFood($id)
 {
     $menuFood = MenuFood::findOrFail($id);
     $week = $menuFood->menu->week;
     $menuFood->delete();
     $menus = Menu::with(['menuFoods', 'menuFoods.menu', 'menuFoods.food'])->where('week', $week)->get();
     return $menus;
 }
 /**
  * @Get("/get-catering-email")
  * @Middleware("admin")
  * 
  * Returns the html email to be sent to catering 
  * for the specified week
  */
 public function getCateringEmail()
 {
     $week = \Input::get('week');
     $data = Menu::getCateringEmailData($week);
     $html = \View::make('emails.catering-order', ['data' => $data, 'pretend' => true])->render();
     return $html;
 }