/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $user = Session::get('user');
     $allowed_departments = Session::get('allowed_departments');
     $match_departments = Session::get('match_departments');
     // Return all playlists the user is allowed to see
     $playlists = Playlist::whereIn('department_id', $match_departments)->orderBy('name', 'ASC')->get();
     $data = array('playlists' => $playlists, 'allowed_departments' => $allowed_departments, 'user' => $user);
     return view('pages/playlists', $data);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $user = Session::get('user');
     $allowed_departments = Session::get('allowed_departments');
     $match_departments = Session::get('match_departments');
     $playlists = Playlist::whereIn('department_id', $match_departments)->get();
     // Return all locations or only the ones th user is assigned to
     if ($user->is_super_user) {
         $locations = Location::all();
     } else {
         $locations = Location::whereIn('department_id', $match_departments)->get();
     }
     $data = array('locations' => $locations, 'allowed_departments' => $allowed_departments, 'user' => $user, 'playlists' => $playlists);
     return view('pages/locations', $data);
 }
 /**
  * Filter screens by criteria
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function filter(Request $request)
 {
     $match_departments = Session::get('match_departments');
     $allowed_departments = Session::get('allowed_departments');
     $user = Session::get('user');
     // Get inputs from POST
     $btnFindScreen = $request->input('btnFindScreen');
     $btnFindAll = $request->input('btnFindAll');
     $locationID = $request->input('drpLocations');
     //$playlistID = $request->input('drpPlaylists');
     $screenID = $request->input('txtScreenID');
     // Check which action to perform
     if (isset($btnFindScreen)) {
         // Filter by id
         $screens = $this->getAllowedScreens($user, $allowed_departments);
         $filtered = $screens->filter(function ($item) use($screenID) {
             if ($item->id == $screenID) {
                 return true;
             }
         });
         // Filter by location
         if ($filtered->count() == 0) {
             $filtered = $screens->filter(function ($item) use($locationID) {
                 if ($item->location_id == $locationID) {
                     return true;
                 }
             });
         }
         $screens = $filtered;
     } else {
         if (isset($btnFindAll)) {
             $screenID = null;
             $screens = $this->getAllowedScreens($user, $allowed_departments);
         } else {
             abort(401);
         }
     }
     $playlists = Playlist::whereIn('department_id', $match_departments)->get();
     // Pass back so we can re-populate the locations list
     //$locations = Location::whereIn('department_id', $match_departments)->get();
     $data = array('screens' => $screens, 'screenID' => $screenID, 'playlists' => $playlists, 'user' => $user);
     return view('pages/screens', $data);
 }