KoolReport's Forum

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

Error passing inputs to array parameters #2383

Open Francois DISSAIT opened this topic on on Oct 12 - 4 comments

Francois DISSAIT commented on Oct 12

Hello, can you please help me ? I cannot pass datetime pikers parameters to my query ... widely inspired from your examples ... When I add in line 60 of actions_par_pays.php the parameters "startDatePicker", "endDatePicker" it bugs ... As shown in the listing, if I use fixed date parameters in the query, it works, so it is not the query that is wrong, but the part of public fonction setup() : params array ( ) I send you my linstings

index.php

<?php include "../../../helpers/run.example.php";?>
__actions_par_pays.php__
<?php
require_once "../../../load.koolreport.php";

use \koolreport\KoolReport;

use \koolreport\processes\CalculatedColumn;
use \koolreport\processes\ColumnMeta;

class ActionsParPays extends \koolreport\KoolReport
{
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding; 
	
	protected function defaultParamValues()
    {
        return array(
			"sauf"=>"--",
			"startDatePicker"=>date("2019-01-01 00:00:00"),
            "endDatePicker"=>date("2025-12-31 23:59:59")
			
        );
    }
	protected function bindParamsToInputs()
    {
        return array(
            "sauf",
			"startDatePicker",
            "endDatePicker"
					
        );
    }
	public function settings()
    {
        $config = include "../../../config.php";

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

    public function setup()	
    {
        $this->src('phamm')
        ->query("
            select `expeditions`.`pays` , `pays`.`country` , `expeditions`.`date_expedition` as date, count(`expeditions`.`pays`) as nombre
			from `expeditions`
			inner join `pays` on `expeditions`.`pays`= `pays`.`pays`	
			where 
			`expeditions`.`pays` <> :sauf 
			and 
	`expeditions`.`date_expedition` < '2021-01-01'
	and
	`expeditions`.`date_expedition` > '2019-12-31'	
			group by `expeditions`.`pays`
			")
		->params(array(
			":sauf"=>$this->params["sauf"]
			
			
						
		))	
        ->pipe(new CalculatedColumn(array(
            "tooltip"=>"'{expeditions.pays} : $'.number_format({nombre}).'{pays.country}'",
        )))
        ->pipe(new ColumnMeta(array(
            "tooltip"=>array(
                "type"=>"string",
            )
        )))
        ->pipe($this->dataStore("expeditions"));
    }
}

actions_par_pays.view.php

<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\GeoChart;
use \koolreport\inputs\DateTimePicker;
use \koolreport\inputs\Select;
?>

<div class='report-content'>
    <div class="text-center">
        <h1>Actions Par Pays</h1>
        <p class="lead">Le rapport montre le nombre d'expéditions dans chaque pays</p>
    </div>
<form method="post">
	 <div class="col-md-12 form-group">
                <html lang="fr">
                <div class="row">
                     <div class="col-md-6">
                        From Date:
                        <?php
                        DateTimePicker::create(array(
                            "name"=>"startDatePicker",
                            "maxDate"=>"@endDatePicker",
                            "format"=>"MM/DD/YYYY HH:mm",
                            "themeBase"=>"bs4",
                        ));
                        ?>
                    </div>
                    <div class="col-md-6">
                        To Date:
                        <?php
                        DateTimePicker::create(array(
                            "name"=>"endDatePicker",
                            "minDate"=>"@startDatePicker",
                            "format"=>"MM/DD/YYYY HH:mm",
                            "themeBase"=>"bs4",
                        ));
                        ?>
                    </div>
						<strong>Sauf</strong>
						<?php
						Select::create(array(
						"name"=>"sauf",
						"dataStore"=>$this->dataStore("expeditions"),
						"defaultOption"=>array("--"=>""),
						"dataBind"=>"pays",
						"attributes"=>array(
                        "class"=>"form-control",
						)
						));
						?>
					</div>
	 </div>
                <div class="col-md-3 " ;">
				<button class="btn btn-lg btn-primary">O.K.</button>
				</div>
				</div>
				 <p class="form-group">
            <i>* Below are values that archived from <code>$params</code>
            </i>
        </p>                        
				<pre><code><?php echo json_encode($this->params,JSON_PRETTY_PRINT) ?></code></pre>
</form>
   

    <?php
    GeoChart::create(array(
        "dataStore"=>$this->dataStore("expeditions"),
        "columns"=>array(
            "country"=>array(
                "label"=>"Pays"
            ),
            "nombre"=>array(
                "label"=>"Actions",
                "type"=>"number",
                "prefix"=>""
            )
        ),
        "width"=>"100%",
		"height"=>"350",
		"options"=>array(			
			"colorAxis" => ["colors"=> ['orange', 'red']],
			"backgroundColor"=> '#81d4fa',
			"showTooltip"=> true,
            "showInfoWindow"=> true     
			
        )
    ));
    ?>

    <?php
    Table::create(array(
        "dataStore"=>$this->dataStore("expeditions")->sort(array("nombre"=>"desc")),
        "columns"=>array(
            "pays"=>array(
                "label"=>"Pays"
            ),
            "nombre"=>array(
                "label"=>"Expeditions",
                "type"=>"number",
                "prefix"=>"",
            )
        ),
        "paging"=>array(
            "pageSize"=>10,
        ),
        "cssClass"=>array(
            "table"=>"table table-bordered table-striped"
        )
    ));
    ?>
	

</div>
Sebastian Morales commented on Oct 12

Pls try this and let us know the result:

$this->src('phamm')
        ->query("
            select `expeditions`.`pays` , `pays`.`country` , `expeditions`.`date_expedition` as date, count(`expeditions`.`pays`) as nombre
			from `expeditions`
			inner join `pays` on `expeditions`.`pays`= `pays`.`pays`	
			where 
			`expeditions`.`pays` <> :sauf 
			and 
	`expeditions`.`date_expedition` < :endDatePicker
	and
	`expeditions`.`date_expedition` > :startDatePicker
			group by `expeditions`.`pays`
			")
		->params(array(
			":sauf"=>$this->params["sauf"],
			":startDatePicker" => $this->params["startDatePicker"],
			":endDatePicker" => $this->params["endDatePicker"],
						
		))	 
...
Francois DISSAIT commented on Oct 12

Of course I did ! as soon as ":startDatePicker" etc is written in the params(array, ) the problem occurs, the page is white ....

Sebastian Morales commented on Oct 13

Pls turn on your PHP error reporting to know exactly what went wrong. Anyway, pls try to output the param values and fill it in your query and copy/paste it to your DB interface to see the result.

    public function setup()	
    {
        var_dump($this->params); echo "<br>";
        $query = "
            select `expeditions`.`pays` , `pays`.`country` , `expeditions`.`date_expedition` as date, count(`expeditions`.`pays`) as nombre
			from `expeditions`
			inner join `pays` on `expeditions`.`pays`= `pays`.`pays`	
			where 
			`expeditions`.`pays` <> $this->params["sauf"] 
			and 
	`expeditions`.`date_expedition` < $this->params["endDatePicker"]
	and
	`expeditions`.`date_expedition` > $this->params["startDatePicker"]
			group by `expeditions`.`pays`
			";
        echo "query = $query"; // run this report and copy this query to your DB
        ...
Francois DISSAIT commented on Oct 15

php report (V7.3) reports

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /home/u521225422/domains/phammadmin.com/public_html/reports_phamm/reports/basic/test_actions/Actions.php on line 52

I wille search and tell you what I find ! François

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

Inputs