diff --git a/library/Scores/Ciblage.php b/library/Scores/Ciblage.php index 90e6b360..bb6feb15 100644 --- a/library/Scores/Ciblage.php +++ b/library/Scores/Ciblage.php @@ -231,7 +231,34 @@ class Ciblage return $resSphinx['total_found']; } } - + + /** + * + * @param unknown $key + * @param string $min + * @param string $max + * @return multitype:unknown + */ + protected function minmax($key, $min=null, $max=null) + { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find($key)->current(); + + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + $min = ($min===null) ? $valMin : $min; + $max = ($max===null) ? $valMax : $max; + + return array( + 'min' => $min, + 'max' => $max, + ); + } + /** * * @param unknown_type $value @@ -341,20 +368,9 @@ class Ciblage protected function nbActio($value) { if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('nbActio')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + list($min, $max) = $this->minmax('nbActio', $value['in'][0], $value['in'][1]); + if ($min===null || $max===null) return; @@ -364,20 +380,9 @@ class Ciblage protected function nbPart($value) { - if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('nbPart')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + if ( array_key_exists('in', $value) ) { + + list($min, $max) = $this->minmax('nbPart', $value['in'][0], $value['in'][1]); if ($min===null || $max===null) return; @@ -389,19 +394,8 @@ class Ciblage protected function nbMPubli($value) { if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('nbMPubli')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + list($min, $max) = $this->minmax('nbMPubli', $value['in'][0], $value['in'][1]); if ($min===null || $max===null) return; @@ -413,19 +407,8 @@ class Ciblage protected function capital($value) { if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('capital')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + list($min, $max) = $this->minmax('capital', $value['in'][0], $value['in'][1]); if ($min===null || $max===null) return; @@ -437,20 +420,9 @@ class Ciblage protected function age_entrep($value) { if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('age_entrep')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; - + + list($min, $max) = $this->minmax('age_entrep', $value['in'][0], $value['in'][1]); + if ($min===null || $max===null) return; @@ -460,21 +432,10 @@ class Ciblage protected function age_etab($value) { - if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('age_etab')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; - + if ( array_key_exists('in', $value) ) { + + list($min, $max) = $this->minmax('age_etab', $value['in'][0], $value['in'][1]); + if ($min===null || $max===null) return; @@ -506,19 +467,8 @@ class Ciblage { if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('eff_etab')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + list($min, $max) = $this->minmax('eff_etab', $value['in'][0], $value['in'][1]); if ($min===null || $max===null) return; @@ -529,20 +479,10 @@ class Ciblage protected function eff_entrep($value) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('eff_entrep')->current(); - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - if ( array_key_exists('in', $value) ) { - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + if ( array_key_exists('in', $value) ) { + + list($min, $max) = $this->minmax('eff_entrep', $value['in'][0], $value['in'][1]); Zend_Registry::get('firebug')->info('Min : '.$min.', Max : '.$max); @@ -555,20 +495,9 @@ class Ciblage protected function nbEtab($value) { - if ( array_key_exists('in', $value) ) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('nbEtab')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + if ( array_key_exists('in', $value) ) { + + list($min, $max) = $this->minmax('nbEtab', $value['in'][0], $value['in'][1]); if ($min===null || $max===null) return; @@ -719,8 +648,12 @@ class Ciblage protected function bilEE($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilEE', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilEE', $min, $max); } } @@ -728,8 +661,12 @@ class Ciblage protected function bilFL($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilFL', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilFL', $min, $max); } } @@ -737,8 +674,12 @@ class Ciblage protected function bilFK($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilFK', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilFK', $min, $max); } } @@ -746,8 +687,12 @@ class Ciblage protected function bilFR($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilFR', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilFR', $min, $max); } } @@ -755,8 +700,12 @@ class Ciblage protected function bilGF($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilGF', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilGF', $min, $max); } } @@ -764,8 +713,12 @@ class Ciblage protected function bilGP($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilGP', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilGP', $min, $max); } } @@ -773,8 +726,12 @@ class Ciblage protected function bilGW($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilGW', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilGW', $min, $max); } } @@ -782,8 +739,12 @@ class Ciblage protected function bilHD($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilHD', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilHD', $min, $max); } } @@ -791,8 +752,12 @@ class Ciblage protected function bilHH($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilHH', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilHH', $min, $max); } } @@ -800,8 +765,12 @@ class Ciblage protected function bilHL($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilHL', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilHL', $min, $max); } } @@ -809,8 +778,12 @@ class Ciblage protected function bilHM($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilHM', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilHM', $min, $max); } } @@ -818,8 +791,12 @@ class Ciblage protected function bilHN($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilHN', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilHN', $min, $max); } } @@ -827,8 +804,12 @@ class Ciblage protected function bilYP($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + + list($min, $max) = $this->minmax('bilYP', $value['in'][0], $value['in'][1]); + + if ($min===null || $max===null) + return; + $this->setFilterRange('bilYP', $min, $max); } }