KoolReport's Forum

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

Undefined Index in Using $this->params #1376

Closed Prescious opened this topic on on Apr 4, 2020 - 2 comments

Prescious commented on Apr 4, 2020

Hello KoolReport Team!

I am trying to add a parameter to my report and this is the current setup that I have: I have this controller:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require APPPATH."\\reports\SecSummaryReport.php";

class Welcome extends CI_Controller {

     public function index()
     {
          $report = new SecSummaryReport(array('camote'=>"YEAR(ts.sec_In) = YEAR('2020/04/03')"));
          $report->run()->render();
     }
}

and the Report file contains:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
require_once APPPATH."libraries\koolreport\core\autoload.php";

use \koolreport\KoolReport;
use \koolreport\processes\Filter;
use \koolreport\processes\TimeBucket;
use \koolreport\processes\Group;
use \koolreport\processes\Limit; 

class SecSummaryReport extends \koolreport\KoolReport
{

  use \koolreport\codeigniter\Friendship;

  public function __construct()
  {
    parent::__construct();
  }
 
  public function settings()
  {
      $config = include(APPPATH."libraries/koolreport/config.php");

      return array(
          "dataSources"=>array(
              "systems_db"=>$config["systemsdb"]
          )
      );
  }   

  public function getWhereCond()
  {
    $conn = new mysqli(PATM_HOST, PATM_USER, PATM_PWD, PATM_DB);

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "SELECT rq_Id, rq_UserId, rq_Query FROM set_reportqueries";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            return 'WHERE '.$row["rq_Query"];
        }
    } else {
        echo "0 results";
    }


    $conn->close();    
  }

   public function setup()
    {
/*        $camote     = '';
        $params         = array();

if(array_key_exists('camote',$this->params)){
        $camote .= 'and camote = :camote';
        $params[':camote'] = $this->params["camote"];
        }*/

        $this->src('systems_db')
        ->query("
            SELECT
                ts.sec_UserNameId AS UserId,
                tul.u_Uname,
                CONCAT_WS(' ',  tul.u_Uname, '~', tul.u_LastName,   tul.u_FirstName,
                    IF (tul.u_SuffixName = 'NONE' OR tul.u_SuffixName LIKE '%n/a%' OR
tul.u_SuffixName LIKE '%n\\a%', '', tul.u_SuffixName),
                    IF (tul.u_MiddleName = 'NONE' OR tul.u_MiddleName LIKE '%n/a%' OR
tul.u_SuffixName LIKE '%n\\a%', '', tul.u_MiddleName) 
                ) AS `User`,
                Count(tul.u_Uname) AS Ilan,
                ts.sec_In,
                ts.sec_Out
            FROM
              tblsec AS ts
            INNER JOIN
              tbluserlist AS tul ON tul.u_Id = ts.sec_UserNameId
            :camote
            
            GROUP BY
              ts.sec_UserNameId
            ORDER BY
            tul.u_LastName ASC
                      ")
        ->params(array(
            ":camote"=>$this->params["camote"]
        ))
        ->pipe($this->dataStore('column_chart'));
    } 

}?> 

However, upon running, I get this error:

Can you help me figure out what is wrong? Thank you very much.

KoolReport commented on Apr 5, 2020

You have constructed the class with no parameters parent::__construct() so there will be no parameters, you should do:

public function __construct($params) {
    parent::__construct($params);
}

and better you should not use the construct there, it does not do anything.

Prescious commented on Apr 5, 2020

Hi KoolReport!

This really helped! Thank you for your support! :)

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

None