From 59fce3b03784df0085d7545367e7764ba23a9b80 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 6 May 2021 15:19:28 +0200 Subject: [PATCH] Migrate sorting of category count Define further sorting to keep expected order. Sort by multiple fields, first by count, then by title. --- .../Frontend/DataProcessing/CategoriesCounts.php | 15 ++++++--------- Configuration/TypoScript/Setup/Page.typoscript | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Classes/Frontend/DataProcessing/CategoriesCounts.php b/Classes/Frontend/DataProcessing/CategoriesCounts.php index d4ec288..0bffcce 100644 --- a/Classes/Frontend/DataProcessing/CategoriesCounts.php +++ b/Classes/Frontend/DataProcessing/CategoriesCounts.php @@ -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(); diff --git a/Configuration/TypoScript/Setup/Page.typoscript b/Configuration/TypoScript/Setup/Page.typoscript index b86fe78..fc79443 100644 --- a/Configuration/TypoScript/Setup/Page.typoscript +++ b/Configuration/TypoScript/Setup/Page.typoscript @@ -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 }