Created
December 9, 2019 10:20
-
-
Save SvenJuergens/e70bdd42d43908ce2ef98a997e55c9d5 to your computer and use it in GitHub Desktop.
Revisions
-
SvenJuergens revised this gist
Dec 9, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,6 +15,6 @@ public function findRandom($limit) ->setMaxResults($limit) ->execute() ->fetchAll(); return records; } -
SvenJuergens created this gist
Dec 9, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ //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 }