2012-03-26 14:47:09 +00:00

127 lines
3.8 KiB
PHP

<?php
class Object_Codepostaux extends Libs_Row
{
/* Selection des classes statut pour jstree */
public function _jstree_checked($type)
{
require_once('Scores/SessionCiblage.php');
$session = new SessionCiblage();
$valeurs = explode(',', $session->getCritere($type));
foreach ($valeurs as $valeur) {
if(!empty($valeur)) {
$return[] = $valeur;
}
}
if(is_array($return)) {
return ($return);
}
return (array($valeurs));
}
public function _jstree_undetermined($niveau, $type)
{
require_once('Scores/SessionCiblage.php');
$session = new SessionCiblage();
$table = new Table_Departements();
$valeurs = explode(',', $session->getCritere($type));
/*$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)
{
$type = explode(':', $valeur);
if(in_array($type[1], $this->_jstree_checked($type[0])))
return ('jstree-checked');
else if (in_array($valeur, $this->_jstree_undetermined($niveau, $type[0])))
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['REGION'].' '.$nom['NCCENR'],
'attr' => array('id' => 'adr_reg:'.$nom['REGION'],
'niveau' => 0,
'class' => $this->_getClass('adr_reg:'.$nom['REGION'], 0)
),
'state' => 'closed',
'children' => array()
);
}
return (json_encode($structure));
}
public function _getDepartements($codeRegionInsee)
{
$code = explode(':', $codeRegionInsee);
$departement = new Table_Departements();
$departements = $departement->fetchAll($departement->select()
->where('codeRegionInsee ='.$code[1]))->toArray();
$structure = array();
foreach($departements as $nom) {
$structure[] = array(
'data' => $nom['numdep'].' '.$nom['libdep'],
'attr' => array('id' => 'adr_dept:'.$nom['numdep'],
'niveau' => 1,
'class' => $this->_getClass('adr_dept:'.$nom['numdep'], 1)
),
'state' => 'closed',
'children' => array()
);
}
return (json_encode($structure));
}
public function _getCommunes($numdep)
{
$numdep = explode(':', $numdep);
$codepostau = new Table_Codepostauxs();
$codepostaux = $codepostau->fetchAll($codepostau->select()->where('codepos LIKE "'.$numdep[1].'%"'))->toArray();
$structure = array();
foreach($codepostaux as $nom) {
$structure[] = array(
'data' => $nom['Codepos'].' '.$nom['Commune'],
'attr' => array('id'=> 'adr_com:'.$nom['INSEE'],
'niveau' => 2,
'class' => $this->_getClass('adr_com:'.$nom['INSEE'], 2)
),
'state' => 'closed',
'children' => array()
);
}
return (json_encode($structure));
}
}