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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

randomized Arraylist. (SS3)


Reply


591 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;

}