public function getIndex() { Auth::getUser()->hasPermissionOr401(Config::get("permissions.playlists"), 0); $view = View::make('home.admin.playlists.index'); $tableData = array(); $pageNo = FormHelpers::getPageNo(); $searchTerm = FormHelpers::getValue("search", "", false, true); // get shared lock on records so that they can't be deleted before query runs to get specific range // (this doesn't prevent new ones getting added but that doesn't really matter too much) $noPlaylists = Playlist::search($searchTerm)->sharedLock()->count(); $noPages = FormHelpers::getNoPages($noPlaylists); if ($pageNo > 0 && FormHelpers::getPageStartIndex() > $noPlaylists - 1) { App::abort(404); return; } $playlists = Playlist::with("show", "mediaItems", "customUri")->search($searchTerm)->usePagination()->orderBy("name", "asc")->orderBy("description", "asc")->orderBy("created_at", "desc")->sharedLock()->get(); foreach ($playlists as $a) { $enabled = (bool) $a->enabled; $enabledStr = $enabled ? "Yes" : "No"; $noPlaylistItems = $a->mediaItems->count(); $show = $a->show; $showStr = !is_null($show) ? $show->name . " (" . $a->series_no . ")" : "[Not Part Of Show]"; $customUri = $a->custom_uri_name; $viewUri = null; if ($a->getIsAccessibleToPublic()) { $viewUri = $a->getUri(); } $tableData[] = array("enabled" => $enabledStr, "enabledCss" => $enabled ? "text-success" : "text-danger", "name" => !is_null($a->name) ? $a->name : "[No Name]", "description" => !is_null($a->description) ? $a->description : "[No Description]", "show" => $showStr, "noPlaylistItems" => $noPlaylistItems, "customUri" => !is_null($customUri) ? $customUri : "[No Custom URI]", "timeCreated" => $a->created_at->toDateTimeString(), "viewUri" => $viewUri, "editUri" => Config::get("custom.admin_base_url") . "/playlists/edit/" . $a->id, "id" => $a->id); } $view->tableData = $tableData; $view->editEnabled = Auth::getUser()->hasPermission(Config::get("permissions.playlists"), 1); $view->pageNo = $pageNo; $view->noPages = $noPages; $view->createUri = Config::get("custom.admin_base_url") . "/playlists/edit"; $view->deleteUri = Config::get("custom.admin_base_url") . "/playlists/delete"; $this->setContent($view, "playlists", "playlists"); }