Skip to content
Snippets Groups Projects
Commit 8f67515e authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Filter for news categories

parent 342f5fac
No related branches found
No related tags found
1 merge request!2Feature be module
......@@ -82,7 +82,7 @@ class BackendController extends ActionController {
// retrieve next site root id
$siteRootId = Utility::getSiteRoot((int) GeneralUtility::_GP('id'));
$categories = Utility::getCategoriesForSiteRoot($siteRootId);
$news = Utility::getAllNewsByCategories($categories);
$news = Utility::getAllNewsByCategories($categories, $filters);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('pageUid', $pageUid);
......
......@@ -131,18 +131,39 @@ class Utility {
}
/**
* Get all news for the given categories (all if filter is empty)
*
* @param array $categories
* @param array $filters
* @return array
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public static function getAllNewsByCategories(array $categories = []) {
public static function getAllNewsByCategories(array $categories = [], array $filters = []) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var NewsRepository $newsRepository */
$newsRepository = $objectManager->get(NewsRepository::class);
// filter by category if set
if (!empty($filters['filters']['categories'])) {
foreach ($categories as $key => $value) {
if (is_array($filters['filters']['categories'])) {
$unset = TRUE;
foreach($filters['filters']['categories'] as $category) {
if ($key == (int) $category) {
$unset = FALSE;
}
}
if ($unset) {
unset($categories[$key]);
}
}
}
}
$categoryIds = [];
foreach($categories as $key => $value) {
foreach ($categories as $key => $value) {
$categoryIds[] = $key;
}
......
......@@ -6,7 +6,7 @@
<f:translate key="backend.filters.category" />
<small><f:translate key="backend.filters.categories.description" /></small>
</label>
<f:form.select class="form-control" multiple="1" size="4" property="categories" options="{categories}" id="filter-category" />
<f:form.select class="form-control" multiple="1" size="4" property="filters.categories" options="{categories}" id="filter-category" />
</div>
</div>
<div class="col-xs-4">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment