First things first

Initiate params binding #

To start using the inputs packages, you need to add the followings to your report:

<?php

class MyReport extends \koolreport\KoolReport
{
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;

    ...
}

The \koolreport\inputs\Bindable will help to set up default parameter's values and bind the them to the inputs that we later use in the view of report.

The \koolreport\inputs\POSTBinding will help to update report's parameter from $_POST. If you are using GET method, you will change to \koolreport\inputs\GETBinding.

Setup default values #

The default values of params are important for the first load of report.

<?php

class MyReport extends \koolreport\KoolReport
{
    ...
    protected function defaultParamValues()
    {
        return array(
            "dateRange"=>array('2017-07-01','2017-07-31'),
            "customer"=>"John Lennon",
        );
    }
    ...
}

As you can see in above example, we have two params in our report which are dateRange and customer. The values on the right are default values.

Binding parameters with inputs #

Now let say in the view of report, you have some input controls and you want to bind its value to the params of report. You will add the function bindParamsToInputs() to your report

<?php

class MyReport extends \koolreport\KoolReport
{
    ...
    protected function bindParamsToInputs()
    {
        return array(
            "dateRange"=>"dateRangeInput",
            "customer"=>"customerInput",
        );
    }
    ...
}

The function bindParamsToInputs() will return an associate array with key is the name of params and value is the name of input controls. In above example we bind dateRangeInput to parameter dateRange and customerInput to parameter customer.

If the parameter's name and input's name are the same. You can write short hand like this:

<?php

class MyReport extends \koolreport\KoolReport
{
    ...
    protected function bindParamsToInputs()
    {
        return array(
            "dateRange", // The param's name and input's name are both `dateRange`
            "customer" // The param's name and input's name are both `customer`
        );
    }
    ...
}

Put things together #

What you need to setup parameter binding in your reports:

<?php

class MyReport extends \koolreport\KoolReport
{

    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;    

    protected function defaultParamValues()
    {
        return array(
            "dateRange"=>array('2017-07-01','2017-07-31'),
            "customer"=>"John Lennon",
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "dateRange"=>"dateRangeInput",
            "customer"=>"customerInput",
        );
    }
    ...
}

Input Controls #

Now we move to setup the input controls in the view of report. All the input controls put into the view must have an unique name. This is important because it helps report knows which controls to bind params to.

All the input controls should be put inside a

<form method="post">
    <?php TextBox::create(array("name"=>"customer")) ?>
    ...
</form>

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.