Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

randomized Arraylist. (SS3)


Go to End


1760 Views

Avatar
dh

Community Member, 13 Posts

13 December 2012 at 10:54pm

Hi, how can i randomize a ArrayList? This is my Code:

public function ImpressionsInRandomOrder($__count = 15) {

$homepagePercent = 0.8;

$homepageCount = (int) round($__count * $homepagePercent);
$currentCount = $__count - $homepageCount;

$_home = ImpressionObject::get()->filter(array('PageID' => '1'))->sort('RAND()')->limit($homepageCount);
$_current = ImpressionObject::get()->filter(array('PageID' => $this->ID))->sort('RAND()')->limit($currentCount);

$_merge = new ArrayList();
$_merge->merge($_home);
$_merge->merge($_current);
$_merge->sort('RAND()'); <-- this don't go

return $_merge;

}