Cube Process
Usage #
Cube process full classname is \koolreport\cube\processes\Cube
When using the Cube
process, you could define the row, column fields and an aggregated one (i.e "sum", "count", etc). For example, in below code, we turn country
data into row, product
to column and we sum the sale.
<?php
use \koolreport\cube\processes\Cube;
class MyReport extends \koolreport\KoolReport
{
...
public function setup()
{
$this->src('sales')
->query("SELECT country,product,sale from tblPurchases")
->pipe(new Cube(array(
"row"=>"country",
"column"=>"product",
"sum"=>"sale"
)))
->pipe($this->dataStore('sales'));
}
}
If you only specify column
, for example:
...
->pipe(new Cube(array(
"column"=>"product",
"sum"=>"sale"
)))
...
the resulted table will have multiple summarized columns and one summarized row like this:
Label | iPhone | Samsung | Total |
---|---|---|---|
Total | 60,000 | 80,000 | 140,000 |
If you only specify row
, for example:
...
->pipe(new Cube(array(
"row"=>"country",
"sum"=>"sale"
)))
...
the resulted table will have multiple summarized rows and one summarized column like this:
Country | Total |
---|---|
U.S | 92,000 |
Canada | 48,000 |
Options #
row #
The "row" property specifies a field whose distinct values are used as the label column for the summarized table. In the above examples, Country
is such a field.
column #
The "column" property specifies a field whose distinct values are used used as columns' name for the summarized table. In the above examples, Product
is such a field.
rows (version >= 2.0.0) #
If you specify multiple fields for rows
property, the resulted table will have multiple label columns ordered by labels from left to right. For example:
->pipe(new Cube(array(
"rows" => "productCategory, productName",
...
)))
Product Category | Product Name | ... |
---|---|---|
Car | Citroen-15CV | ... |
Car | Ford Falcon | ... |
Truck | Ford F-150 | ... |
columns (version >= 2.0.0) #
If you specify multiple fields for columns
property, the resulted table will have multiple data columns like this:
->pipe(new Cube(array(
"columns" => "orderYear, orderMonth",
...
)))
... | orderYear - 2014 | dollar_sales - sum | orderYear - 2015 | dollar_sales - sum | orderMonth - 12 | dollar_sales - sum | orderMonth - 12 | dollar_sales - sum | ... |
---|---|---|---|---|---|
... | 580,000 | 680,000 | 28 | 32 | ... |
... | 730,000 | 850,000 | 45 | 52 | ... |
Aggregated operator #
The Cube process accepts aggregated operators including "sum", "count", "min", "max", "avg" (version >= 1.0.0) and "count percent", "sum percent" (version >= 2.0.0) and "count distinct", "sum distinct", "count not null" (version >= 3.5.0). Each operator can specify exactly one field whose values are aggregated according to the operator into the data of the summarized table.
Summarized table format #
The summarized table of the Cube
process includes rows of distinct values of the "row"/"rows" fields (if defined) and columns whose names are in the format of "
Country | iPhone | Samsung | {{all}} |
---|---|---|---|
U.S | 48,000 | 44,000 | 92,000 |
Canada | 12,000 | 36,000 | 48,000 |
Get started with KoolReport
KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.