Exemplo n.º 1
0
 public function index()
 {
     if (Auth::guest()) {
         return view('pages.home');
     }
     //Check to make sure gender and names are populated
     $user = Auth::user();
     $fields = ['first_name' => $user->first_name, 'last_name' => $user->last_name, 'gender' => $user->gender];
     $validation = Validator::make($fields, User::$baseRules);
     if (!$validation->passes()) {
         return redirect('user/name-and-gender');
     }
     //Check to make sure user has choson categories
     if (!$this->categoryAccount->where('user_id', $user->id)->first()) {
         return redirect('user/categories');
     }
     $chosenCategories = $this->categoryAccount->where('user_id', Auth::user()->id)->orderByRaw('RAND()')->get();
     //Get one random task for the "one for the road"
     $oneForTheRoad = array();
     foreach ($chosenCategories as $category) {
         $events = $this->event->where('type', $category->category_id)->orderByRaw('RAND()')->get();
         foreach ($events as $event) {
             if (!$this->eventUser->where('event_id', $event->id)->where('user_id', Auth::user()->id)->first() && !$this->eventUser->where('user_id', Auth::user()->id)->where('created_at', '<=', date('Y-m-d 24:00:00'))->where('created_at', '>=', date('Y-m-d 00:00:00'))->where('complete', 1)->first()) {
                 array_push($oneForTheRoad, ['id' => $event->id, 'name' => $event->name, 'description' => $event->description, 'class' => 'active']);
             } else {
                 array_push($oneForTheRoad, ['id' => '0', 'name' => 'None for today!', 'description' => 'One for the road has completed', 'class' => 'inactive']);
             }
         }
     }
     $category = $this->category;
     return view('pages.dashboard', compact('category', 'chosenCategories', 'oneForTheRoad'));
 }
Exemplo n.º 2
0
 public function addFirstUserCategories(Request $request)
 {
     $user = $this->user->find($request['user_id']);
     $category = $this->category->find($request['category_id']);
     if (!$this->categoryAccount->where('category_id', $category->id)->where('user_id', $user->id)->first()) {
         $this->categoryAccount->create($request->all());
     } else {
         $this->categoryAccount->where('category_id', $category->id)->where('user_id', $user->id)->delete();
     }
     return response()->json(['categories' => $this->categoryAccount->where('user_id', Auth::user()->id)->count()]);
 }