Add category filter for news post

This commit is contained in:
Maxime St-Pierre 2018-01-29 15:53:50 -05:00
parent d7578d19a1
commit 91a1c8eefa
2 changed files with 22 additions and 0 deletions

View file

@ -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');

View file

@ -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
]
]];
}
} }