Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » randomized Arraylist. (SS3)

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 481 Views
  • dh
    Avatar
    Community Member
    13 Posts

    randomized Arraylist. (SS3) Link to this post

    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;

    }

    481 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.