/** * Show home page * GET / */ public function getIndex() { $perPage = Config::get('site.snippetsPerPage'); $snippets = $this->snippet->byPage($perPage); $topSnippetContributors = $this->user->getTopSnippetContributors(); $mostViewedSnippets = $this->snippet->getMostViewed(10); $tags = $this->tag->all(); return View::make('website.pages.index', compact('snippets', 'topSnippetContributors', 'mostViewedSnippets', 'tags')); }
/** * Unstars a snippet * GET /snippets/{slug}/unstar */ public function unstarSnippet($slug) { $snippet = $this->snippet->bySlug($slug); $user = Auth::user(); if (empty($user)) { return Redirect::route('snippet.getShow', array($slug))->with('message', sprintf('Only logged in users can unstar snippets. Please %s or %s.', link_to_route('auth.getLogin', 'login'), link_to_route('auth.getSignup', 'signup'))); } $user->unStarSnippet($snippet->id); return Redirect::route('snippet.getShow', array($slug)); }
/** * Show listing of snippets of a user * GET /profiles/{slug}/snippets */ public function getSnippets($slug) { $page = Input::get('page', 1); // Candidate for config item $perPage = 10; $pagiData = $this->snippet->byAuthor($slug, $page, $perPage); $user = $pagiData->user; $snippets = Paginator::make($pagiData->items, $pagiData->totalItems, $perPage); return View::make('users.snippets', compact('snippets', 'user')); }
/** * Show dashboard with snippets and starred snippets of the current logged-in user * GET /members/dashboard */ public function dashboard() { $page = Input::get('page', 1); // Candidate for config item $perPage = 10; $pagiData = $this->snippet->byAuthor(Auth::user()->slug, $page, $perPage, $all = true); $my_snippets = Paginator::make($pagiData->items, $pagiData->totalItems, $perPage); $user = Auth::user(); $starred_snippets = $user->starred()->with('Snippet')->get(); return View::make('member.users.dashboard', compact('my_snippets', 'starred_snippets')); }
/** * Show home page * GET / */ public function getIndex() { $page = Input::get('page', 1); // Candidate for config item $perPage = 10; $pagiData = $this->snippet->byPage($page, $perPage); $snippets = Paginator::make($pagiData->items, $pagiData->totalItems, $perPage); $topSnippetContributors = $this->user->getTopSnippetContributors(); $mostViewedSnippets = $this->snippet->getMostViewed(10); $tags = $this->tag->all(); return View::make('website.pages.index', compact('snippets', 'topSnippetContributors', 'mostViewedSnippets', 'tags')); }
/** * Show listing of snippets filtered by a tag * GET /tags/{slug} */ public function getShow($slug) { $page = Input::get('page', 1); // Candidate for config item $perPage = 30; $pagiData = $this->snippet->byTag($slug, $page, $perPage); if (!$pagiData->tag) { return App::abort(404); } $tag = $pagiData->tag; $snippets = Paginator::make($pagiData->items, $pagiData->totalItems, $perPage); $tags = $this->tag->all(); $topSnippetContributors = $this->user->getTopSnippetContributors(); return View::make('tags.snippets', compact('snippets', 'tag', 'tags', 'topSnippetContributors')); }
/** * Show the snippet edit form * GET /members/snippets/{slug}/edit */ public function getEdit($slug) { $snippet = $this->snippet->bySlug($slug, $all = true); // validate that the user updating the snippet is the snippet author if (!$snippet->isTheAuthor(Auth::user())) { return App::abort(404); } $tags = $this->tag->all()->lists('name', 'id'); return View::make('member.snippets.edit', compact('snippet', 'tags')); }