KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Dashboard SQL own files #2770

Closed GHSix opened this topic on on Jul 28, 2022 - 3 comments

GHSix commented on Jul 28, 2022

Actually I have in MyTable.php, ie, the following DS:

protected function dataSource()
    {
       return AutoMaker::table('portal_users');
    }

I would like to put all the SQLs in their own files, so I can reuse it if needed in other boards. The only way I know to do it now is like:

protected function dataSource()
    {
       return require('My_portal_users.sql.php');
    }

There is a better way? Maybe some dashboard class where I can have a file like MyQueries.php and use it where needed as in MyTable.php?

GHSix commented on Jul 28, 2022

In add to the question, how to pass params to queries?

$query = AutoMaker::rawSQL("
    SELECT paymentDate, amount
    FROM payments
   WHERE amount > :someAmount
");

->params() does not seem to exist here.

KoolReport commented on Jul 29, 2022

For your first question, you may create a trait MyQueries.php

trait MyQueries
{
    function getCustomerTable()
    {
        return AutoMaker::table("customer");
    }
}

The trait contains functions that return query. Later in each widget, you can use "use MyQueries;" to include those query functions.

Hope that helps.

For second questions, the rawSQL now is really a raw query string, we will include the bind parameters later.

GHSix commented on Jul 29, 2022

It works!

Just to let it clear for others:

MyTable.php

...
class MyTable extends Table
{
    use MyQueries;

    protected function dataSource()
        {
           return $this->getCustomerTable();
        }
...

Thank you.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Dashboard