Skip to content

Commit

Permalink
fix for #32
Browse files Browse the repository at this point in the history
  • Loading branch information
svewap committed Jun 18, 2024
1 parent ba7d9d4 commit 1dbcc72
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Classes/Domain/Repository/GlossaryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@

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;
use WapplerSystems\A21glossary\Domain\Model\Glossary;

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);
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 1dbcc72

Please sign in to comment.