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.

General Questions /

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

Member based $searchable_fields


Reply


3 Posts   1151 Views

Avatar
micahsheets

Community Member, 165 Posts

24 June 2009 at 7:26am

I have been told that to make $searchable_fields based on members group or permissions I have to use a public function searchableFields() instead of a static $searchable_fields. However I cannot figure out the syntax.

I need one set of searchable fields for one user group and another set for another user group for the same DataObject.

I figured it would be:

public function searchableFields() {

$member = Member::currentUser();

$searchable_fields = array(
      'BestNotesID',
      'FirstName',
      'Surname',
      'Therapist.FirstName',
      'StudentGroup.Name'
   );

if ($member && $member->inGroups(array('office-staff', 'office-managers'))) {
$searchable_fields[] = 'OfficeLocation';
{

return $searchable_fields;
}

This code throws the error: Fatal error: Class 'B' not found in ....... sapphire/core/model/DataObject.php on line 1632

Avatar
Sam

Administrator, 685 Posts

24 June 2009 at 1:13pm

If you define a searchableFields() method you need to to a bit of pre-processing yourself. Try returning this instead, as an example.

$searchable_fields = array(
'BestNotesID' => array(),
'FirstName' => array('title' => 'First name'),
'Surname' => array(),
'Therapist.FirstName' => array(),
'StudentGroup.Name => array()'
);

Avatar
micahsheets

Community Member, 165 Posts

25 June 2009 at 4:53am

Thanks for the help, I got it working. Now I need to make one of the search fields a dropdown instead of a text field. Is there a way to do this? The dropdown would be populated with the names of DataObjects of a particular class.