Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Custom filter to show only <18yo members

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: 1571 Views
  • Ed
    Avatar
    Community Member
    5 Posts

    Custom filter to show only <18yo members Link to this post

    Event hasMany Registration hasOne Member

          // Registrations
          $regTablefield = new DataObjectManager(
             $this,
             'Registration',
             'Registration',
             array(
                'Member.Nickname' => 'Username',
                'Member.FirstName' => 'First Name',
                'Member.Surname' => 'Surname',
                'Member.DateOfBirth' => 'DOB',
                'Paid' => 'Paid'
             ),
             null,
             "`EventID` = '$this->ID'"
          );
          $regTablefield->setAddTitle( 'Attendee' );
          $fields->addFieldToTab( 'Root.Content.Registrations', $regTablefield );

    DataObjectManager supports drop-down custom filters, but as far as I can tell this will simply filter exact matches. What I'd like to be able to do is have a filter for example that will list all Registrations in which the Member will be less than 18 at the time of the event (using Member.DateOfBirth and Event.StartDate).

    Is this possible using DataObjectManager?

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Custom filter to show only <18yo members Link to this post

    You can use DataObject::get() to retrieve a set of filtered results then use toDropDownMap().

          $product_dom->setFilter(
             'Category',
             'Filter by category',
             DataObject::get(...params...)->toDropDownMap('Name', 'Name')
          );

    Edit: Some good advice from UC: Check get() returns something first rather than blindly passing the results to toDropDownTable() or there could be fatal consequences (for your CMS, not you).

    1571 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.