Class Reference

Learn about properties and methods of core classes.

KoolReport

KoolReport class stands in the center of model. It helps to construct the data pipeline, store results and render view. You report is derived from this class. The class full name is \koolrepport\KoolReport inherited from general \koolreport\core\Base class.

Protected properties

Name type description defined by
params mixed Contain the params put into report through at class construction KoolReport
dataSources array List of data sources KoolReport
dataStores array List of data stores KoolReport

Public Methods

Name return description defined by
__construct()
__construct(mixed $params)
It may construct with or without $params If there is $params then it will be saved to properties $params for later access.
settings() array Your report will overwrite this method to provide settings of report. KoolReport
dataStore(string $name) DataStore Get data store KoolReport
run() Start run the report. This methods will trigger data source to pull data and pipe them to processes to reach data stores KoolReport
render()
render(string $view)
render(string $view,bool $return)
string This function will render the view of report. If there is no parameters, it will automatically look for {ReportClass}.view.php to render. If there is $view parameter, it will look for {$view}.view.php The $return default is false which mean that content will be echo to browser. If $return is set to true, content will be return by the function. KoolReport
innerView(string $view)
innerView(string $view,array $params)
innerView(string $view,array $params,bool $return)
string Render a view. The function will look for view file {$view}.view.php You may send any $params to the inner view as well. If you want to return view as string instead of rendering html out, you set the $return to true KoolReport
registerEvent(string $eventName,mixed $method) KoolReport

Register an events, currently support "OnBeforeRun", "OnRunEnd","OnBeforeRender", "OnRenderEnd".

The method could be name of method in report class or a anonymous function.

$this->registerEvent("OnBeforeRun","doWork");//You have method doWork() in your report
$this->register("OnBeforeRun",function($params){
    //Do work
})
KoolReport
fireEvent(string $eventName,array $params) Fire an event. The event handlers will be called and run with $params sent. KoolReport
getResourceManager() ResourceManager Return the resource manager object of an report KoolReport
getColorScheme(int $index) array Return the color scheme array KoolReport
publishAssetFolder(string $path) string This function will copy a folder to public asset folder of a report. the $path is the absolute path pointing to the folder. The function then will return the public url to the asset folder that it published. KoolReport

Protected Methods

Name return description defined by
setup() Your report will overwrite this method to define the pipeline of data. This method will be called at the end of class construction. KoolReport
src(string $name) DataSource Return the DataSource object KoolReport

Node

This class has full name \koolreport\core\Node derived from general \koolreport\core\Base This class represent a node of data processing, it is the super class of DataSource,Process and DataStore.

Protected properties

Name type description defined by
streamingSource Node Contain the most recent source that stream data to. Node

Public Methods

Name type description defined by
__construct() Construct the class, initiating sources and destinations. Node
pipe(Node $node) Node Setup the next node to be stream data to. It return the next node object. Node
next(array $data) Pipe data to the next nodes Node
startInput(Node $source) Notify the next nodes that it will start streaming. The $source is the node which stream data to this. Node
input(array $data,Node $source) Recieve input from the source Node
endInput(Node $source) Get notification that the $source's input has been ended
meta() mixed Get the meta data Node
receiveMeta(mixed $metaData,Node $source) Source will call this function when they want to forward metadata Node
isEnd() bool Get true the node send no more data. Node
sendMeta(mixed $metaData) Send the next nodes $metaData Node
previous([int $index=0]) Node Return the previous node the piped to this node. If there are many nodes piping to this node, you can specify the index to get them. Node

Events

Name return description defined by
onStartInput() Get called when source node is prepared to send data Node
onInput($data) Get the data to process. Use next() to forward data to next nodes after processing Node
onInutEnd() Get called when all the sources end input Node
onMetaReceived(mixed $metaData) mixed Get called when source sends meta data, return the changing meta data to next nodes Node

DataSource

DataSource has full classname \koolreport\core\DataSource extended from base class \koolreport\core\Node. DataSource is the base class for all the specific data source connections such as PdoDataSource, ArrayDataSource or CSVDataSource.

Protected properties

Name type description defined by
$params mixed Contain information to start a datasource such as connectionString, username and password DataSource

Public Methods

Name return description defined by
__construct(mixed $params) Init the data source
start() Start pulling data from sources and pipe them to next nodes DataSource
sendMeta(mixed $metaData) Send the next nodes $metaData Node
startInput(Node $source) Send start input notification to next nodes. Since data sources is the first node in pipeline, you should call $this->startInput(null); indicate that it initiate start input by itself. Node
endInput(Node $source) Send end input notification to next nodes. Since data sources is the first node in pipeline, you should call $this->endInput(null); indicate that it initiate end input by itself. Node
next(array $data) Pipe data to the next nodes Node

Events

Name return description defined by
onInit() Get called when the data source object is initiated DataSource

Process

Process has full classname \koolreport\core\Process derived from \koolreport\core\Node and be the base class for many processes.

Protected Properties

Name type description defined by
$params mixed Contain the parameters that user input to the process Process

Public Methods

Name return description defined by
__construct(mixed $params) Init the process.
sendMeta(mixed $metaData) Send the next nodes $metaData Node
next(array $data) Pipe data to the next nodes Node

Events

Name return description defined by
onInit() Get called when the process initiates Process
onStartInput() Get called when source node is prepared to send data Node
onInput($data) Get the data to process. Use next() to forward data to next nodes after processing Node
onInutEnd() Get called when all the sources end input Node
onMetaReceived(mixed $metaData) mixed Get called when source sends meta data, return the changing meta data to next nodes Node

DataStore

DataStore has full classname \koolreport\core\DataStore derived from \koolreport\core\Node. DataStore is auto-created by KoolReport to store data as end result ready to send to view.

Public Methods

Name return description defined by
data() array Return the raw data stored in datastore DataStore
data(array $data) DataStore Set data for datastore DataStore
meta() array Return the meta data DataStore
meta(array $meta) DataStore Set meta data for dataStore. DataStore
countData() number Return number of data rows. DataStore
filter(array $condition) DataStore Return new datastore with data that match the condition.
$this->dataStore('ex')->filter( array('age', '>', 35));

$this->dataStore('ex')->filter("product", "in", array("car","moto"));

$this->dataStore('ex')->filter("product", "contain", "bike");

$this->dataStore('ex')->filter("age", "between", 35, 55);
The filter support following operators:
  • "==" or "=": Equal
  • "===": Stricly Equal
  • "!=": Not Equal
  • "!==": Stricly Not Equal
  • ">": Greater than
  • ">=": Greater or Equal
  • "<": Smaller than
  • "<=": Smaller or Equal
  • "between": Between two values
  • "notBetween": Not between two values
  • "contain": Contain a string
  • "notContain": Not contain a string
  • "in": Value is in an array
  • "notIn": Value is NOT in an array
  • "startWith": Value starts with a specified string
  • "notStartWith": Value NOT start with a specified string
  • "endWith": Value ends with a specified string
  • "notEndWith": Value does not end with a specified string
DataStore
popStart() Reset the pop queue, preparing for pop() function to retrieve row by row from beginning. DataStore
pop() array Return the next data row. DataStore
getPopIndex() number Return the current data index by pop() function DataStore
get(int $index,[string $columnName]) mixed Return row of specific $index. If the columnName is specified then it will return the value of that column. DataStore
top(int $num, [int $offset]) DataStore Return datastore containing top n rows. The offset parameter is optional to set the starting row. DataStore
topByPercent(int $num) DataStore Return datastore containing top n percent rows DataStore
bottom(int $num) DataStore Return datastore containing bottom n rows DataStore
bottomByPercent(int $num) DataStore Return datastore containing bottom n percent rows DataStore
sort(array $sorts) DataStore Sort data
$this->dataStore('ex')->sort(array("name"=>"desc"));
DataStore
min(string $columnName) number Return the min value of the specified column DataStore
max(string $columnName) number Return the max value of the specified column DataStore
sum(string $columnName) number Return the aggregated sum of the specified column DataStore
avg(string $columnName) number Return the aggregated average of the specified column DataStore
requestDataSending() This will trigger the data pipe to transferred data from the source to data store DataStore
getReport() KoolReport Return the report containing this datastore DataStore

ProcessGroup

The idea of ProcessGroup is to group multiple processes into one process so that it is faster for us to process data with single call.

Example


<?php
use \koolreport\processes\Filter;
use \koolreport\processes\Group;
use \koolreport\processes\ProcessGroup;
class MyProcessGroup extends \koolreport\core\ProcessGroup
{
    ...
    public function setup()
    {
        $this->incoming()
        ->pipe(new Filter(array(array("sales",">","1000"))))
        ->pipe(new Group(array("by"=>"customerName","sum"=>"sales")))
        ->pipe($this->outcoming());
    }
}
                

Protected Properties

Name type description defined by
$params Containing the setting parameters Process

Public Methods

Name return description defined by
setup() Setup the flow of internal processes ProcessGroup

Protected Methods

Name return description defined by
incoming() Process Represent the incoming source of data ProcessGroup
outcoming() Process Represent the outcoming node ProcessGroup

Events

Name return description defined by
onInit() Get called when the process group is initiated. Process

Widget

Widget has full classname \koolreport\core\Widget derived from \koolreport\core\Node. It is the super class of all the available widget like Table or Google Charts.

Properties

Name type description defined by
$params mixed Containing the setting parameters for Widget Widget

Static Methods

Name return description defined by
create(array $params,[bool $return]) null/string Create and render widget right away. If the $return is true, the create function will return html instead of rendering out. Widget
html(array $params) string Create and return html of widget. This will be helpful when you need to get html of widget then process it before rendering. Widget

Public Methods

Name return description defined by
getReport() KoolReport Return the report object Widget
getAssetManager() AssetManager Return the asset manager for this widget Widget
registerResources() Register resources with KoolReport Widget
renderResources($return=false) string Render the needed resources for widgets, if $return is true then this function will return resource in string rather than echo to browser Widget
render() Render the view of Widget Widget

Protected Methods

Name return description defined by
template()
template(string $template)
template(string $template,mixed $variables)
template(string $template,mixed $variables, bool $return)
string Load widget template to render, if there is no $template it will look for {WidgetName}.tpl.php. If $template is set then it look for {$template}.tpl.php. The $variables is the array containing variables for the widget view. If the $return is set to true then template() will return content as string instead of rendering. Widget
resourceSettings() array Return a settings for resources in array form.

protected function resourceSettings()
{
    return array(
        "library"=>array("jquery"),
        "folder"=>"clients",
        "js"=>array("mywidget.js"),
        "css"=>array("mywidget.css")
    );
}
                                
*Note: This function is mostly used in creating widget.
Widget

Events

Name return description defined by
onInit() Get called when the Widget is initiated Widget

AssetManager

Widget may contains assets such as javascript or css needed to be rendered with. However in same php applications, KoolReport library may be placed in protected folders which can not be accessed by browser. To solve this problem, AssetManager comes into plays. AssetManager assists to prepare those assets. It can helps to copy the resource of a widget to predefined public assets folder set by KoolReport.

Public Methods

Name return description defined by
__construct(Widget $widget) Construction of asset manager, it take $widget as its parameter AssetManager
getAssetUrl() string Return the aliasing asset url AssetManager
publish(string $assetFolder) Publish a widget asset folder to a public folder set by KoolReport. AssetManager

ResourceManager

ResourceManager is associated with KoolReport object providing the management for resource of the report. It manages and resolves all the resource that added to the views by Widget or others. ResourceManager allows Widget to add .css file, .js file, style or custom script at the beginning of the view or at the end of the view.

Public Methods

Name return description defined by
init() Initiate the resource manager. It helps to clear any resources added before. ResourceManager
addScriptFileOnBegin(string $src, $options=array()) ResourceMananger

Add a script file on the begin of the view. $src specifies the url of js file. $options specifies extra options for the <script> tag.

$report->getResourceManager()->addScriptFileOnBegin("/assets/jquery.js");
ResourceMananger
addScriptFileOnEnd(string $src, $options=array()) ResourceMananger Add a script file at the end of view. ResourceMananger
addScriptOnBegin(string,$script,$options=array()) ResourceMananger

Run a script at the begin of the view.

$report->getResourceManager()->addScriptOnBegin("alert(1)");
ResourceMananger
addScriptOnEnd(string,$script,$options=array()) ResourceMananger Run a script at the end of the view. ResourceMananger
addCssFile(string $href, $options = array()) ResourceMananger

Add a css file to the view.

$report->getResourceManager()->addCssFile("/assets/report.css");
ResourceMananger
addStyle(string $style, $options = array()) ResourceMananger

Add style to view

$report->getResourceManager()->addStyle("a {font-size:12px;}");
ResourceMananger
addLinkTag($options = array()) ResourceMananger Add a custom link tag to the view. ResourceMananger
Data Visualization