A report collection allows several reports to be aggregated together into one report. Each sub-report is run individually and uses it's own caching system so if the individual reports are run the results are still cached.
Using this report is slightly different to the main reportBase class. Instead of having to implement a _run and isValid() methods, you just need the reportBase::initialise() method and then in this method add the reports that should be aggregated together.
There are a few points to note: aggregated reports require ALL parameters for all sub-reports be set before it can be run. If these are shared, they only need to be set once. It is not possible for aggregate reports to run with separate settings per report.
Report options should be passed to the sub-reports when they are created - the same with the report style. This ensures that the options and style is available when the initialise() method is called on the sub-reports during instantiation.
Finally: only certain output writers support report collections. These are: reportWriterHtml, reportWriterExcel, reportWriterOds and reportWriterPdf. CSV and XML are not supported because the data will not make any sense if it is compiled whereas ODS, Excel (both XLS and XLSX), HTML and PDF allow multiple reports to be presented in a meaningful manner.
An example that combines 3 reports into one, each sub-report should exist already.
class myCustomerReportCollection extends reportCollectionBase {
function initialise() {
$this->addReport(new myNewCustomerReport($this->getOptionsSet()->getOptions(), $this->getReportStyle()));
$this->addReport(new myCustomerPurchasesReport($this->getOptionsSet()->getOptions(), $this->getReportStyle()));
$this->addReport(new myCustomerIssuesReport($this->getOptionsSet()->getOptions(), $this->getReportStyle()));
}
}
// run report & output
$oReport = new myCustomerReportCollection(
array(
reportBase::OPTION_USE_CACHE => true,
reportBase::OPTION_OUTPUT_TYPE => reportManager::OUTPUT_HTML,
)
);
$oReport->run();
$oWriter = $oReport->getReportWriter();
$oWriter->compile();
header("Content-Type: ".$oWriter->getMimeType());
readfile($oWriter->getFullPathToOutputFile());
public isValid()
Returns true if all report options are valid
public run()
Overridden run because we dont need caching in this report
public _run()
Runs all sub-reports with the current options
public getReportDescription()
Returns the report description, should be overridden in child objects
public getSupportedReportWriters()
Returns an array of supported output writers for the collection report
public count()
Returns the number of sub-reports
public getCount()
Alias of count()
public getIterator()
Returns the iterator allowing the object to be iterated in foreach loops
public addReport($inReport)
Adds a report to the collection, injecting options from this report
public getReports()
Returns the reports in this collection
public setReports([$inArray = array()])
Sets an array of reports to the collection
Posted by: Scorpio Documentor (Writer), in Report on 06 Dec 2009 @ 16:06
Tags: countable, iteratoraggregate, report, reportbase, reportcollectionbase, traversable,
This
work is licenced under a
Creative Commons Licence.