Events

Introduction #

During report life cycle, report will emit certain events. This is extremely useful for debugging, service add-on functioning and event processing.

Two Types of Events #

There are two type of events:

  1. Before: Emit right before something happens and has capability to prevent that thing to happen.
  2. After: Emit right after something happens.

The events which emit before something happens normally has form of "OnBefore{SomethingHappens}" in their names.

Those events which emit after something happens normally has form of "On{SomethingHappens}" in their names.

Register An Event #

Bellow are common form to register events in KoolReport

class MyReport extends \koolreport\KoolReport
{
    ...
    protected function OnBeforeSetup()
    {
        // Happens when report is about to call setup() method

        return true; // To allow setup() to run
    }

    protected function OnSetup()
    {
        //Happens when report has just run setup() method

    }
}

List of Events #

OnBeforeServicesInit #

Emitted before KoolReport's services are initiated. Return true to approve action, return false to disapprove action.

protected function OnBeforeServicesInit()
{
    echo "Services is about to init";
    return true;
}

OnServicesInit #

Emitted after KoolReport's services are initiated.

protected function OnServicesInit()
{
    echo "Services has been initiated";
}

OnInit #

Emitted after KoolReport is init, services are added but have not setup data processing.

protected function OnInit()
{
    echo "Report has been initiated";
}

OnBeforeSetup #

Emitted before setting up the data process tree. Return true to approve action, return false to disapprove action.

protected function OnBeforeSetup()
{
    echo "About to setup data process tree";
    return true;
}

OnSetup #

Emitted after data processing tree is setup

protected function OnSetup()
{
    echo "Data processing tree has been setup";
}

OnInitDone #

Emitted after the initiation phase is completed

protected function OnInitDone()
{
    echo "Report's initiation is completed";
}

OnBeforeRun #

Emitted before report is run. Return true to approve action, return false to disapprove action.

protected function OnBeforeRun()
{
    echo "Report is about to run";
    return true;
}

OnRunEnd #

Emitted after report is run

protected function OnRunEnd()
{
    echo "Report has been run";
}

OnBeforeRender #

Emitted before report is rendered. Return true to approve action, return false to disapprove action.

protected function OnBeforeRender()
{
    echo "Report is about to render";
    return true;
}

OnRenderEnd #

OnBeforeResourceAttached #

Emitted before resource manager attaches resources to report's view. Return true to approve action, return false to disapprove action.

protected function OnBeforeResourceAttached()
{
    echo "Report is about to have resource attached";
    return true;
}

OnResourceAttached #

Emitted after resource manager attaches resources to report's view.

protected function OnResourceAttached()
{
    echo "Report has bad resouces attached";
}

OnResourceInit #

Emitted after resource manager is initiated.

protected function OnResourceInit()
{
    echo "Resource manager is initiated";
}

OnBeforeWidgetInit #

Emitted before any widget is initiated. Return true to approve action, return false to disapprove action.

protected function OnBeforeWidgetInit($widget)
{
    echo "[$widget->name] is about to init";
    return true;
}

OnWidgetInit #

Emitted after widget is initiated

protected function OnWidgetInit($widget)
{
    echo "[$widget->name] was initiated";
}

OnBeforeWidgetRender #

Emitted before any widget is rendered. Return true to approve action, return false to disapprove action.

protected function OnBeforeWidgetInit($widget)
{
    echo "[$widget->name] is about to render";
    return true;
}

OnWidgetRender #

Emitted after widget rendered

protected function OnWidgetRender($widget)
{
    echo "[$widget->name] rendered";
}

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.