Hi all,
I am building report with multiple dropdown select lists which I use to filter data in query. I've bind them in bindParamsToInputs and than in setup() function I am using different (4 in total) different queries depending on the input from bindParamsToInputs
Here is my if else query selection statement
if (($this->params["proizv"] == "ALL") && ($this->params["nadgrupa"] == "ALL")) {
// all filters are set to ALL (any)
$this->src('automaker')
->query($sumirana_prodaja['ALL'])
->params(array(
":korisnik"=>$this->params["korisnik"],
":start"=>$this->params["dateRange"][0],
":end"=>$this->params["dateRange"][1],
))
->pipe($this->dataStore("sumirana_prodaja"));
} elseif (($this->params["nadgrupa"] == "ALL") || ($this->params["proizv"] == "ALL")) {
// one of the filters is selected, find out which one
if($this->params["nadgrupa"] != "ALL"){
// category is selected
$this->src('automaker')
->query($sumirana_prodaja['f_nadgrupa'])
->params(array(
":korisnik"=>$this->params["korisnik"],
":start"=>$this->params["dateRange"][0],
":end"=>$this->params["dateRange"][1],
":nadgrupa"=>$this->params["nadgrupa"]."%",
))
->pipe($this->dataStore("sumirana_prodaja"));
} else {
// manufacturer is selected
$this->src('automaker')
->query($sumirana_prodaja['f_proizv'])
->params(array(
":korisnik"=>$this->params["korisnik"],
":start"=>$this->params["dateRange"][0],
":end"=>$this->params["dateRange"][1],
":proizv"=>$this->params["proizv"],
))
->pipe($this->dataStore("sumirana_prodaja"));
}
// kraj provjere
} else {
// both filters are selected: category and manufacturer
$this->src('automaker')
->query($sumirana_prodaja['nadgrupa_proizvodjac'])
->params(array(
":korisnik"=>$this->params["korisnik"],
":start"=>$this->params["dateRange"][0],
":end"=>$this->params["dateRange"][1],
":nadgrupa"=>$this->params["nadgrupa"]."%",
":proizv"=>$this->params["proizv"],
))
->pipe($this->dataStore("sumirana_prodaja"));
}
I am calling different query using simple array $sumirana_prodaja['nadgrupa_proizvodjac'] and each query accepts different parameters like below:
$sumirana_prodaja['sve'] = "...
WHERE cm_prodaja.Dobavljac = :korisnik AND cm_prodaja.DatumOtprem BETWEEN :start AND :end
...";
$sumirana_prodaja['f_nadgrupa'] = "...
WHERE cm_prodaja.Dobavljac = :korisnik AND cm_prodaja.DatumOtprem BETWEEN :start AND :end AND cm_prodaja.Grupa like :nadgrupa
...";
$sumirana_prodaja['f_proizv'] = "...
WHERE cm_prodaja.Dobavljac = :korisnik AND cm_prodaja.DatumOtprem BETWEEN :start AND :end AND cm_prodaja.Proizvodjac = :proizv
...";
$sumirana_prodaja['nadgrupa_proizvodjac'] = "...
WHERE cm_prodaja.Dobavljac = :korisnik AND cm_prodaja.DatumOtprem BETWEEN :start AND :end AND cm_prodaja.Grupa like :nadgrupa AND cm_prodaja.Proizvodjac = :proizv
...";
My question is, is there different way to get same result but on shorter way? I could be having more input parameters and it would be impossible to use this method.