Hi Aaron,
thanks :-)
I didn't have to modify the results() method. The only thing I did was:
public function getCustomSearchContext()
{
$fields = $this->scaffoldSearchFields( array(
'restrictFields' => array(
'Title',
'Content',
'Instrument',
'Plz',
'Location',
'Ambition',
'ExpiryDate',
'EntryCategoryID',
),
'fieldClasses' => array(
'ExpiryDate' => 'HiddenField',
)
)
);
$filters = array(
'Title' => new PartialMatchFilter( 'Title' ),
'Content' => new PartialMatchFilter( 'Content' ),
'Instrument' => new ExactMatchFilter( 'Instrument' ),
'Plz' => new PartialMatchFilter( 'Plz' ),
'Location' => new ExactMatchFilter( 'Location' ),
'Ambition' => new ExactMatchFilter( 'Ambition' ),
'ExpiryDate' => new GreaterThanFilter( 'ExpiryDate' ),
'EntryCategoryID' => new ExactMatchFilter( 'EntryCategoryID' ),
);
$expiryDateYesterday = date( "d.m.Y", mktime( 0, 0, 0, date( "m" ), date( "d" )-1, date( "Y" ) ) );
$objExpiryDate = new HiddenField( 'ExpiryDate', 'ExpiryDate', $expiryDateYesterday );
$fields->replaceField( 'ExpiryDate', $objExpiryDate );
return new SearchContext(
$this->class,
$fields,
$filters
);
}
Initially on the controller I do:
public function ActiveEntries()
{
return $this->Entries(
"( ExpiryDate >= DATE( NOW() ) )"
);
}
This gives me a reduced resultset initially. Since the searchContext doesn't work like this, I had to do it ugly with the hidden field within the model where the CustomSearchContext is defined :-(
Edit: It woud be really nice to have some more possibilities like presetting values in a i.e. fieldsPreset = array( 'fieldname' => 'value' ) or something like that. Also the the filters are lacking >= and <=
Plus there needs to be a possibility to restrict the resultset otherwise, too. Like with an addition WHERE statement.
This might be a nice candidate for a changerequest ;-)