Migrate sorting of category count

Define further sorting to keep expected order.
Sort by multiple fields, first by count, then by title.
This commit is contained in:
Daniel Siepmann 2021-05-06 15:19:28 +02:00
parent 5916c93fd9
commit 59fce3b037
2 changed files with 8 additions and 11 deletions

View file

@ -47,19 +47,14 @@ class CategoriesCounts implements DataProcessorInterface
$as = $cObj->stdWrapValue('as', $processorConfiguration, 'categories');
$parent = $cObj->stdWrapValue('parent', $processorConfiguration, '');
$orderBy = $cObj->stdWrapValue('orderBy', $processorConfiguration, 'count desc');
[$orderByField, $orderByDirection] = QueryHelper::parseOrderBy($orderBy)[0];
if ($parent === '') {
throw new \InvalidArgumentException('No "parent" given.', 1600988668);
}
if ($orderByField === null || $orderByDirection === null) {
throw new \Exception('Non correct "orderBy" given. Needs field and "asc" or "desc".', 1600988713);
}
$processedData[$as] = $this->getCategoriesCount(
$parent,
$orderByField,
$orderByDirection
$orderBy
);
return $processedData;
@ -67,8 +62,7 @@ class CategoriesCounts implements DataProcessorInterface
private function getCategoriesCount(
int $parentId,
string $orderByField,
string $orderByDirection
string $orderBy
): array {
$queryBuilder = clone $this->queryBuilder;
@ -94,7 +88,10 @@ class CategoriesCounts implements DataProcessorInterface
)
);
$queryBuilder->groupBy('category.uid');
$queryBuilder->orderBy($orderByField, $orderByDirection);
foreach (QueryHelper::parseOrderBy($orderBy) as $orderBy) {
$queryBuilder->addOrderBy($orderBy[0], $orderBy[1]);
}
$statement = $queryBuilder->execute();

View file

@ -84,13 +84,13 @@ page {
100 = DanielSiepmann\DsSite\Frontend\DataProcessing\CategoriesCounts
100 {
as = allTopics
orderBy = count desc
orderBy = count desc, title asc
parent = 1
}
101 < .100
101 {
as = allTypo3Compatible
orderBy = title asc
orderBy = title asc, title asc
parent = 2
}