KoolReport's Forum

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

Multiple Data Filters #1642

Open Thomas opened this topic on on Oct 1, 2020 - 4 comments

Thomas commented on Oct 1, 2020

I would like to filter the report by Select2. It won't filter but I can't see see error. It would be great it somebody could take a look at it.

If I type in a default paramater in the defaultParamValues() the page blank, so there must be an error somewhere.

MyReport.php


    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;

    protected function defaultParamValues()
    {
        return array(
            "submitdates"=>array(),
            "seeds"=>array(),
            "lastpages"=>array()
        );
    }
    
    protected function bindparamsToInputs()
    {
        return array(
            "submitdates",
            "seeds",
            "lastpages"
        );
    }

setup()


// Quiry Parameters for Group 3
        $query_params = array();
        if($this->params["submitdates"]!=array())
        {
            $query_params[":submitdates"] = $this->params["submitdates"];
        }
        if($this->params["seeds"]!=array())
        {
            $query_params[":seeds"] = $this->params["seeds"];
        }
        if($this->params["lastpages"]!=array())
        {
            $query_params[":lastpages"] = $this->params["lastpages"];
        }


        $survey_data_group_3 = $this->src('survey_data')
        ->query("SELECT submitdate, seed, lastpage from $survey_db_table_name
            ".(($this->params["submitdates"]!=array())?"and submitdate in (:submitdates)":"")."
            ".(($this->params["seeds"]!=array())?"and seed in (:seeds)":"")."
            ".(($this->params["lastpages"]!=array())?"and lastpage in (:lastpages)":"")."             
            ")
        ;
        
        $survey_data_group_3
        ->params($query_params)
        ->pipe($this->dataStore("data_group_3"));

MyReport.view.php

<form method="post">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <b>Select Years -> submitdates</b>
                    <?php 
                    Select2::create(array(
                        "multiple"=>true,
                        "name"=>"submitdates",
                        "dataSource"=>$this->src("survey_data")->query("
                            SELECT submitdate from lime_survey_201005
                            group by submitdate
                        "),
                        "attributes"=>array(
                            "class"=>"form-control"
                        )
                    ));
                    ?>
                </div>    
  
                <div class="form-group">
                    <b>Select Product Lines -> seed</b>
                    <?php 
                    Select2::create(array(
                        "multiple"=>true,
                        "name"=>"seed",
                        "dataSource"=>$this->src("survey_data")->query("
                            SELECT seed from lime_survey_201005 
                            ".(  $this->params["submitdates"]!=array() ?"where submitdate in (:submitdates)":"")."
                            group by seed
                        ")->params(
                            $this->params["submitdates"]!=array()?
                            array(":submitdates"=>$this->params["submitdates"]):
                            array()
                        ),
                        "attributes"=>array(
                            "class"=>"form-control"
                        )
                    ));
                    ?>                
                </div>
                <div class="form-group">
                    <b>Select Customers -> lastpage</b>
                    <?php 
                    Select2::create(array(
                        "multiple"=>true,
                        "name"=>"lastpage",
                        "dataSource"=>$this->src("survey_data")->query("
                            SELECT lastpage
                            from lime_survey_201005                           
                            ".( $this->params["submitdates"]!=array()?"where submitdate in (:submitdates)":"")."
                            group by lastpage
                        ")->params(
                            $this->params["submitdates"]!=array()?
                            array(":submitdates"=>$this->params["submitdates"]):
                            array()
                        ),
                        "attributes"=>array(
                            "class"=>"form-control"
                        )
                    ));
                    ?>                
                </div>  
                <div class="form-group">
                    <button class="btn btn-primary">Submit</button>
                </div>    
            </div>
        </div>
        
    </form>
David Winterburn commented on Oct 1, 2020

Did you add "multiple" => true for the Select2 inputs? Anyway, please put this var_dump command in your report's setup and let us know the result:

function setup()
{
    echo "report params = "; var_dump($this->params);
    ...

Thanks!

Thomas commented on Oct 1, 2020

Yes: "multiple" => true" I basically copied the example and changed variables to my table. Here is the output:

report params = array(3) { ["submitdates"]=> array(0) { } ["seeds"]=> array(0) { } ["lastpages"]=> array(0) { } } 
David Winterburn commented on Oct 2, 2020

Please print out the query in setup as well:

     $query = "SELECT submitdate, seed, lastpage from $survey_db_table_name
            ".(($this->params["submitdates"]!=array())?"and submitdate in (:submitdates)":"")."
            ".(($this->params["seeds"]!=array())?"and seed in (:seeds)":"")."
            ".(($this->params["lastpages"]!=array())?"and lastpage in (:lastpages)":"")."             
            ";
    echo "query = $query";

Then copy the echoed query to your database admin interface (fill in the param values if necessary) to see its result. Thanks!

Thomas commented on Oct 6, 2020

I think I found the error. Because the sql query showed my the right output, there have to by something with the bindParameters. My guess is, that there is an error in the examples, which I copied. After I deleted the "s" (from plural to singular) in the parameters, everything worked as expected.

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

None