127 lines
3.8 KiB
PHP
Raw Normal View History

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 */
2012-03-26 14:47:09 +00:00
public function _jstree_checked($type)
2012-02-02 17:29:14 +00:00
{
2012-02-15 09:25:21 +00:00
require_once('Scores/SessionCiblage.php');
$session = new SessionCiblage();
2012-03-26 14:47:09 +00:00
$valeurs = explode(',', $session->getCritere($type));
foreach ($valeurs as $valeur) {
if(!empty($valeur)) {
$return[] = $valeur;
}
}
if(is_array($return)) {
2012-02-15 09:25:21 +00:00
return ($return);
2012-03-26 14:47:09 +00:00
}
2012-02-15 09:25:21 +00:00
return (array($valeurs));
}
2012-03-26 14:47:09 +00:00
public function _jstree_undetermined($niveau, $type)
2012-02-15 09:25:21 +00:00
{
require_once('Scores/SessionCiblage.php');
$session = new SessionCiblage();
$table = new Table_Departements();
2012-03-26 14:47:09 +00:00
$valeurs = explode(',', $session->getCritere($type));
/*$valeurs = array_merge($valeurs, explode(',', $session->getCritere('adr_com')));*/
2012-02-15 09:25:21 +00:00
$in = array();
2012-03-26 14:47:09 +00:00
2012-02-15 09:25:21 +00:00
foreach($valeurs as $valeur) {
if($niveau == 0) {
2012-03-26 14:47:09 +00:00
if ($type == 'adr_dept'){
2012-02-15 09:25:21 +00:00
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
2012-02-15 09:25:21 +00:00
foreach ($insee as $code)
2012-03-15 15:44:10 +00:00
$in[] = 'adr_reg:'.$code['codeRegionInsee'];
2012-02-15 09:25:21 +00:00
} else{
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
foreach ($insee as $code)
2012-03-15 15:44:10 +00:00
$in[] = 'adr_reg:'.$code['codeRegionInsee'];
2012-02-02 17:29:14 +00:00
}
2012-02-15 09:25:21 +00:00
} else if ($niveau == 1) {
$insee = $table->fetchAll($table->select('departements', array('codeRegionInsee'))
->where('numdep = ?', substr($valeur, 0, 2)))->toArray();
foreach ($insee as $code)
2012-03-15 15:44:10 +00:00
$in[] = 'adr_dept:'.$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)
{
2012-03-26 14:47:09 +00:00
$type = explode(':', $valeur);
if(in_array($type[1], $this->_jstree_checked($type[0])))
2012-02-15 09:25:21 +00:00
return ('jstree-checked');
2012-03-26 14:47:09 +00:00
else if (in_array($valeur, $this->_jstree_undetermined($niveau, $type[0])))
2012-02-15 09:25:21 +00:00
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(
2012-03-26 14:47:09 +00:00
'data' => $nom['REGION'].' '.$nom['NCCENR'],
2012-03-15 15:44:10 +00:00
'attr' => array('id' => 'adr_reg:'.$nom['REGION'],
2012-02-15 09:25:21 +00:00
'niveau' => 0,
2012-03-15 15:44:10 +00:00
'class' => $this->_getClass('adr_reg:'.$nom['REGION'], 0)
2012-02-15 09:25:21 +00:00
),
'state' => 'closed',
'children' => array()
);
}
return (json_encode($structure));
}
public function _getDepartements($codeRegionInsee)
{
2012-03-15 15:44:10 +00:00
$code = explode(':', $codeRegionInsee);
2012-02-15 09:25:21 +00:00
$departement = new Table_Departements();
$departements = $departement->fetchAll($departement->select()
2012-03-15 15:44:10 +00:00
->where('codeRegionInsee ='.$code[1]))->toArray();
2012-02-15 09:25:21 +00:00
$structure = array();
2012-02-02 17:29:14 +00:00
2012-02-15 09:25:21 +00:00
foreach($departements as $nom) {
$structure[] = array(
2012-03-20 08:24:41 +00:00
'data' => $nom['numdep'].' '.$nom['libdep'],
2012-03-15 15:44:10 +00:00
'attr' => array('id' => 'adr_dept:'.$nom['numdep'],
2012-02-15 09:25:21 +00:00
'niveau' => 1,
2012-03-15 15:44:10 +00:00
'class' => $this->_getClass('adr_dept:'.$nom['numdep'], 1)
2012-02-15 09:25:21 +00:00
),
'state' => 'closed',
'children' => array()
);
}
return (json_encode($structure));
}
public function _getCommunes($numdep)
{
2012-03-15 15:44:10 +00:00
$numdep = explode(':', $numdep);
2012-02-15 09:25:21 +00:00
$codepostau = new Table_Codepostauxs();
2012-03-15 15:44:10 +00:00
$codepostaux = $codepostau->fetchAll($codepostau->select()->where('codepos LIKE "'.$numdep[1].'%"'))->toArray();
2012-02-15 09:25:21 +00:00
$structure = array();
foreach($codepostaux as $nom) {
$structure[] = array(
2012-03-20 08:24:41 +00:00
'data' => $nom['Codepos'].' '.$nom['Commune'],
2012-03-15 15:44:10 +00:00
'attr' => array('id'=> 'adr_com:'.$nom['INSEE'],
2012-02-15 09:25:21 +00:00
'niveau' => 2,
2012-03-15 15:44:10 +00:00
'class' => $this->_getClass('adr_com:'.$nom['INSEE'], 2)
2012-02-15 09:25:21 +00:00
),
'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
}
}