KoolReport's Forum

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

Problem with parameters transfer for csv export #1008

Closed Eugene opened this topic on on Jul 24, 2019 - 10 comments

Eugene commented on Jul 24, 2019

Hi, could you help me to organise the csv export correctly

I have a big report and would like to export a part of it. I created a separate class report file for that stock_list_csv.php and the export report file csv_export.php So from my main report i call csv_export.php via the form where with the post method i send the report parameters

The csv_export.php

<?php

require_once "stock_list_csv.php";

$report = new stock_list_csv;
//var_dump($_POST);
$report->run()->exportToCSV(array(
        "dataStores" => array(
            "stock_fact_names" => array(
                "delimiter" => ",",
            )
        )
))->toBrowser("myreport.csv");

As you can see I use var_dump to check how my form from the main file send the parameters and it looks ok.

/csv_export.php:8:
array (size=2)
  'barmode' => string '1' (length=1)
  'update_date' => string '62' (length=2)

The stock_list_csv.php

<?php
require_once "../../koolreport/core/autoload.php";

class stock_list_csv extends \koolreport\KoolReport
{
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\excel\CSVExportable;

    
    function settings()
    {
        $config = include "../../config.php";
        return array(
            "dataSources" => array(
                "quinos" => $config["quinos"],
            )
        );
    }

    function setup()
    {
        $query_fact = 'SELECT 
          item_id as id_f
        , quantity
        FROM mytbl_actual_stock 
        WHERE date_id in(:date_id) AND stock in(:stock)';


        $this->src("quinos")
            ->query($query_fact)
            ->params(array(
                ":date_id" => $this->params["update_date"],
                ":stock" => (($this->params["barmode"]==1) ? array(3) : array(2)),
            ))
            ->pipe($this->dataStore("stock_fact_names"));
    }
}

But as result I'm gettingt the empty table... so it looks like my stock_list_csv.php does not have access to the parameters from the main file and csv_export.php. if i set ":date_id" and ":stock" manually the report works... Where is my mistake?

KoolReport commented on Jul 24, 2019

There is no where you transfer the parameter from $_POST to the report. That is the problem. There are two ways to solve:

  1. You can use directly $_POST in the report for example: ":date_id" => $_POST["update_date"],
  2. Or you can transfer the parameter to the report like this:
$report = new stock_list_csv(array(
    "update_time"=>$_POST["update_time"]
    ...
));

I prefer the second option.

Eugene commented on Jul 24, 2019

I thought it happens automatically :-) because i use the POSTBinding...

Also the report works if i add

protected function bindParamsToInputs()
    {
        return array(
            "update_date" => "update_date",
            "barmode"=>"barmode",
        );
    }

to stock_list_csv.php - (I've found it a minute ago)

KoolReport commented on Jul 24, 2019

Yes, it work if you do so. it is the feature of inputs package which automatics binding $_POST when you use the Bindable and POSTBinding in your report.

Eugene commented on Jul 24, 2019

And one more question... Is it possible to not include the columns names to the csv file?

KoolReport commented on Jul 24, 2019

Currently we do not have this option to remove the column header. The standard format of a CSV is having columns header. If you need to read produced csv, you may bypass the first row and start with data in second row.

Eugene commented on Jul 24, 2019

Unfortunately I need to import it to another application where I don't have a control under the import process and this app expected only data and no names of columns. It is not so difficult for me to delete the first row in a text editor but if I could get the file without name it were better :-) but if you don't have this option it is ok - koolreport has so many other more significant options that this small thing is not so important fo me :-)

Thank you

KoolReport commented on Jul 24, 2019

You can hack our code if you want to. Please go to line 331 of koolreport/excel/ExportHandler.php and you will find this code

$content .= implode($delimiter, $expColLabels) . "\n";

make it:

$content = "";

Now the exported CSV will lost its column header. That's brilliant :D

Eugene commented on Jul 24, 2019

Thank you... :-)

Eugene commented on Jul 24, 2019

Or like this :

$includeTitles = Util::get($option, 'includeTitles', true);
            if($includeTitles){
                $content .= implode($delimiter, $expColLabels) . "\n";
            } else {
                $content = "";
            }
KoolReport commented on Jul 24, 2019

That's absolutely brilliant :D

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