The example demonstrates usage of AggregatedColumn
process. This process creates new column and fill in the aggregated value of an existed column. In above example, we generated 4 new columns total_cost, avg_cost, min_cost, max_cost.
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";
use \koolreport\processes\ColumnMeta;
use \koolreport\processes\AggregatedColumn;
//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
protected function settings()
{
return array(
"dataSources"=>array(
"data"=>array(
"class"=>'\koolreport\datasources\ArrayDataSource',
"dataFormat"=>"table",
"data"=>array(
array("item","cost"),
array("Machines",50000),
array("Human Resource",60000),
array("Materials",100000),
array("Others",80000),
)
)
)
);
}
protected function setup()
{
//Prepare data
$this->src("data")
->pipe(new ColumnMeta(array(
"cost"=>array(
"type"=>"number",
"prefix"=>"$"
)
)))
->saveTo($source);
//Save orginal data
$source->pipe($this->dataStore("origin"));
//Pipe through process to get result
$source->pipe(new AggregatedColumn(array(
"total_cost"=>array("sum","cost"),
"average_cost"=>array("avg","cost"),
"min_cost"=>array("min","cost"),
"max_cost"=>array("max","cost"),
)))
->pipe(new ColumnMeta(array(
"total_cost"=>array(
"type"=>"number",
"prefix"=>'$'
),
"average_cost"=>array(
"type"=>"number",
"prefix"=>'$'
),
"min_cost"=>array(
"type"=>"number",
"prefix"=>'$'
),
"max_cost"=>array(
"type"=>"number",
"prefix"=>'$'
),
)))
->pipe($this->dataStore("result"));
}
}
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
<div class="text-center">
<h1>AggregatedColumn Process</h1>
<p class="lead">This example shows the usage of AggregatedColumn process</p>
</div>
<?php
Table::create(array(
"dataSource"=>$this->dataStore("origin"),
"cssClass"=>array(
"table"=>"table-bordered table-striped table-hover"
)
));
?>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new AggregatedColumn(array(
"total_cost"=>array("sum","cost"),
"average_cost"=>array("avg","cost"),
"min_cost"=>array("min","cost"),
"max_cost"=>array("max","cost"),
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<div style="margin-top:20px;">
<?php
Table::create(array(
"dataSource"=>$this->dataStore("result"),
"cssClass"=>array(
"table"=>"table-bordered table-striped table-hover"
)
));
?>
</div>
</div>