Jump to:

23479 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] Finding and filtering multiple related data objects

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2 3
Go to End
Author Topic: 2488 Views
  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: [SOLVED] Finding and filtering multiple related data objects Link to this post

    You're right it doesn't make any difference. I tried your suggestion of using $do->push($record) instead of $do->push(new ArrayData($record)) but no change. I'm definitely sure it's got something to do with find()

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: [SOLVED] Finding and filtering multiple related data objects Link to this post

    I figured out a solution without even using find().

    Final code:

    public function FeaturedVideo() {
          $vid = null;
          if($ClassName = "ProfileHolder" && $cat = $this->urlParams['ID']) {
             $cat = str_replace('-', ' ', $cat);
             $cat = ucwords($cat);
             $ccid = DataObject::get_one("ClientCategory", "Name = '{$cat}'")->ID;
             $profiles = DataObject::get("Profile", "ClientCategoryID = $ccid");
             $videoIDs = array();
             foreach($profiles as $profile => $data) {
                foreach($data->Videos() as $video) {
                   $videoIDs[] = $video->ID;
                }
             }
             $vids = new DataObjectSet();
             foreach($videoIDs as $id) {
                $record = DataObject::get_by_id("Video", $id);
                if($record->Featured = true) {
                   $vids->push($record);
                }
             }
             $vids->sort('LastEdited', 'DESC');
             $vid = $vids->First();
          }
          if($vid) {
             return DataObject::get_by_id("Video", $vid->ID);
          } else
             return DataObject::get_one("Video", "Featured = true");
       }

    2488 Views
Page: 1 2 3
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.