151 lines
4.4 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-04-12 08:10:10 +00:00
$valeurs = $session->getCritere($type);
return (substr($valeurs, 0, strlen($valeurs)-1));
2012-02-15 09:25:21 +00:00
}
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));
2012-04-12 08:10:10 +00:00
//print_r($valeurs);
2012-03-26 14:47:09 +00:00
/*$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-04-12 08:10:10 +00:00
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))
2012-02-15 09:25:21 +00:00
return ('jstree-checked');
2012-04-12 08:10:10 +00:00
else if($row > 0)
2012-02-15 09:25:21 +00:00
return ('jstree-undetermined');
2012-04-12 08:10:10 +00:00
/*$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 Table_Departements();
$sql = $table->select()
->where('codeRegionInsee = '.$region);
$result = $table->fetchAll($sql)->toArray();
$depts = array();
foreach($result as $departement) {
$depts[] = $departement['numdep'];
}
return (implode(',', $depts));
2012-02-15 09:25:21 +00:00
}
/* 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-04-12 08:10:10 +00:00
'attr' => array('id' => $this->getDepartement($nom['REGION']),
2012-02-15 09:25:21 +00:00
'niveau' => 0,
2012-04-12 08:10:10 +00:00
'class' => $this->_getClass($this->getDepartement($nom['REGION']), 0)
2012-02-15 09:25:21 +00:00
),
'state' => 'closed',
'children' => array()
);
}
return (json_encode($structure));
}
public function _getDepartements($codeRegionInsee)
{
2012-04-12 08:10:10 +00:00
//$code = explode(':', $codeRegionInsee);
2012-02-15 09:25:21 +00:00
$departement = new Table_Departements();
2012-04-12 08:10:10 +00:00
foreach(explode(',', $codeRegionInsee) as $dept) {
$departements[] = $departement->fetchAll($departement->select()
->where('numdep ='.$dept))->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-04-12 08:10:10 +00:00
'data' => $nom[0]['numdep'].' '.$nom[0]['libdep'],
'attr' => array('id' => $nom[0]['numdep'],
2012-02-15 09:25:21 +00:00
'niveau' => 1,
2012-04-12 08:10:10 +00:00
'class' => $this->_getClass($nom[0]['numdep'], 1)
2012-02-15 09:25:21 +00:00
),
'state' => 'closed',
'children' => array()
);
}
return (json_encode($structure));
}
public function _getCommunes($numdep)
{
2012-04-12 08:10:10 +00:00
//$numdep = explode(':', $numdep);
2012-02-15 09:25:21 +00:00
$codepostau = new Table_Codepostauxs();
2012-04-12 08:10:10 +00:00
$codepostaux = $codepostau->fetchAll($codepostau->select()->where('codepos LIKE "'.$numdep.'%"'))->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-04-12 08:10:10 +00:00
'attr' => array('id'=> $nom['INSEE'],
2012-02-15 09:25:21 +00:00
'niveau' => 2,
2012-04-12 08:10:10 +00:00
'class' => $this->_getClass($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
}
}