Hi team - I've been leveraging the dashboard package and template but have some questions on piping.
I would like to: . set up a datasource for each dashboard, . query the database (most of the widgets would leverage the same data queried from db), then *. pipe the data into different datastores (to be consumed by like widgets)
I want to use different datastores depending on the needs of the widget (some datastores could supply multiple widgets).
Question 1: what would be the right architecture to do that? I am using a BaseReport.php as described previously [https://www.koolreport.com/forum/topics/67](Topic 67) for my Settings and Setup. Question 2: How do I reference and use the datastore? (I couldn't find any examples in the demo of it being used)
<?php
//BaseReport.php to hold like settings
namespace demo\headcount;
use demo\AutoMaker;
class BaseReport extends Automaker
{
protected function settings()
{
return array(
"dataSources"=>array(
'dsemployee'=>array(
'connectionString'=>'mysql:host=localhost;dbname=talentanalytics',
'username'=>'root',
'password'=>'',
'charset'=>'utf8'
),
)
);
}
public function setup()
{
$this->src('dsemployee')
->query
(DB::table("eetable")
->select("Hire_Date","End_Date")
->where("COID",$coid)
)
->pipe($this->dataStore("mydata"))
->requestDataSending(); //populate data to the datastore
}
}
<?php
// HeadcountBoard.php uses BaseReport
namespace demo\headcount;
use demo\BaseReport;
<?php
//TotalEmployee.php contains SimpleCard widget
namespace demo\headcount;
use koolreport\dashboard\widgets\SimpleCard;
class TotalEmployees extends SimpleCard
{
protected function process()
{ //nothing to process
}
protected function value()
{
//Get value from the date range picker
$range = $this->sibling("HeadcountDateRange")->value();
/* THIS Errors out: return BaseReport::create(array("dataSource"=>$this->dataStore('mydata')))
Message: Call undefined dataStore() method
QUESTION: How do I use reference PIPED datasource? */
//This one works when query directly
return BaseReport::table("eetable")
->count('Hire_Date')
->whereBetween("Hire_Date",$range)
->run()
->getScalar();
}
protected function onCreated()
{
$this
->type("primary")
->text("Employees")
->icon("fas fa-users");
}
}