KoolReport's Forum

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

Loading Report Data Dynamically via Array #3283

Open Brad Wickwire opened this topic on on Apr 27 - 1 comments

Brad Wickwire commented on Apr 27

I am new to KoolReport and trying to see if I can easily switch all of our reports over. Everything is loaded into an Array and then with our current reporting we then loop through the array and write the contents. So I am hoping that I can write one file and just pass the $arrReportData to it and it would load the data. The issue is that the function settings is called first so is there a way to pass the data or tell it replace the reportData dataSources?

index.php

require_once "ReportRunner.php";
$objReportRunner = new ReportRunner;
$objReportRunner->loadData($arrReportData);
$objReportRunner->run()->render(); 

Here is the ReportRunner file

ReportRunner.php

<?php

// Require autoload.php from koolreport library
require_once "includes/koolreport/core/autoload.php";

//Specify some data processes that will be used to process
use \koolreport\processes\Sort;

//Define the class
class ReportRunner extends \koolreport\KoolReport	{
	var $arrData;
	
    use \koolreport\clients\Bootstrap;
    protected function settings()	{
				$arrDefaultData = array(
                        array("ID","Date","Member Name", "Member Email", "Member Phone", "Order Amount", "Items Purchased"),
                        array("3557319","1/12/2024 7:20","Default A Member","a@mail.com","111-111-1111","30.23","1"),
                        array("3557735","1/12/2024 16:56","B Member","b@mail.com","222-222-2222","72.45","2"),
                        array("3562528","1/18/2024 20:01","C Member","c@mail.com","333-333-3333","19.23","1"),
                        array("3579843","2/4/2024 19:54","D Member","d@mail.com","444-444-4444","30","1"),
                    );

        return array(
            "dataSources"=>array(
                "reportData"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table", //Table data format
                    "data"=>$arrDefaultData
                ),
            )
        );
    }
  
    protected function setup()	{
        $this->src('reportData')
        ->pipe(new Sort(array(
            "ID"=>"desc"
        )))
        ->pipe($this->dataStore('full_report_data'));
    }
    
    public function loadData($arrData)	{
    	$this->arrData = $arrData;
    	// THIS IS WHERE I WANT TO LOAD THE DATA FROM
    }
}
KoolReport commented on May 2

You do this:

require_once "ReportRunner.php";
$objReportRunner = new ReportRunner([
    "reportData"=>$arrReportData
]);
$objReportRunner->run()->render(); 

In the settings() function:

        return array(
            "dataSources"=>array(
                "reportData"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table", //Table data format
                    "data"=>$this->params["reportData"]
                ),
            )
        );

Let us know if you need further assistance.

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
None yet

None