[TYPO3-english] Random order on extbase
amadeo Marketing & Design - Paul Garais
garais at amadeo-marketing.de
Mon Jan 14 16:54:09 CET 2013
How about this workaround (but it needs 2 queries for the result):
<?php
class Tx_ExtensionKey_Domain_Repository_AbstractRepository extends Tx_Extbase_Persistence_Repository{
/**
* Get a random object
* @return Tx_Extbase_Persistence_QueryResultInterface|array
*/
public function findRandom() {
$rows = $this->createQuery()->execute()->count();
$row_number = mt_rand(0, max(0, ($rows - 1)));
return $this->createQuery()->setOffset($row_number)->setLimit(1)->execute();
}
}
?>
Am 14.01.2013 17:49, schrieb Sergio:
> Hi Paul,
>
> yes, I know, but it's not possible for now to do in extbase:
>
> $query->setOrderings(array(
> 'RAND()' => Tx_Extbase_Persistence_Query::ORDER_ASCENDING
> ));
>
> :-(
> _______________________________________________
> TYPO3-english mailing list
> TYPO3-english at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english
>
More information about the TYPO3-english
mailing list