moduleHandler != ArticleList::class) return; $articles = ArticleModel::where('moduleHandler', Article::class) ->with('comments') ->with('category') ->where(function ($query) { $query->where('publishedFrom', '<', Carbon::now()) ->orWhereNull('publishedFrom'); }) ->where(function ($query) { $query->where('publishedTo', '>', Carbon::now()) ->orWhereNull('publishedTo'); }) ->orderBy('publishedFrom', 'DESC') ->orderBy('created_at', 'DESC'); // show articles for not-logged users of even for logged onew? $articles = !Auth::user() ? $articles->where('status', IContent::STATUS_PUBLIC) : $articles->whereIn('status', [ IContent::STATUS_PUBLIC, IContent::STATUS_PROTECTED ]); // selected articles from archive? $this->archive($articles); // is given any category? $this->category($articles); // show articles only from specified user $author = Input::get('author'); if ($author) { $user = User::findOrFail($author); $articles = $articles->where('user_id', $user->id); } $page->articles = $articles->paginate(setting('articlesPerPage', 20)); } /** * Filter articles on article list using archive * * @param $articles */ protected function archive(&$articles) { $year = Input::get('y'); $month = Input::get('m'); $day = Input::get('d'); if ($year) { $articles = $articles->where(DB::raw('YEAR(created_at)'), $year); } if ($month) { $articles = $articles->where(DB::raw('MONTH(created_at)'), $month); } if ($day) { $articles = $articles->where(DB::raw('DAY(created_at)'), $day); } } /** * Filter article list to some specified category * * Category URL is specified as GET attribute "category" * * @param $articles */ protected function category(&$articles) { $categoryUrl = Input::get('category'); $categoriesEnabled = \Module::get('Categories') ->enabled(); if ($categoryUrl && $categoriesEnabled) { $category = Category::where('url', $categoryUrl) ->firstOrFail(); $subcategories = $category->getChildren() ->toArray(); $categories = [$category->id]; $categories = array_merge($categories, array_map(function ($cat) { return $cat['id']; }, $subcategories)); $articles = $articles->whereIn('category_id', $categories); } } }