KoolReport's Forum

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

Undefined property: koolreport\core\WidgetContainer::$queryParams #2554

Closed deep opened this topic on on Feb 2, 2022 - 1 comments

deep commented on Feb 2, 2022

Hi I am trying to access kool report with my existing code igniter application. it self is a big application and recently I have bought pro version. Kindly guide me what I am doing wrong. Currently I have done the code as per example, I have getting following error :

Undefined property: koolreport\core\WidgetContainer::$queryParams Filename: visualquery/VisualQuery.php Line Number: 85

and

Type: Error

Message: Call to undefined method koolreport\core\WidgetContainer::paramsToValue()

Filename: C:\wamp64\www\my-folder\assets\koolreport\visualquery\VisualQuery.php

Line Number: 86

I have existing report php which is as follow..

/**
 * Class Reports
 */
class Reports extends Admin_Controller
{
    public function graphical_report() {
        $data['report'] = new MyReport;
        $this->layout->set($data);
        $this->layout->buffer('content', 'reports/graphical_report_view');
        $this->layout->render();
    }
}

require_once APPPATH.'..\assets\koolreport\core\autoload.php';
use \koolreport\core\Utility as Util;
class MyReport extends \koolreport\KoolReport
{
    use \koolreport\bootstrap4\Theme;
    // use \koolreport\clients\Bootstrap;
    use \koolreport\visualquery\Bindable;
        

    public function defineSchemas()
    {
        return [
            "salesSchema" => array(
                "tables" => [
                    "customers" => array(
                        "{meta}" => [
                            "alias" => "Table Customers"
                        ],
                        "customerNumber" => array(
                            "alias" => "Customer Number",
                        ),
                        "customerName" => array(
                            "alias" => "Customer Name",
                        ),
                    ),
                    "orders" => array(
                        "{meta}" => [
                            "alias" => "Table Orders"
                        ],
                        "orderNumber" => array(
                            "alias" => "Order Number"
                        ),
                        "orderDay" => array(
                            "alias" => "Order Day",
                            "expression" => "date(orderDate)",
                            "type" => "date",
                        ),
                        "orderDate" => array(
                            "alias" => "Order Date",
                            "type" => "datetime",
                        ),
                        "orderMonth" => [
                            "expression" => "month(orderDate)",
                            "type" => "number",
                        ]
                        // "customerNumber"=>array(
                        //    "alias"=>"Customer Number"
                        // )
                    ),
                    "orderdetails" => array(
                        "{meta}" => [
                            "alias" => "Order Details"
                        ],
                        // "orderNumber"=>array(
                        //     "alias"=>"Order Number"
                        // ),
                        "quantityOrdered" => array(
                            "alias" => "Quantity",
                            "type" => "number",
                        ),
                        "priceEach" => array(
                            "alias" => "Price Each",
                            "type" => "number",
                            "decimal" => 2,
                            "prefix" => "$",
                        ),
                        // "productCode"=>array(
                        //     "alias"=>"Product Code"
                        // ),
                        "cost" => [
                            // "expression" => "orderdetails.quantityOrdered * orderdetails.priceEach",
                            "expression" => "quantityOrdered * priceEach",
                            "alias" => "Order Cost",
                            "type" => "number",
                            "decimal" => 2,
                            "prefix" => "$",
                        ]
                    ),
                    "products" => array(
                        "{meta}" => [
                            "alias" => "Table Products"
                        ],
                        "productCode" => array(
                            "alias" => "Product Code"
                        ),
                        "productName" => array(
                            // "alias" => "Product Name"
                        ),
                    )
                ],
                "relations" => [
                    ["orders.customerNumber", "leftjoin", "customers.customerNumber"],
                    ["orders.orderNumber", "join", "orderdetails.orderNumber"],
                    ["orderdetails.productCode", "leftjoin", "products.productCode"],
                ],
            ),
            "separator" => "."
        ];
    }

    function settings()
    {
        return array(
            "dataSources" => array(
                "automaker" => array(
                    "connectionString" => "mysql:host=localhost;dbname=automaker",
                    "username" => "root",
                    "password" => "",
                    "charset" => "utf8"
                ),
                'mysql' => [
                    'host' => 'localhost',
                    'username' => 'root',
                    'password' => '',
                    'dbname' => 'automaker',
                    'class' => '\koolreport\datasources\MySQLDataSource',
                ],
            )
        );
    }   
    
    protected function setup()
    {
        $params = Util::get($this->queryParams, 'visualquery1');
        // echo "params = "; Util::prettyPrint($params);
        $qb = $this->paramsToQueryBuilder($params);
        // $arr = $qb->toArray();
        // echo "qb array="; Util::prettyPrint($arr);
        $this->query = $params ? 
            $qb->toMySQL() : "select * from customers where 1=0";
        $this->paramQuery = $params ? 
        // $qb->toMySQL(['useSQLParams' => "question"]) : "select * from customers where 1=0";
            $qb->toMySQL(['useSQLParams' => "name"]) : "select * from customers where 1=0";
        $this->sqlParams = $qb->getSQLParams();
        // echo "paramQuery="; echo $this->paramQuery; echo "<br>";
        // Util::prettyPrint($this->sqlParams);

        $this
            ->src('automaker')
            // ->query($this->query)
            ->query($this->paramQuery)
            ->params($this->sqlParams)
            ->pipe(new \koolreport\processes\ColumnMeta([
                "Order Number" => [
                    "type" => "string"
                ],
                "orderMonth" => [
                    "type" => "string"
                ],
            ]))
            ->pipe($this->dataStore('vqDS'));
    } 

}

graphical_view page:

<?php
    use \koolreport\core\Utility as Util;

?>
<html>
    <head>
        <title>KoolReport visual query</title>
    </head>
    <body>
        
        <?php 
        //to view table data in table formate
        /*Table::create(array(
            "dataSource"=>$clientData
        ));*/
        ?>

        <?php

        //to view column char or bar char formate 
        // ColumnChart::create(array(
        //     "title"=>"Client Report",
        //     "dataSource"=>$clientData,
        //     "columns"=>array(
        //         "client_name"=>array("label"=>"Client name","type"=>"text"),
        //         "opening_balance"=>array("label"=>"Opening Balance","type"=>"number","prefix"=>"$"),
        //         "transactions_debit"=>array("label"=>"Debit","type"=>"number","prefix"=>"$"),
        //         "transactions_credit"=>array("label"=>"Credit","type"=>"number","prefix"=>"$"),
        //         "closing_balance"=>array("label"=>"Closing Balance","type"=>"number","prefix"=>"$"),
        //     )
        // ));
        ?>

        <form method='post' class2='container box-container'>
            <h1>Test visual query</h1>
            <div>
                <?php
                // Util::prettyPrint($_POST);
                \koolreport\visualquery\VisualQuery::create(array(
                    "name" => "visualquery1",
                    // "themeBase" => "bs4",
                    "schema" => "salesSchema",
                    "defaultValue" => [
                        "selectDistinct" => true,
                        "selectTables" => [
                            "orders",
                            "orderdetails",
                            "products",
                        ],
                        "selectFields" => [
                            "products.productName",
                        ],
                        "filters" => [
                            [
                                "field" => "orders.orderDay", 
                                "operator" => ">", 
                                "value1" => "2001-01-01", 
                                "value2" => "", 
                                "logic" => "and",
                                "toggle" => true,
                            ],
                            ["products.productCode", "btw", "2", "998", "and", "toggle" => false],
                            "(",
                            // ["products.productName", "nbtw", "1", "", "and"],
                            ["products.productName", "<>", "a", "", "and"],
                            ["products.productName", "nin", "a", "", "and"],
                            ")",
                            // ["products.productName", "null", "a", "", "or"],
                            ["products.productName", "nnull", "a", "", "and"],
                            ["products.productName", "ctn", "a", "", "and"],
                            ["orders.orderMonth", "btw", 0, 12, "and"],
                        ],
                        "groups" => [
                            [
                                "field" => "orderdetails.cost", 
                                "aggregate" => "sum", 
                                "toggle" => true
                            ]
                        ],
                        "havings" => [
                            "(",
                            [
                                "field" => "sum(orderdetails.cost)", 
                                "operator" => ">", 
                                "value1" => "10000", 
                                "value2" => "", 
                                "logic" => "and",
                                "toggle" => true,
                            ],
                            ")",
                            // ["products.productName", "<>", "a", "", "or"],
                        ],
                        "sorts" => [
                            [
                                "field" => "sum(orderdetails.cost)", 
                                "direction" => "desc", 
                                "toggle" => true
                            ],
                            ["products.productName", "desc", "toggle" => false]
                        ],
                        "limit" => [
                            "offset" => 5,
                            "limit" => 15,
                            "toggle" => false,
                        ]
                    ],
                    "activeTab" => "filters",
                ));
                ?>
            </div>
            <div style='padding: 15px;'>
                <!-- <input type='text' name='input1' value='value1' /> -->
                <button type='submit' class='btn btn-primary'>Submit</button>
            </div>
            <style>
                pre {
                    overflow-x: auto;
                    white-space: pre-wrap;
                    white-space: -moz-pre-wrap;
                    white-space: -pre-wrap;
                    white-space: -o-pre-wrap;
                    word-wrap: break-word;
                }
            </style>
            <div style="margin: 30px; width:800px">
                <pre style="width:800px"><?php echo $this->query; ?></pre>
            </div>
            <div>
                <?php
                // print_r($this->dataStore('vqDS')->meta());
                \koolreport\charttable\ChartTable::create(array(
                    "name" => "charttable1",
                    "dataSource" => $this->dataStore('vqDS'),
                    // "columns" => ["Quantity", "Product Name"],
                    "options" => [
                        // "order" => [[1, 'desc']],
                        // "ordering" => false,
                        // "buttons" => [],
                    ]
                ));
                ?>
            </div>
            <div style='padding: 15px;'>
                <?php
                // echo "queryParams = "; Util::prettyPrint($this->queryParams); echo "<br>"; 
                ?>
                <?php
                // Util::prettyPrint($_POST); echo "<br>";
                ?>
            </div>
        </form>
    </body>
</html>
Shaurya Bajaj commented on Feb 4, 2022

Posted by my team member Duplicate of [(https://www.koolreport.com/forum/topics/2556)].

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

VisualQuery