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

Custom filter to show only <18yo members


Go to End


2 Posts   3106 Views

Avatar
Ed

Forum Moderator, 7 Posts

13 January 2010 at 3:33pm

Edited: 13/01/2010 3:33pm

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?

Avatar
timwjohn

Community Member, 98 Posts

22 March 2010 at 12:52pm

Edited: 24/03/2010 7:02am

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