<?php
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
/**
* The repository for ExampleRepository
*/
class ExampleRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
/**
* Find all results by a list of uids and order by this uid list
*
* @param String $uidList List of uids
* @return array
*/
public function findAllByCommaIdString(String $uidList) {
$uids = GeneralUtility::intExplode(',', $uidList, true);
if ($uidList === '' || count($uids) === 0) {
return [];
}
$dataMapper = GeneralUtility::makeInstance(DataMapper::class);
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_example_domain_model_example');
$rows = $queryBuilder
->select('*')
->from('tx_example_domain_model_example')
->where($queryBuilder->expr()->in('uid', $uids))
->add(
'orderBy',
'FIELD(tx_example_domain_model_example.uid,' . implode(',', $uids) . ')'
)
->execute()
->fetchAll();
return $dataMapper->map(\FooBar\Example\Domain\Model\Example::class, $rows);
}
}