Skip to content

Instantly share code, notes, and snippets.

@derhansen
Created May 9, 2017 18:22
Show Gist options
  • Save derhansen/7a638cf99f18ca584ac5f67de9e81151 to your computer and use it in GitHub Desktop.
Save derhansen/7a638cf99f18ca584ac5f67de9e81151 to your computer and use it in GitHub Desktop.
// The use statements for the fileheader
use MyVendor\MyExtension\Domain\Model\Mymodel;
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;
/**
* Returns all matching records for the given list of uids and applies the uidList sorting for the result
*
* @param string $uidList
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findByUidList($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_myext_domain_model_mymodel');
$rows = $queryBuilder
->select('*')
->from('tx_myext_domain_model_mymodel')
->where($queryBuilder->expr()->in('uid', $uids))
->add('orderBy', 'FIELD(tx_myext_domain_model_mymodel.uid,' . implode(',', $uids) . ')')
->execute()
->fetchAll();
return $dataMapper->map(Mymodel::class, $rows);
}
@stephangrass
Copy link

Hi, that's exactly what I need.
But how can I manage to find the records for the current language?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment