/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $match_departments = Session::get('match_departments'); $allowed_departments = Session::get('allowed_departments'); $user = Session::get('user'); // Return locations and playlits the user can access $locations = Location::whereIn('department_id', $match_departments)->get(); //$playlists = Playlist::whereIn('department_id', $match_departments)->get(); // Get screens that the user has access to $screens = $this->getAllowedScreens($user, $allowed_departments); $data = array('screens' => $screens, 'locations' => $locations, 'user' => $user); return view('pages/screens', $data); }
/** * Filter locations by criteria * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function filter(Request $request) { $locations = null; // Get all input vars $btnFindLocation = $request->input('btnFindLocation'); $btnFindAll = $request->input('btnFindAll'); $locationName = $request->input('txtLocationName'); $departmentID = $request->input('drpDepartments'); $match_departments = Session::get('match_departments'); $locations = Location::whereIn('department_id', $match_departments)->get(); // Check which action to perform if (isset($btnFindLocation)) { $filtered = collect([]); // Filter by name if ($locationName != null) { $filtered = $locations->filter(function ($item) use($locationName) { if (strpos($item->name, $locationName) !== false) { // Get rough match return true; } }); } // Filter by department id if ($filtered->count() == 0) { $filtered = $locations->filter(function ($item) use($departmentID) { if ($item->department_id == $departmentID) { return true; } }); } $locations = $filtered; } else { if (isset($btnFindAll)) { $locationName = null; } else { abort(401, 'Unauthorized'); } } $user = Session::get('user'); $allowed_departments = Session::get('allowed_departments'); $data = array('locations' => $locations, 'searchItem' => $locationName, 'user' => $user, 'allowed_departments' => $allowed_departments); return view('pages/locations', $data); }