Created
December 9, 2019 10:20
-
-
Save SvenJuergens/e70bdd42d43908ce2ef98a997e55c9d5 to your computer and use it in GitHub Desktop.
TYPO3 Order by Random im Repository
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
| //hier gefunden:https://www.npostnik.de/typo3/typo3-order-by-random-im-repository/ | |
| /** | |
| * @param int $limit | |
| */ | |
| public function findRandom($limit) | |
| { | |
| $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->getTableName()); | |
| $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class)); | |
| $records = $queryBuilder | |
| ->select('*') | |
| ->addSelectLiteral('rand() AS random_sort') | |
| ->from($this->getTableName()) | |
| ->orderBy('random_sort') | |
| ->setMaxResults($limit) | |
| ->execute() | |
| ->fetchAll(); | |
| return records; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment