diff --git a/modules/Blog/ArticleList/Handlers/ArticleList.php b/modules/Blog/ArticleList/Handlers/ArticleList.php index 0d67a508..555464cf 100644 --- a/modules/Blog/ArticleList/Handlers/ArticleList.php +++ b/modules/Blog/ArticleList/Handlers/ArticleList.php @@ -8,7 +8,10 @@ use App\Http\Requests\Request; use App\Models\Content; use App\Models\User; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Input; use Modules\Blog\Article\Handlers\Article; +use Modules\Categories\Entities\Category; class ArticleList extends Handler { @@ -39,13 +42,60 @@ class ArticleList extends Handler { $articles = Content::where('module_handler', Article::class); + // selected category? + + // selected articles from archive? + $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); + } + + // is given any category? + $categoryUrl = Input::get('category'); + if ($categoryUrl && \Module::get('Categories') + ->enabled() + ) { + $category = Category::where('url', $categoryUrl) + ->first(); + + $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); + } + + // show articles for not-logged users of even for logged onew? if (!Auth::user()) { $articles = $articles->where('status', Content::STATUS_PUBLIC); } else { $articles = $articles->whereIn('status', [Content::STATUS_PUBLIC, Content::STATUS_PROTECTED]); } - $articles = $articles->orderBy('created_at') + // show articles only from specified user + $author = Input::get('author'); + if ($author) { + $user = User::findOrFail($author); + + $articles = $articles->where('user_id', $user->id); + } + + $articles = $articles->orderBy('created_at', 'DESC') ->paginate(20); return Controller::VisitorsView($content->template, ['page' => $content, 'articles' => $articles]);