5116 Posts in 1525 Topics by 1118 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1337 Views |
-
Filter Report using form values

26 January 2011 at 10:45pm
Hi,
I need some help filtering the DataObjects returned from a Report. Basically I have a custom query using groupby and COUNT() to display the number of bookings made to individual Service Centrer, and now I would like to be able to filter these results using a start and end date. Have tried to set this up using a Report but if i try to submit the Form using any custom classes I get "Method 'doReport' not found in class 'Form'" and not sure what I could extend do include that function... maybe this would be better in the ModelAdmin but couldn't figure out how to do the groupby and MySQL COUNT there. Any help or pointers would be appreciated!
<?php
class BookingsReport extends SSReport {
protected $title = "Bookings report";
protected $description = "Booking requests submitted by email";function getCMSFields() {
$fields = new FieldSet();
$fields->push(new CalendarDateField('StartDate', 'StartDate'));
$fields->push(new CalendarDateField('EndDate', 'EndDate'));
$fields->push(new FormAction('doReport', 'Run Report'));
$fields->push($this->ReportField);
return $fields;
}function doReport() {
echo "1";
} -
Re: Filter Report using form values

27 January 2011 at 2:08am
Hey,
To add a form for filtering the report items, you don't want to overload getCMSFields - that deals with actually generating the report fields. What you want to do is overload parameterFields to return a FieldSet containing the fields you want to show in the filter form, and then overload sourceRecords to actually apply the filter. Check out the broken links report code for an example of how this is done, but basically you just want to check if a from/to date is set in sourceRecords, and if so use it to filter a DataObject::get() call.
Note that the jquery popup date picker field won't work in the report admin area if you want to use it. I had to create a custom extension which would include the JS requirements, as well as a little but of custom CSS to make it look OK. However, if you're happy with a text field for date input you'll have no problems.
-
Re: Filter Report using form values

27 January 2011 at 11:18pm
Thanks aj, got it now.
Looks like I am stuck with 2.3 for this one though so will stick a few static reports in there and save this for later
| 1337 Views | ||
|
Page:
1
|
Go to Top |


