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.

Customising the CMS

SS_Report and SideReport : how to?


Reply

6 Posts   1909 Views

Avatar
biapar

6 June 2010 at 1:17am Forum Moderator, 435 Posts

I tried to create reports, but I don't see any of them.

class DBReport_AquistatiProducts extends SideReport {
   
   function title() {
      return "Prodotti Acquistati";
   }
   
   function records() {
      return DataObject::get("Product", "Aquistato = 1", "Title");
   }
   
   function fieldsToShow() {
      return array(
         "Title" => array("NestedTitle", array("2")),
      );
   }
}

and under mysite/code/reports

class CurrentOrdersReport extends SSReport {
...
}

Is there a guideline?
Thank you

Avatar
Willr

6 June 2010 at 11:49am Forum Moderator, 5511 Posts

In 2.3 these would appear automatically after doing a ?flush=1. In 2.4 you now have to register the reports you want to include in the cms via this line of code in your _config file.

SS_Report::register("SideReport", "SideReport_NameOfReport");

Avatar
cuSSter

3 September 2010 at 6:04am Community Member, 56 Posts

Hi Wilr,

I have a class that extends the SS_Report. And I have this module that saves the report in a PDF format, its called DOMPDF module. Now, the thing is I want to create a custom template to render the report. Is this possible? If it is indeed possible, how do I go through this?

Thanks in advance!

Avatar
rwestera

11 March 2011 at 12:13pm Community Member, 3 Posts

And again - IS THERE A GUIDELINE?
This seems to be horrendously underdocumented for something taking up a full tab in the CMS.
The only tutorial I can find is http://doc.silverstripe.org/sapphire/en/reference/site-reports and that's completely out of date.

So what needs to be done to add a report for 2.4?
And is it SideReport or SS_Report now?

Avatar
inCharge

15 September 2011 at 4:29am (Last edited: 15 September 2011 4:40am), Community Member, 102 Posts

rwestera, I know I'm replying to a months old post and you've probably switched to Drupal by now, but for anyone else trying to do this...

This seems to be horrendously underdocumented for something taking up a full tab in the CMS.

See http://api.silverstripe.org/2.4/cms/reports/SS_Report.html

If you use the code as documentation, then you have everything you need.

E.g. See cms/code/reports/BrokenLinksReport.php to see how to write a report. Search all php files for 'BrokenLinksReport' to see how it's utilised.

This report allows users to download a csv of all users in the newsletter group:

class UserReport extends SS_Report {

   function title() {
      return 'Users';
   }

   function sourceRecords($params, $sort, $limit) {

      return DataObject::get(
             "Member"
            , "`Group`.`code`='newsletter'"
            , $sort
            , "inner join group_members on member.id = group_members.MemberId inner join `group` on group_members.GroupId = `group`.id"
            , $limit
         );
   }

   function columns() {

      $fields = array(
          'FirstName' => array(
               'title' => 'First name'
            )
         , 'Surname' => array(
               'title' => 'Surname'
            )
         , 'Email' => array(
               'title' => 'Email'
            )
         );

      return $fields;
   }

}

To register a report in the CMS 'Reports' tab...

SS_Report::register('ReportAdmin', 'UserReport', -19);

I guess the number at the end determines the order they are shown in the menu.

I think...

SS_Report::register("SideReport", "SideReport_NameOfReport");


...is for reports that appear on the pages tab under 'Site Reports'.

Avatar
Carbon Crayon

11 October 2011 at 10:44am Community Member, 598 Posts

There is now an up to date tutorial for adding reports here: http://www.ssbits.com/tutorials/2011/adding-custom-filterable-reports-to-reportadmin/

Hope that helps :)

Aram