Skip to content

Instantly share code, notes, and snippets.

@SvenJuergens
Created December 9, 2019 10:20
Show Gist options
  • Select an option

  • Save SvenJuergens/e70bdd42d43908ce2ef98a997e55c9d5 to your computer and use it in GitHub Desktop.

Select an option

Save SvenJuergens/e70bdd42d43908ce2ef98a997e55c9d5 to your computer and use it in GitHub Desktop.

Revisions

  1. SvenJuergens revised this gist Dec 9, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion TYPO3 Order by Random im Repository
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,6 @@ public function findRandom($limit)
    ->setMaxResults($limit)
    ->execute()
    ->fetchAll();
    return records
    return records;
    }

  2. SvenJuergens created this gist Dec 9, 2019.
    20 changes: 20 additions & 0 deletions TYPO3 Order by Random im Repository
    Original 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
    }