Traits
TName #
TName
trait allows object to get or set name with name()
method. The Dashboard and Widget are implemented this trait.
Example:
class MyClass
{
use \koolreport\dashboard\TName;
}
$obj = new MyClass();
echo $obj->name();
// Output "MyClass"
$obj->name("this is my class");
echo $obj->name();
//Output "this is my class"
TProps #
TProps facilitate object to get/set property for an object.
Example:
// Example of using object with TProps trait
$object
->hidden(true)
->width(1/2)
->cssClass("bold");
echo $object->hidden(); //true
echo $object->width(); //1/2
echo $object->cssClass(); //bold
Methods #
When TProps is implemented in an object, object has below methods
Name | type | description |
---|---|---|
props(array $list) | Set the properties available, $list is an associate array with name of property and its default value | |
props() | array | Using props() without parameter will return the list of properties in associate array |
hasProp(string $propName) | Return true if the property is existed | |
removeProps(array $list) | Remove some properties, for example ->removeProps(["width","height"]) | |
getProp(string $name) | mixed | Get value of a property |
extractProps(array $list) | array | Get list of some properties, for example ->extractProps(["width","height"]) |
Example:
use \koolreport\dashboard\TProps;
use \koolreport\dashboard\TConstructServices;
class MyClass
{
use TProps;
use TConstructServices;
public function __construct()
{
$this->constructServices();
$this->props([
"width"=>120,
"height"=>240,
"color"=>"red",
]);
}
}
$obj = new MyClass;
$obj->width(240)->height(360)->color("blue");
echo $obj->width(); //240
echo $obj->color(); //"blue"
echo $obj->getProp("width"); //240
echo json_encode ($object->extractProps(["width","height"])); // {"width":240,"height":360}
echo $obj->hasProp("width")?"yes":"no"; // "yes"
$object->removeProps(["width","height"]); // Now there is only "color" property
TAppLink #
TAppLink
trait contains app()
function which allows get/set the application object. Dashboard, Widget, Request are implemented this trait.
Example:
$this->app(); //Get the app object
$this->app($app); //Set the app object
TDashboardLink #
TDashboardLink
trait contains dashboard()
function which allows get/set the dashboard object. Widget is implemented this trait.
Example:
$this->dashboard(); //Get the dashboard object
$this->dashboard($dashboard); //Set the dashboard object
TWidgetLink #
TWidgetLink
trait contains widget()
function which allows get/set the widget object. Field is implemented this trait.
Example:
$this->widget(); //Get the widget object
$this->widget($widget); //Set the dashboard object
TParams #
TParams
provides params()
method to object. Dashboard and Widget are implemented this trait.
Example:
//Set parameters
$this->params([
"year"=>2020,
"productId"=>30
]);
$this->params(); //Get all params
$this->params("year"); // Get only year parameter
TEnabledPermit #
TEnabledPermit
provides methods enabled()
and enabledWhen()
method to object. Dashboard, Widget and Field are implemented this trait.
enabled() #
Get or set the availability of object
Example:
$this->enabled(false); // Disable the object
// Set by function
$this->enabled(function($request) {
return $request->user()->hasRole("admin");
});
// Get status
$enabled = $this->enabled();
enabledWhen() #
If your application is provided with Permit object then you can use enabledWhen()
Example:
$this->enabledWhen("beAdmin");
//The "beAdmin" is define like this
class Permit extends \koolreport\dashboard\Permit
{
protected function beAdmin($request, $sender)
{
return $request->user()->hasRole("admin");
}
}
//The Permit will be provided to Application like this:
class App extends \koolreport\dashboard\Application
{
protected function permission()
{
return Permit::create();
}
}
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.