From 1dbcc7202c5f2f5751d82fc44764f9fd0e93447d Mon Sep 17 00:00:00 2001 From: Sven Wappler Date: Tue, 18 Jun 2024 23:39:43 +0200 Subject: [PATCH] fix for #32 --- .../Domain/Repository/GlossaryRepository.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Classes/Domain/Repository/GlossaryRepository.php b/Classes/Domain/Repository/GlossaryRepository.php index 351ad76..1103809 100644 --- a/Classes/Domain/Repository/GlossaryRepository.php +++ b/Classes/Domain/Repository/GlossaryRepository.php @@ -2,9 +2,9 @@ namespace WapplerSystems\A21glossary\Domain\Repository; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; use TYPO3\CMS\Extbase\Persistence\Generic\Query; -use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser; use TYPO3\CMS\Extbase\Persistence\QueryInterface; use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; use TYPO3\CMS\Extbase\Persistence\Repository; @@ -12,23 +12,25 @@ class GlossaryRepository extends Repository { + public function __construct( + private readonly ConnectionPool $connectionPool, + ) { + parent::__construct(); + } + protected $defaultOrderings = [ 'short' => QueryInterface::ORDER_ASCENDING ]; - /** - * @return string[] - */ public function findAllForIndex() { /** @var Query $query */ $query = $this->createQuery(); - // Get the query parser via object manager to use dependency injection - $parser = $this->objectManager->get(Typo3DbQueryParser::class); - // Convert the extbase query to a query builder - $queryBuilder = $parser->convertQueryToDoctrineQueryBuilder($query); - // Add our select and group by - $queryBuilder->selectLiteral('substr(' . $queryBuilder->quoteIdentifier('short') . ', 1, 1) AS ' . $queryBuilder->quoteIdentifier('char')) + + $queryBuilder = $this->connectionPool + ->getQueryBuilderForTable('tx_a21glossary_main'); + $queryBuilder->from('tx_a21glossary_main') + ->selectLiteral('substr(' . $queryBuilder->quoteIdentifier('short') . ', 1, 1) AS ' . $queryBuilder->quoteIdentifier('char')) ->groupBy('char'); return $query->statement($queryBuilder)->execute(true); @@ -40,7 +42,7 @@ public function findAllForIndex() * @return Glossary[]|QueryResultInterface * @throws InvalidQueryException */ - public function findAllWithChar(string $char) + public function findAllWithChar(string $char): QueryResultInterface|array { $query = $this->createQuery(); $query->matching( @@ -56,7 +58,7 @@ public function findAllWithChar(string $char) * @return Glossary[]|QueryResultInterface * @throws InvalidQueryException */ - public function findAllWithQuery(string $q) + public function findAllWithQuery(string $q): QueryResultInterface|array { $query = $this->createQuery(); $query->matching(