nyeholt / silverstripe-advancedreports

A reporting module that provides an extra level of configuration and functionality over the base silverstripe structures. Generates static output content in HTML, CSV and PDF formats
BSD 3-Clause "New" or "Revised" License
13 stars 7 forks source link

Fields from HasMany Relationship #1

Closed srmcatee closed 11 years ago

srmcatee commented 13 years ago

Is it in tthe roadmap to add field values from the hasmany or manymany relationship?

nyeholt commented 13 years ago

It's something that would be nice - for the moment, if you're wanting fields from a relationship, you need to create your own AdvancedReport (or DataObjectReport) subclass and manually add in the fields the user can select by

srmcatee commented 13 years ago

Thank you for your assistance.

I've started building my own obeject. Everything looks good but when
I go to run preview on the report I get this error:

error_log(/var/log/silverstripe): failed to open stream: Is a directory error_log([22-Sep-2011 06:28:48] Error at
advancedreports/code/dataobjects/AdvancedReport.php line 359: Uncaught
Exception: Abstract method called; please implement getDataObjects()
(http://localhost/hiho2/admin/advanced-reports/DirectoryReport/14/preview)
,3,/var/log/silverstripe,) Line 57 of LogFileWriter.php

I've modified permissions on /var/log/silverstripe to 777. I've also
chown and chgrp to www-data. Nothing fixes it.

Can you advise what advanced report is trying to do here?

Thank you.

Steve

Quoting nyeholt
reply@reply.github.com:

It's something that would be nice - for the moment, if you're
wanting fields from a relationship, you need to create your own
AdvancedReport (or DataObjectReport) subclass and manually add in
the fields the user can select by

  • Override getReportableFields() to add in the field value the user
    can select
  • Override getDataObjects() to provide your own logic for selecting
    the data objects to include in the report.

Reply to this email directly or view it on GitHub: https://github.com/nyeholt/silverstripe-advancedreports/issues/1#issuecomment-2007253

nyeholt commented 13 years ago

The important bit is

Uncaught Exception: Abstract method called; please implement getDataObjects()

Your report subclass needs to implement this method to return the actual data objects that will be displayed in the report. Check the DataObjectReport class for an example.

srmcatee commented 13 years ago

K. That is fixed.

Now my final issue. I'm trying to include fields from a hasmany table that relates to my primary table.

I modified getReportableFields to reference one of my other tables. In the example code below I have a primary table "Family" and another table "Individual". The relationship that relates them is "Individuals". So here is the code:

protected function getReportableFields() { $fields = array( 'ID' => 'ID', 'Created' => 'Created', 'LastModified' => 'LastModified', ); if ($this->ReportOn) { $dbfields = Object::combined_static($this->ReportOn, 'db'); $addtl=array('Individuals.FirstName'=>'Individuals.FirstName'); $fields=array_merge($fields,$dbfields); $fields=array_merge($fields,$addtl); $fields = array_combine(array_keys($fields), array_keys($fields)); ....

The field is displayed but comes up blank when I generate the report. How do I get the report to pull the selected field value from a hasmany relationship?

}