From d1366241bc3e445c35dcdf353784d2c1254a4fa5 Mon Sep 17 00:00:00 2001 From: Damien LASSERRE Date: Wed, 25 Jan 2012 09:01:27 +0000 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20l'arbo=20localisation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ArborescenceController.php | 189 +++++++++++++++++- 1 file changed, 187 insertions(+), 2 deletions(-) diff --git a/application/controllers/ArborescenceController.php b/application/controllers/ArborescenceController.php index bf277342..ddc43a94 100644 --- a/application/controllers/ArborescenceController.php +++ b/application/controllers/ArborescenceController.php @@ -132,12 +132,197 @@ class ArborescenceController extends Zend_Controller_Action */ public function geographiqueAction() { + require_once 'Scores/SessionCiblage.php'; $this->_helper->layout()->disableLayout(); $this->view->inlineScript()->appendFile('/themes/default/scripts/jquery.jstree.js'); + require_once 'Scores/SessionCiblage.php'; + $session = new SessionCiblage(); + $val = $session->getCritere('adr_cp'); + $valuesCheckeds = explode(',', $val); + if(count($valuesCheckeds) > 0) { + for($i=0;count($valuesCheckeds) > $i;$i++) { + $valuesCheckeds[$i] = substr($valuesCheckeds[$i], 1); + } + } + $valuesUndetermined = array(); + if($val != null) + { + $values = explode(',', $val); + foreach($values as $valuesChecked) { + if(strlen($valuesChecked) == 5) { + $dept = substr($valuesChecked, 0, 2); + $table = new Application_Model_Departements(); + $sql = $table->select()->from('departements', array('codeRegionInsee'))->where('numdep = ?',$dept); + $results = $table->fetchAll($sql)->toArray(); + foreach($results as $result) { + $valuesUndetermined[] = $result['codeRegionInsee']; + } + } + if(substr($valuesChecked, 0, 1) == 'R') { + $valuesCheckeds[] = substr($valuesChecked, 1); + } else if (substr($valuesChecked, 0, 1) == 'D') { + $table = new Application_Model_Departements(); + $sql = $table->select()->from('departements', array('codeRegionInsee'))->where('numdep = ?', substr($valuesChecked, 1)); + $result = $table->fetchAll($sql)->toArray(); + foreach($result as $item) { + $valuesUndetermined[] = $item['codeRegionInsee']; + } + } + } + } + + $key = $this->getRequest()->getParam('key'); + $this->view->assign('key', $key); + $regionsM = new Application_Model_Regions(); - //$sql = $regionsM->select(); - $this->view->assign('regions', $regionsM->fetchAll()->toArray()); + $sql = $regionsM->select()->from('regions'); + $regions = $regionsM->fetchAll()->toArray(); + + $structure = array(); + foreach($regions as $region) { + $structure = array( + 'data' => $region['NCCENR'], + 'attr' => array('id' => 'R'.$region['REGION'], 'niveau' => 1), + 'state' => 'closed', + 'children' => array() + ); + if(in_array($region['REGION'], $valuesCheckeds)) { + $structure['attr']['class'] = 'jstree-checked'; + } + if(in_array($region['REGION'], $valuesUndetermined)) { + $structure['attr']['class'] = 'jstree-undetermined'; + } + $tabAdrDep[] = $structure; + } + $this->view->regions = json_encode($tabAdrDep); + } + + public function getGeographiqueParent($values) + { + foreach($values as $value) { + $type = strlen($value, 0, 1); + + if($type == 'D') { + $table = new Application_Model_Departements(); + + } + } + } + + public function geographiqueajaxAction() + { + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $request = $this->getRequest(); + $key = $request->getParam('key'); + $niveau = $request->getParam('niveau'); + + if($niveau == 1) { + require_once 'Scores/SessionCiblage.php'; + $session = new SessionCiblage(); + $val = $session->getCritere('adr_cp'); + $valuesCheckeds = array(); + $valuesUndetermined = array(); + if($val != null) + { + $values = explode(',', $val); + foreach($values as $valuesChecked) { + if(strlen($valuesChecked) == 5) { + $valuesUndetermined[] = substr($valuesChecked, 0, 2); + } + if(substr($valuesChecked, 0, 1) == 'D') { + $valuesCheckeds[] = substr($valuesChecked, 1); + } else if (substr($valuesChecked, 0, 1) == 'R') { + $table = new Application_Model_Departements(); + $sql = $table->select()->from('departements', array('numdep'))->where('codeRegionInsee = ?', substr($valuesChecked, 1)); + $result = $table->fetchAll($sql)->toArray(); + foreach($result as $item) { + $valuesCheckeds[] = $item['numdep']; + } + + } + } + } + $region = substr($request->getParam('id'), 1); + $deps = new Application_Model_Departements(); + $sql = $deps->select() + ->from('departements') + ->where('codeRegionInsee = ?', $region); + $departements = $deps->fetchAll($sql)->toArray(); + foreach($departements as $departement) { + $structure = array( + 'data' => $departement['libdep'], + 'attr' => array('id' => 'D'.$departement['numdep'], 'niveau' => 2), + 'state' => 'closed', + 'children' => array() + ); + if(in_array($departement['numdep'], $valuesCheckeds)) { + $structure['attr']['class'] = 'jstree-checked'; + } + if(in_array($departement['numdep'], $valuesUndetermined)) { + $structure['attr']['class'] = 'jstree-undetermined'; + } + $departementTab[] = $structure; + } + echo json_encode($departementTab); + } else { + require_once 'Scores/SessionCiblage.php'; + $session = new SessionCiblage(); + $val = $session->getCritere('adr_cp'); + $valuesCheckeds = array(); + if($val != null) + { + $values = explode(',', $val); + //print_r($values); + foreach($values as $valuesChecked) { + if(strlen($valuesChecked) == 5) { + $valuesCheckeds[] = $valuesChecked; + } + else if(substr($valuesChecked, 0, 1) == 'D') { + $table = new Application_Model_Codepostaux(); + $sql = $table->select()->from('codepostaux', array('Codepos'))->where('Codepos LIKE "'.substr($valuesChecked, 1).'%"'); + $results = $table->fetchAll($sql)->toArray(); + foreach($results as $result) { + if(!in_array($result['Codepos'], $values)) + $valuesCheckeds[] = $result['Codepos']; + } + } else if (substr($valuesChecked, 0, 1) == 'R') { + $Departements= new Application_Model_Departements(); + $sql = $Departements->select()->from('departements', array('numdep'))->where('codeRegionInsee = ?', substr($valuesChecked, 1)); + $results = $Departements->fetchAll($sql)->toArray(); + foreach($results as $result) { + $table = new Application_Model_Codepostaux(); + $sql = $table->select()->from('codepostaux', array('Codepos'))->where('Codepos LIKE "'.$result['numdep'].'%"'); + $codes = $table->fetchAll($sql)->toArray(); + foreach($codes as $code) { + if(!in_array($result['Codepos'], $values)) + $valuesCheckeds[] = $code['Codepos']; + } + } + } + } + } + $numdep = substr($request->getParam('id'), 1); + $code = new Application_Model_Codepostaux(); + $sql = $code->select() + ->from('codepostaux') + ->where('Codepos LIKE "'.$numdep.'%"'); + $codePostaux = $code->fetchAll($sql)->toArray(); + + foreach($codePostaux as $codePostau) { + $structure = array( + 'data' => '[ '.$codePostau['Codepos'].' ]'.ucfirst(strtolower($codePostau['Commune'])), + 'attr' => array('id' => $codePostau['Codepos'], 'niveau' => 3) + ); + if(in_array($codePostau['Codepos'], $valuesCheckeds)) { + $structure['attr']['class'] = 'jstree-checked'; + } + $CodePostauxTab[] = $structure; + } + echo json_encode($CodePostauxTab); + } } /**