mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
Add category filter for news post
This commit is contained in:
parent
d7578d19a1
commit
91a1c8eefa
2 changed files with 22 additions and 0 deletions
|
@ -125,6 +125,7 @@ class Controller
|
||||||
$router->any('/yt2', 'AcquisitionActions::executeYT2');
|
$router->any('/yt2', 'AcquisitionActions::executeYT2');
|
||||||
$router->get('/verify/{token}', 'AcquisitionActions::executeVerify');
|
$router->get('/verify/{token}', 'AcquisitionActions::executeVerify');
|
||||||
|
|
||||||
|
$router->get('/news/category/{category}', 'ContentActions::executePostCategoryFilter');
|
||||||
|
|
||||||
$router->post('/set-culture', 'i18nActions::setCulture');
|
$router->post('/set-culture', 'i18nActions::setCulture');
|
||||||
|
|
||||||
|
|
|
@ -364,4 +364,25 @@ class ContentActions extends Actions
|
||||||
'posts' => array_slice(Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC), 0, $count)
|
'posts' => array_slice(Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC), 0, $count)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
public static function executePostCategoryFilter(string $category)
|
||||||
|
{
|
||||||
|
Response::enableHttpCache();
|
||||||
|
|
||||||
|
$filter_post = [];
|
||||||
|
|
||||||
|
$posts = array_filter(
|
||||||
|
Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC),
|
||||||
|
function(Post $post) use ($category) {
|
||||||
|
return (($post->getCategory() === $category) && (!$post->getDate() || $post->getDate()->format('U') <= date('U')));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return ['content/news', [
|
||||||
|
'posts' => $posts,
|
||||||
|
View::LAYOUT_PARAMS => [
|
||||||
|
'showRssLink' => true
|
||||||
|
]
|
||||||
|
]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue