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\processses\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:

LabeliPhoneSamsungTotal
Total60,00080,000140,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:

CountryTotal
U.S92,000
Canada48,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 CategoryProduct Name...
CarCitroen-15CV...
CarFord Falcon...
TruckFord 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 - sumorderYear - 2015 | dollar_sales - sumorderMonth - 12 | dollar_sales - sumorderMonth - 12 | dollar_sales - sum...
...580,000680,0002832...
...730,000850,0004552...

Aggregated operator #

The Cube process accepts aggregated operator including "sum", "count", "min", "max", "avg" (version >= 1.0.0) and "count percent", "sum percent" (version >= 2.0.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 "" or "{{all}}". Beside those columns there are label columns which are the "row"/"rows" fields and ordered by labels from left to right. Here's an example:

CountryiPhoneSamsung{{all}}
U.S48,00044,00092,000
Canada12,00036,00048,000