152 lines
4.5 KiB
PHP
152 lines
4.5 KiB
PHP
<?php
|
|
class Object_Codepostaux
|
|
{
|
|
/* Selection des classes statut pour jstree */
|
|
public function _jstree_checked($type)
|
|
{
|
|
require_once('Scores/SessionCiblage.php');
|
|
$session = new SessionCiblage();
|
|
$valeurs = $session->getCritere($type);
|
|
return (substr($valeurs, 0, strlen($valeurs)-1));
|
|
}
|
|
|
|
public function _jstree_undetermined($niveau, $type)
|
|
{
|
|
require_once('Scores/SessionCiblage.php');
|
|
$session = new SessionCiblage();
|
|
$table = new Application_Model_Departements();
|
|
$valeurs = explode(',', $session->getCritere($type));
|
|
//print_r($valeurs);
|
|
/*$valeurs = array_merge($valeurs, explode(',', $session->getCritere('adr_com')));*/
|
|
$in = array();
|
|
|
|
foreach($valeurs as $valeur) {
|
|
if($niveau == 0) {
|
|
if ($type == 'adr_dept'){
|
|
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
|
|
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
|
|
foreach ($insee as $code)
|
|
$in[] = 'adr_reg:'.$code['codeRegionInsee'];
|
|
} else{
|
|
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
|
|
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
|
|
foreach ($insee as $code)
|
|
$in[] = 'adr_reg:'.$code['codeRegionInsee'];
|
|
}
|
|
} else if ($niveau == 1) {
|
|
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
|
|
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
|
|
foreach ($insee as $code)
|
|
$in[] = 'adr_dept:'.$code['numdep'];
|
|
}
|
|
}
|
|
return ($in);
|
|
}
|
|
|
|
public function _getClass($valeur, $niveau)
|
|
{
|
|
require_once('Scores/SessionCiblage.php');
|
|
$session = new SessionCiblage();
|
|
$valeurs = explode(',', $valeur);
|
|
$key = ((strlen($valeur) < 5)?'adr_dept':'adr_com');
|
|
$session = explode(',', $session->getCritere('adr_dept'));
|
|
$row = 0;
|
|
foreach ($session as $dept) {
|
|
if(in_array($dept, $valeurs))
|
|
$row++;
|
|
}
|
|
if($row == count($valeurs) and $row != 1) {
|
|
return ('jstree-checked');
|
|
}
|
|
else if($row > 1)
|
|
return ('jstree-undetermined');
|
|
|
|
/*$type = explode(':', $valeur);
|
|
if($type[1] == $this->_jstree_checked($type[0]))
|
|
return ('jstree-checked');
|
|
else if (in_array($valeur, $this->_jstree_undetermined($niveau, $type[0])))
|
|
return ('jstree-undetermined');*/
|
|
}
|
|
|
|
protected function getDepartement($region)
|
|
{
|
|
$table = new Application_Model_Departements();
|
|
$sql = $table->select()
|
|
->where('codeRegionInsee = '.$region);
|
|
$result = $table->fetchAll($sql)->toArray();
|
|
$depts = array();
|
|
foreach($result as $departement) {
|
|
$depts[] = $departement['numdep'];
|
|
}
|
|
return (implode(',', $depts));
|
|
}
|
|
|
|
/* Fonctions de construction de jstree */
|
|
public function _getRegions()
|
|
{
|
|
$region = new Application_Model_Regions();
|
|
$regions = $region->fetchAll($region->select()->order('NCCENR ASC'))->toArray();
|
|
$structure = array();
|
|
|
|
foreach($regions as $nom) {
|
|
$structure[] = array(
|
|
'data' => $nom['NCCENR'],
|
|
'attr' => array('id' => $this->getDepartement($nom['REGION']),
|
|
'niveau' => 0,
|
|
'class' => $this->_getClass($this->getDepartement($nom['REGION']), 0)
|
|
),
|
|
'state' => 'closed',
|
|
'children' => array()
|
|
);
|
|
}
|
|
return (json_encode($structure));
|
|
}
|
|
|
|
public function _getDepartements($codeRegionInsee)
|
|
{
|
|
//$code = explode(':', $codeRegionInsee);
|
|
$departement = new Application_Model_Departements();
|
|
foreach(explode(',', $codeRegionInsee) as $dept) {
|
|
$departements[] = $departement->fetchAll($departement->select()
|
|
->where('numdep ='.$dept))->toArray();
|
|
}
|
|
$structure = array();
|
|
|
|
foreach($departements as $nom) {
|
|
$structure[] = array(
|
|
'data' => $nom[0]['numdep'].' '.$nom[0]['libdep'],
|
|
'attr' => array('id' => $nom[0]['numdep'],
|
|
'niveau' => 1,
|
|
'class' => $this->_getClass($nom[0]['numdep'], 1)
|
|
),
|
|
'state' => 'closed',
|
|
'children' => array()
|
|
);
|
|
}
|
|
|
|
return (json_encode($structure));
|
|
}
|
|
|
|
public function _getCommunes($numdep)
|
|
{
|
|
|
|
//$numdep = explode(':', $numdep);
|
|
$codepostau = new Application_Model_CodePostaux();
|
|
$codepostaux = $codepostau->fetchAll($codepostau->select()->where('codepos LIKE "'.$numdep.'%"'))->toArray();
|
|
$structure = array();
|
|
|
|
foreach($codepostaux as $nom) {
|
|
$structure[] = array(
|
|
'data' => $nom['Codepos'].' '.$nom['Commune'],
|
|
'attr' => array('id'=> $nom['INSEE'],
|
|
'niveau' => 2,
|
|
'class' => $this->_getClass($nom['INSEE'], 2)
|
|
),
|
|
'state' => 'closed',
|
|
'children' => array()
|
|
);
|
|
}
|
|
|
|
return (json_encode($structure));
|
|
}
|
|
} |