SuperCube process extends the power of Cube process.
It allows users to create aggregated reports in one step
that could take a lot of Cube's and other processes' steps to achieve.
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";
use \koolreport\processes\Limit;
use \koolreport\processes\Sort;
use \koolreport\processes\Map;
use \koolreport\cube\processes\Cube;
use \koolreport\cube\processes\SuperCube;
use \koolreport\core\Utility as Util;
//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
function settings()
{
return array(
"dataSources" => array(
"dollarsales"=>array(
'filePath' => '../../../databases/customer_product_dollarsales2.csv',
'fieldSeparator' => ';',
'class' => "\koolreport\datasources\CSVDataSource"
),
)
);
}
function setup()
{
$node = $this->src('dollarsales')
->pipe(new Map(array(
'{value}' => function($row, $metaData) {
$row['Year'] = $row['orderYear'];
$row['Quarter'] = $row['orderQuarter'];
return array($row);
},
'{meta}' => function($metaData) {
$metaData['columns']['dollar_sales'] = array(
'type' => 'number',
"prefix" => "$",
);
$metaData['columns']['orderQuarter'] = array(
'type' => 'string',
);
return $metaData;
},
)));
//multi row fields
$node->pipe(new SuperCube(array(
"rows" => "productLine, productName",
"sum" => "dollar_sales",
)))
->pipe(new Sort(array(
'{{all}} - {{all}} | dollar_sales - sum' => 'desc',
)))
->pipe(new Limit(array(
5, 0
)))
->pipe($this->dataStore('salesCategoryProduct'));
//multi column fields
$node->pipe(new SuperCube(array(
"columns" => "Year, Quarter",
"sum" => "dollar_sales",
)))
->pipe(new Sort(array(
'orderYear - {{all}} | dollar_sales - sum' => 'desc',
)))
->pipe(new Limit(array(
5, 0
)))
->pipe($this->dataStore('salesYearQuarter'));
//multi aggregated fields
$node->pipe(new SuperCube(array(
"rows" => "customerName",
// "columns" => "Year",
"sum" => "dollar_sales",
"count" => "dollar_sales",
"avg" => "dollar_sales",
'sum percent' => 'dollar_sales',
)))
->pipe(new Sort(array(
'{{all}} - {{all}} | dollar_sales - sum' => 'desc',
)))
->pipe(new Limit(array(
5, 0
)))
->pipe($this->dataStore('salesCustomerYear'));
}
}
<?php
use \koolreport\datagrid\DataTables;
use \koolreport\morris_chart;
use \koolreport\sparklines;
use \koolreport\widgets\google;
use \koolreport\widgets\koolphp\Table;
?>
<div class="report-content">
<div class="text-center">
<h1>Sales SuperCube</h1>
<p class="lead">
Supporing multiple rows, columns and aggregates
</p>
</div>
<p class="lead text-center">Multi row fields (productLine, productName) SuperCube</p>
<?php
Table::create(array(
"dataSource" => $this->dataStore('salesCategoryProduct'),
"options" => array(
"searching" => true,
"paging" => true,
"colReorder" => true,
"order" => [],
"pageLength" => 5,
"lengthMenu" => [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]]
),
"showFooter" => true,
));
?>
<p class="lead text-center">Multi column fields (Year, Quarter) SuperCube</p>
<?php
Table::create(array(
"dataSource" => $this->dataStore('salesYearQuarter'),
"options" => array(
"searching" => true,
"paging" => true,
"colReorder" => true,
"order" => [],
"pageLength" => 5,
"lengthMenu" => [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]]
),
"showFooter" => true,
));
?>
<p class="lead text-center">Multi aggregated fields (dollar_sales sum, count, average and sum percent) SuperCube</p>
<?php
Table::create(array(
"dataSource" => $this->dataStore('salesCustomerYear'),
"options" => array(
"searching" => true,
"paging" => true,
"colReorder" => true,
"order" => [],
"pageLength" => 5,
"lengthMenu" => [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]]
),
"showFooter" => true,
));
?>
</div>
customerName | productName | productLine | orderDate | orderDay | orderMonth | orderYear | orderQuarter | dollar_sales |
Vitachrome Inc. |
1937 Lincoln Berline |
Vintage Cars |
2003-01-10 00:00:00 |
10 |
1 |
2003 |
1 |
3726.45 |
Vitachrome Inc. |
1936 Mercedes-Benz 500K Special Roadster |
Vintage Cars |
2003-01-10 00:00:00 |
10 |
1 |
2003 |
1 |
1768.3300000000002 |
Baane Mini Imports |
1952 Alpine Renault 1300 |
Classic Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
5571.8 |
Baane Mini Imports |
1962 LanciaA Delta 16V |
Classic Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
5026.14 |
Baane Mini Imports |
1958 Setra Bus |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
3284.28 |
Baane Mini Imports |
1940 Ford Pickup Truck |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
3307.5 |
Baane Mini Imports |
1926 Ford Fire Engine |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
1283.48 |
Baane Mini Imports |
1913 Ford Model T Speedster |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
2489.13 |
Baane Mini Imports |
1934 Ford V8 Coupe |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
2164.4 |
Baane Mini Imports |
18th Century Vintage Horse Carriage |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
2173 |