/** * Gets an array of all the allowed screens the specified user is able * to access and modify because they're admin * @param User $user * @param array $allowed_departments * @return EloquentCollection */ public function getAllowedScreens($user, $allowed_departments) { // Return all if a suprer user if ($user->is_super_user) { return Screen::all(); } else { // If the screens assigned department matches // one in the users allowed list then display it $screens = collect([]); foreach ($allowed_departments as $department) { $departmentScreens = $department->Screens()->get(); if ($departmentScreens->count() > 0) { $screens = $screens->merge($departmentScreens); } } } return $screens; }
/** * Calls loadPlaylist and getGlobal to pass back any changes to the client * @param int $id * @return \Illuminate\Http\Response */ public function sync($id) { // Load the selected screen $screen = Screen::find($id); if (isset($screen) == false) { return response('Not found', 404); } // Eager load playlists $data = $this->loadPlaylists($screen); $adverts = $this->applySchedule($data->location->playlist->adverts); $data = array('screen' => $screen, 'playlist' => $data->location->playlist, 'adverts' => $adverts, 'global' => $this->getGlobal()); return $data; }