Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Filter Report using form values

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1512 Views
  • beezer
    Avatar
    Community Member
    16 Posts

    Filter Report using form values Link to this post

    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";
    }

    Attached Files
  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Filter Report using form values Link to this post

    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.

  • beezer
    Avatar
    Community Member
    16 Posts

    Re: Filter Report using form values Link to this post

    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

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