Created
May 9, 2017 18:22
-
-
Save derhansen/7a638cf99f18ca584ac5f67de9e81151 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, that's exactly what I need.
But how can I manage to find the records for the current language?