REFACTORING: split ArticleList::render into few smaller methods
This commit is contained in:
@@ -32,22 +32,12 @@ class ArticleList extends Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render given module into visitor area.
|
* Filter articles on article list using archive
|
||||||
*
|
*
|
||||||
* @param Content $content DB model from table contents
|
* @param $articles
|
||||||
* @param array $parameters parameters used for modifications/custom settings of given model
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function render(Content $content, $parameters)
|
protected static function archive(&$articles)
|
||||||
{
|
{
|
||||||
$articles = ArticleModel::where('module_handler', Article::class)
|
|
||||||
->with('comments')
|
|
||||||
->with('category');
|
|
||||||
|
|
||||||
// selected category?
|
|
||||||
|
|
||||||
// selected articles from archive?
|
|
||||||
$year = Input::get('y');
|
$year = Input::get('y');
|
||||||
$month = Input::get('m');
|
$month = Input::get('m');
|
||||||
$day = Input::get('d');
|
$day = Input::get('d');
|
||||||
@@ -63,12 +53,23 @@ class ArticleList extends Handler
|
|||||||
if ($day) {
|
if ($day) {
|
||||||
$articles = $articles->where(DB::raw('DAY(created_at)'), $day);
|
$articles = $articles->where(DB::raw('DAY(created_at)'), $day);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// is given any category?
|
/**
|
||||||
|
* Filter article list to some specified category
|
||||||
|
*
|
||||||
|
* Category URL is specified as GET attribute "category"
|
||||||
|
*
|
||||||
|
* @param $articles
|
||||||
|
*/
|
||||||
|
protected static function category(&$articles)
|
||||||
|
{
|
||||||
$categoryUrl = Input::get('category');
|
$categoryUrl = Input::get('category');
|
||||||
if ($categoryUrl && \Module::get('Categories')
|
|
||||||
->enabled()
|
$categoriesEnabled = \Module::get('Categories')
|
||||||
) {
|
->enabled();
|
||||||
|
|
||||||
|
if ($categoryUrl && $categoriesEnabled) {
|
||||||
$category = Category::where('url', $categoryUrl)
|
$category = Category::where('url', $categoryUrl)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
@@ -82,6 +83,22 @@ class ArticleList extends Handler
|
|||||||
|
|
||||||
$articles = $articles->whereIn('category_id', $categories);
|
$articles = $articles->whereIn('category_id', $categories);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render given module into visitor area.
|
||||||
|
*
|
||||||
|
* @param Content $content DB model from table contents
|
||||||
|
* @param array $parameters parameters used for modifications/custom settings of given model
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function render(Content $content, $parameters)
|
||||||
|
{
|
||||||
|
$articles = ArticleModel::where('module_handler', Article::class)
|
||||||
|
->with('comments')
|
||||||
|
->with('category')
|
||||||
|
->orderBy('published_from', 'DESC');
|
||||||
|
|
||||||
// show articles for not-logged users of even for logged onew?
|
// show articles for not-logged users of even for logged onew?
|
||||||
if (!Auth::user()) {
|
if (!Auth::user()) {
|
||||||
@@ -90,6 +107,12 @@ class ArticleList extends Handler
|
|||||||
$articles = $articles->whereIn('status', [Content::STATUS_PUBLIC, Content::STATUS_PROTECTED]);
|
$articles = $articles->whereIn('status', [Content::STATUS_PUBLIC, Content::STATUS_PROTECTED]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selected articles from archive?
|
||||||
|
self::archive($articles);
|
||||||
|
|
||||||
|
// is given any category?
|
||||||
|
self::category($articles);
|
||||||
|
|
||||||
// show articles only from specified user
|
// show articles only from specified user
|
||||||
$author = Input::get('author');
|
$author = Input::get('author');
|
||||||
if ($author) {
|
if ($author) {
|
||||||
@@ -98,8 +121,7 @@ class ArticleList extends Handler
|
|||||||
$articles = $articles->where('user_id', $user->id);
|
$articles = $articles->where('user_id', $user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$articles = $articles->orderBy('created_at', 'DESC')
|
$articles = $articles->paginate(20);
|
||||||
->paginate(20);
|
|
||||||
|
|
||||||
// decode module settings
|
// decode module settings
|
||||||
foreach ($articles as $article) {
|
foreach ($articles as $article) {
|
||||||
|
|||||||
Reference in New Issue
Block a user