Application

Bootstrap #

Application is the main entrant to start KoolReport Dashboard

Bootstrap the application

//index.php

 //Load composer autoload will load koolreport/core/autoload.php
require_once "vendor/autoload.php";

require_once "App.php";

App::create()->run();
// App.php
use \koolreport\dashboard\Application;

class App extends Application
{

}

Adding dashboards #

You need to provide list of dashboards to the dashboards() method like following.

class App extends Application
{
    protected function dashboards()
    {
        return [
            "Home"=>HomeBoard::create(),
            "Sale"=>SaleBoard::create(),
        ];
    }
}

Above example will produce 2 dashboards Home and Sale appearing on the menu of application. Learn how to create a dashboard.

Grouped dashboards #

use \koolreport\dashboard\menu\Group;

class App extends Application
{
    protected function dashboards()
    {
        return [
            "Home"=>HomeBoard::create(),
            "Sale Reports"=>Group::create()->icon("fa fa-line-chart")->sub([
                "Overview"=>SaleOverviewBoard::create(),
                "Main Products"=>MainProductBoard::create(),
            ]),
            "Cost Reports"=>Group::create()->icon("fa fa-pie-chart")->sub([
                "Overview Cost"=>CostOverviewBoard::create(),
                "BreakDown Cost"=>BreakDownCostBoard::create(),
            ])
        ];
    }
}

3rd level of menu #

You can add another layers of menu breakdown which called Section

use \koolreport\dashboard\menu\Section;
use \koolreport\dashboard\menu\Group;

class App extends Application
{
    protected function dashboards()
    {
        return [
            "Home"=>HomeBoard::create(),
            "Sale and Cost"=>Section::create()->sub([
                "Sale Reports"=>Group::create()->icon("fa fa-line-chart")->sub([
                    "Overview"=>SaleOverviewBoard::create(),
                    "Main Products"=>MainProductBoard::create(),
                ]),
                "Cost Reports"=>Group::create()->icon("fa fa-pie-chart")->sub([
                    "Overview Cost"=>CostOverviewBoard::create(),
                    "BreakDown Cost"=>BreakDownCostBoard::create(),
                ])
            ])
        ];
    }
}

Authentication #

Enable Login page #

By default, any one can access the dashboard. If you would like to have dashboard's login, you do as following:

use \koolreport\dashboard\Application;
use \koolreport\dashboard\pages\Login;
use \koolreport\dashboard\User;

class App extends Application
{
    protected function login()
    {
        return  Login::create()
                ->authenticate(function($username,$password){
                    if($username==="admin@example.com" && $password==="admin_password")
                    {
                        // If authenticated, return User object
                        return User::create()
                            ->id(1)
                            ->name("Admin")
                            ->avatar("avatars/8.jpg")
                            ->roles(["admin"]);
                    }
                    // If unauthenticated, return null
                    return null;
                });
    }
}

Basically, to turn on authentication feature, we will need to provide Login page with authenticate() method. In the anonymous function provided inside authenticate(), we will receive $username and $password as parameters, we will check whether they are valid login. If they are correct, we will return User object. If not, we will return null value indicating that login is failed.

Set user directly #

If you establish dashboard as a part of your existed application, there is high chance that you have login system already and when authenticated user access dashboard, we do not want user to do login again. In this case, we can set user like following:

//index.php

App::create()
->user(
    User::create()
    ->id($id)
    ->name($name)
    ->avatar("avatars/user.jpg")
    ->roles(["user"])
)
->run();

By providing user object, the dashboard app will bypass the Login page.

Authorization #

App's access authorization #

allowAccess() method is the front gate keeper of authorization. return false; from the method will block the request and return Unauthorized response. We can use the method to pre-check the request received and user's permission to decide whether request is authorized to go through.

use \koolreport\dashboard\Application;

class App extends Application
{
    protected function allowAccess($request)
    {
        $user = $request->user();
        $route = $request->route();
        $action = $request->action();
        $params = $request->params();

        //Allow true to allow access and false otherwise
        return true; 
    }
}

Permissions #

By deriving the permission() method and provide Permit object, we are able to set authorization rules for users and requests. For more information of Permit class, please click here.

use \koolreport\dashboard\Application;

class App extends Application
{
    protected function permission()
    { 
        return Permit::create();
    }
}

Language #

In order to set language, we do:

use \koolreport\dashboard\Application;

class App extends Application
{
    use \koolreport\dashboard\languages\ES;

}

Theme #

In order to set theme, we do:

use \koolreport\dashboard\Application;

class App extends Application
{
    use \koolreport\dashboard\amazing\Theme;

}

Currently, Amazing theme is default and the only theme of Dashboard app. This Amazing theme will be used regardless you set theme. In the future, more themes will be available.

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.