FEATURE: add article list -- advanced options
This commit is contained in:
@@ -8,7 +8,10 @@ use App\Http\Requests\Request;
|
|||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Input;
|
||||||
use Modules\Blog\Article\Handlers\Article;
|
use Modules\Blog\Article\Handlers\Article;
|
||||||
|
use Modules\Categories\Entities\Category;
|
||||||
|
|
||||||
class ArticleList extends Handler
|
class ArticleList extends Handler
|
||||||
{
|
{
|
||||||
@@ -39,13 +42,60 @@ class ArticleList extends Handler
|
|||||||
{
|
{
|
||||||
$articles = Content::where('module_handler', Article::class);
|
$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()) {
|
if (!Auth::user()) {
|
||||||
$articles = $articles->where('status', Content::STATUS_PUBLIC);
|
$articles = $articles->where('status', Content::STATUS_PUBLIC);
|
||||||
} else {
|
} else {
|
||||||
$articles = $articles->whereIn('status', [Content::STATUS_PUBLIC, Content::STATUS_PROTECTED]);
|
$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);
|
->paginate(20);
|
||||||
|
|
||||||
return Controller::VisitorsView($content->template, ['page' => $content, 'articles' => $articles]);
|
return Controller::VisitorsView($content->template, ['page' => $content, 'articles' => $articles]);
|
||||||
|
|||||||
Reference in New Issue
Block a user