ReportDataSource is a special data source which help to get data from another report. Let imagine we create a report that requires data already existed in another report. We want to connect to existed report and get those data rather than spending time to rewrite code. ReportDataSource will help you to do so.
public function settings()
{
require "HardwareSaleReport.php";
return array(
"dataSources"=>array(
"hardwareSaleReport"=>array(
"class"=>"/koolreport/datasources/ReportDataSource",
"report"=>"HardwareSaleReport",
"params"=>array("month"=>1,"year"=>2017)
)
)
);
}
public function setup()
{
$this->src('hardwareSaleReport')
->dataStore('sale') //We want to get data from "sale" data store of HardwareSaleReport
...
->pipe(this->dataStore('sale_of_hardware'));
}
<?php
require_once "SakilaRental2.php";
$report = new SakilaRental2;
$report->run()->render();
<?php
require_once "../../../load.koolreport.php";
class SakilaRental2 extends \koolreport\KoolReport
{
public function settings()
{
require_once "../csv_report/SakilaRental.php";
return array(
"dataSources"=>array(
"sakila_rental"=>array(
"class"=>"/koolreport/datasources/ReportDataSource",
"report"=>"SakilaRental",
)
)
);
}
protected function setup()
{
$this->src('sakila_rental')
->dataStore('sale_by_month') //We want to get data from "sale" data store of HardwareSaleReport
->pipe($this->dataStore('sale_by_month_2'));
}
}
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\ColumnChart;
?>
<div class="report-content">
<div class="text-center">
<h1>ReportDataSource</h1>
<p class="lead">The report shows how to build report from another report data</p>
</div>
<?php
ColumnChart::create(array(
"dataStore"=>$this->dataStore('sale_by_month_2'),
"columns"=>array(
"payment_date"=>array(
"label"=>"Month",
"type"=>"datetime",
"format"=>"Y-n",
"displayFormat"=>"F, Y",
),
"amount"=>array(
"label"=>"Amount",
"type"=>"number",
"prefix"=>"$",
)
),
"width"=>"100%",
));
?>
<?php
Table::create(array(
"dataStore"=>$this->dataStore('sale_by_month_2'),
"columns"=>array(
"payment_date"=>array(
"label"=>"Month",
"type"=>"datetime",
"format"=>"Y-n",
"displayFormat"=>"F, Y",
),
"amount"=>array(
"label"=>"Amount",
"type"=>"number",
"prefix"=>"$",
)
),
"cssClass"=>array(
"table"=>"table table-hover table-bordered"
)
));
?>
</div>