2012-02-02 17:29:14 +00:00
|
|
|
<?php
|
|
|
|
class Object_Codepostaux extends Libs_Row
|
|
|
|
{
|
2012-02-15 09:25:21 +00:00
|
|
|
/* Selection des classes statut pour jstree */
|
|
|
|
public function _jstree_checked()
|
2012-02-02 17:29:14 +00:00
|
|
|
{
|
2012-02-15 09:25:21 +00:00
|
|
|
require_once('Scores/SessionCiblage.php');
|
|
|
|
$session = new SessionCiblage();
|
|
|
|
$valeurs = explode(',', $session->getCritere('adr_com'));
|
2012-02-02 17:29:14 +00:00
|
|
|
|
2012-02-15 09:25:21 +00:00
|
|
|
foreach ($valeurs as $valeur)
|
|
|
|
$return[] = $valeur;
|
|
|
|
if(is_array($return))
|
|
|
|
return ($return);
|
|
|
|
return (array($valeurs));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function _jstree_undetermined($niveau)
|
|
|
|
{
|
|
|
|
require_once('Scores/SessionCiblage.php');
|
|
|
|
$session = new SessionCiblage();
|
|
|
|
$table = new Table_Departements();
|
|
|
|
$valeurs = explode(',', $session->getCritere('adr_com'));
|
|
|
|
$in = array();
|
|
|
|
|
|
|
|
foreach($valeurs as $valeur) {
|
|
|
|
if($niveau == 0) {
|
|
|
|
if ($valeur[0] == 'D'){
|
|
|
|
$valeur = substr($valeur, 1, strlen($valeur));
|
|
|
|
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
|
2012-02-16 08:42:47 +00:00
|
|
|
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
|
2012-02-15 09:25:21 +00:00
|
|
|
foreach ($insee as $code)
|
|
|
|
$in[] = 'R'.$code['codeRegionInsee'];
|
|
|
|
} else{
|
2012-02-16 08:42:47 +00:00
|
|
|
$valeur = substr($valeur, 0, strlen($valeur));
|
2012-02-15 09:25:21 +00:00
|
|
|
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
|
|
|
|
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
|
|
|
|
foreach ($insee as $code)
|
2012-02-16 08:42:47 +00:00
|
|
|
$in[] = 'R'.$code['codeRegionInsee'];
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-02-15 09:25:21 +00:00
|
|
|
} else if ($niveau == 1) {
|
2012-02-16 08:42:47 +00:00
|
|
|
$valeur = substr($valeur, 0, strlen($valeur));
|
2012-02-15 09:25:21 +00:00
|
|
|
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
|
|
|
|
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
|
|
|
|
foreach ($insee as $code)
|
2012-02-16 08:42:47 +00:00
|
|
|
$in[] = 'D'.$code['numdep'];
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-15 09:25:21 +00:00
|
|
|
return ($in);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function _getClass($valeur, $niveau)
|
|
|
|
{
|
|
|
|
if(in_array($valeur, $this->_jstree_checked()))
|
|
|
|
return ('jstree-checked');
|
|
|
|
else if (in_array($valeur, $this->_jstree_undetermined($niveau)))
|
|
|
|
return ('jstree-undetermined');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fonctions de construction de jstree */
|
|
|
|
public function _getRegions()
|
|
|
|
{
|
|
|
|
$region = new Table_Regions();
|
|
|
|
$regions = $region->fetchAll($region->select())->toArray();
|
|
|
|
$structure = array();
|
|
|
|
|
|
|
|
foreach($regions as $nom) {
|
|
|
|
$structure[] = array(
|
|
|
|
'data' => $nom['NCCENR'],
|
|
|
|
'attr' => array('id' => 'R'.$nom['REGION'],
|
|
|
|
'niveau' => 0,
|
|
|
|
'class' => $this->_getClass('R'.$nom['REGION'], 0)
|
|
|
|
),
|
|
|
|
'state' => 'closed',
|
|
|
|
'children' => array()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (json_encode($structure));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function _getDepartements($codeRegionInsee)
|
|
|
|
{
|
|
|
|
$departement = new Table_Departements();
|
|
|
|
$departements = $departement->fetchAll($departement->select()
|
|
|
|
->where('codeRegionInsee ='.substr($codeRegionInsee, 1, strlen($codeRegionInsee))))->toArray();
|
|
|
|
$structure = array();
|
2012-02-02 17:29:14 +00:00
|
|
|
|
2012-02-15 09:25:21 +00:00
|
|
|
foreach($departements as $nom) {
|
|
|
|
$structure[] = array(
|
|
|
|
'data' => $nom['libdep'],
|
|
|
|
'attr' => array('id' => 'D'.$nom['numdep'],
|
|
|
|
'niveau' => 1,
|
|
|
|
'class' => $this->_getClass('D'.$nom['numdep'], 1)
|
|
|
|
),
|
|
|
|
'state' => 'closed',
|
|
|
|
'children' => array()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (json_encode($structure));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function _getCommunes($numdep)
|
|
|
|
{
|
|
|
|
$numdep = substr($numdep, 1, strlen($numdep));
|
|
|
|
$codepostau = new Table_Codepostauxs();
|
|
|
|
$codepostaux = $codepostau->fetchAll($codepostau->select()->where('codepos LIKE "'.$numdep.'%"'))->toArray();
|
|
|
|
$structure = array();
|
|
|
|
|
|
|
|
foreach($codepostaux as $nom) {
|
|
|
|
$structure[] = array(
|
|
|
|
'data' => $nom['Commune'],
|
|
|
|
'attr' => array('id'=> $nom['INSEE'],
|
|
|
|
'niveau' => 2,
|
|
|
|
'class' => $this->_getClass($nom['INSEE'], 2)
|
|
|
|
),
|
|
|
|
'state' => 'closed',
|
|
|
|
'children' => array()
|
2012-02-02 17:29:14 +00:00
|
|
|
);
|
|
|
|
}
|
2012-02-15 09:25:21 +00:00
|
|
|
|
|
|
|
return (json_encode($structure));
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|