Gestion des imbrications entre codeCommune et départements

This commit is contained in:
Michael RICOIS 2012-05-16 14:14:19 +00:00
parent 1444bd6283
commit 053d4d0b89

View File

@ -177,11 +177,14 @@ class Ciblage
} else {
$this->sphinx->SetLimits(0, 1);
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
Zend_Registry::get('firebug')->info("Sphinx : ".$this->alpha);
Zend_Registry::get('firebug')->info("Sphinx : ".$this->alpha);
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
Zend_Registry::get('firebug')->info($resSphinx);
return $resSphinx['total_found'];
if ($resSphinx === false)
return false;
return $resSphinx['total_found'];
}
}
@ -196,11 +199,10 @@ class Ciblage
}
}
//Valeur NULL dans BDD
protected function groupe($value)
{
if ( array_key_exists('in', $value) ) {
//$this->setFilter('sirenGrp', $value);
$this->setFilter('sirenGrp', $value);
}
}
@ -710,21 +712,21 @@ class Ciblage
foreach ( $value['in'] as $item ) {
switch( substr($item,0,1) ) {
case 'C':
$communeValueIn[] = substr($item,1);
$communeValueIn[] = intval(substr($item,1));
break;
case 'D':
$departementValueIn[] = substr($item,1);
$departementValueIn[] = intval(substr($item,1));
break;
case 'R':
$departementsM = new Application_Model_Departements();
$sql = $departementsM->select()
->form($departementsM, array('numdep'))
->from($departementsM, array('numdep'))
->where('codeRegionInsee = ?', substr($item,1));
$departements = $departementsM->fetchAll($sql)->toArray();
foreach ($departements as $d) {
$departementValueIn[] = $d['numdep'];
$departementValueIn[] = intval($d['numdep']);
}
break;
}
@ -735,21 +737,21 @@ class Ciblage
foreach ( $value['ex'] as $item ) {
switch( substr($item,0,1) ) {
case 'C':
$communeValueEx[] = substr($item,1);
$communeValueEx[] = intval(substr($item,1));
break;
case 'D':
$departementValueEx[] = substr($item,1);
$departementValueEx[] = intval(substr($item,1));
break;
case 'R':
$departementsM = new Application_Model_Departements();
$sql = $departementsM->select()
->form($departementsM, array('numdep'))
->from($departementsM, array('numdep'))
->where('codeRegionInsee = ?', substr($item,1));
$departements = $departementsM->fetchAll($sql)->toArray();
foreach ($departements as $d) {
$departementValueEx[] = $d['numdep'];
$departementValueEx[] = intval($d['numdep']);
}
break;
}
@ -764,12 +766,46 @@ class Ciblage
$this->setFilter('adr_dep', $departementValueEx, true);
}
if ( count($departementValueIn)>0 ) {
$this->setFilter('codeCommne', $communeValueIn);
if ( count($communeValueIn)>0 ) {
//Check if a departement include a codeCommune else remove this codeCommune
if (count($departementValueIn)>0) {
foreach ( $departementValueIn as $item ) {
$codePostauxM = new Application_Model_CodePostaux();
$sql = $codePostauxM->select()
->from($codePostauxM, array('INSEE'))
->where('Codepos LIKE ?', $item.'%');
$result = $codePostauxM->fetchAll($sql)->toArray();
$arrayDiff = array();
foreach ( $result as $insee ) {
$arrayDiff[] = intval($insee['INSEE']);
}
$communeValueIn = array_diff($communeValueIn, $arrayDiff);
}
}
if ( count($communeValueIn)>0 ) {
$this->setFilter('codeCommune', $communeValueIn);
}
}
if ( count($departementValueEx)>0 ) {
$this->setFilter('codeCommune', $communeValueEx, true);
if ( count($communeValueEx)>0 ) {
//Check if a departement include a codeCommune else remove this codeCommune
if (count($departementValueEx)>0) {
foreach ( $departementValueEx as $item ) {
$codePostauxM = new Application_Model_CodePostaux();
$sql = $codePostauxM->select()
->from($codePostauxM, array('INSEE'))
->where('Codepos LIKE ?', $item.'%');
$result = $codePostauxM->fetchAll($sql)->toArray();
$arrayDiff = array();
foreach ( $result as $insee ) {
$arrayDiff[] = intval($insee['INSEE']);
}
$communeValueEx = array_diff($communeValueEx, $arrayDiff);
}
}
if ( count($communeValueEx)>0 ) {
$this->setFilter('codeCommune', $communeValueEx, true);
}
}
}