425 lines
12 KiB
PHP
425 lines
12 KiB
PHP
<?php
|
|
class ArborescenceController extends Zend_Controller_Action
|
|
{
|
|
/* Nafs */
|
|
public function nafAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
$request = $this->getRequest();
|
|
$key = $request->getParam('key');
|
|
$niveau = $request->getParam('niveau', 1);
|
|
|
|
$fields = new Scores_Fields();
|
|
$val = $fields->getCritere($key);
|
|
$valuesChecked = array();
|
|
$valuesUndetermined = array();
|
|
|
|
if ($val != null){
|
|
$valuesChecked = $val['in'];
|
|
if (count($valuesChecked)>0) {
|
|
foreach($valuesChecked as $value){
|
|
$valuesUndetermined = array_merge($valuesUndetermined, $this->getNafParent($value, true));
|
|
}
|
|
}
|
|
}
|
|
|
|
$nafM = new Application_Model_Naf();
|
|
$sql = $nafM->select()->where('niveau = ?', $niveau)->order('code ASC');
|
|
$result = $nafM->fetchAll($sql)->toArray();
|
|
|
|
$tabNaf = array();
|
|
foreach($result as $item)
|
|
{
|
|
if ( $item['niveau']==1 ) {
|
|
$data = $item['lib'];
|
|
} else {
|
|
$data = $item['lib'].' ('.$item['code'].')';
|
|
}
|
|
|
|
$structure = array(
|
|
'data' => $data,
|
|
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
|
'state' => 'closed',
|
|
'children' => array(),
|
|
);
|
|
if (in_array($item['code'], $valuesChecked)){
|
|
$structure['attr']['class'] = 'jstree-checked';
|
|
}
|
|
if (in_array($item['code'], $valuesUndetermined)){
|
|
$structure['attr']['class'] = 'jstree-undetermined';
|
|
}
|
|
$tabNaf[] = $structure;
|
|
}
|
|
$this->view->key = $key;
|
|
$this->view->naf = json_encode($tabNaf);
|
|
}
|
|
|
|
public function nafajaxAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
$request = $this->getRequest();
|
|
$key = $request->getParam('key');
|
|
$niveau = $request->getParam('niveau', 1);
|
|
$niveau = $niveau + 1;
|
|
|
|
//Récupération des valeurs enregistrées en session
|
|
$fields = new Scores_Fields();
|
|
$val = $fields->getCritere($key);
|
|
$valuesChecked = array();
|
|
|
|
$valuesUndetermined = array();
|
|
|
|
if ($val != null){
|
|
$valuesChecked = $val['in'];
|
|
if (count($valuesChecked)>0) {
|
|
foreach($valuesChecked as $value){
|
|
$valuesUndetermined = array_merge($valuesUndetermined, $this->getNafParent($value, true));
|
|
}
|
|
}
|
|
}
|
|
|
|
$niveau++;
|
|
$nafM = new Application_Model_Naf();
|
|
$sql = $nafM->select();
|
|
|
|
if (!empty($parent) && $niveau==2) {
|
|
$sql->where('parent = ?', $parent);
|
|
} elseif (!empty($parent) && $niveau>2) {
|
|
$sql->where("code LIKE '".$parent."%'");
|
|
}
|
|
$sql->where('niveau = ?', $niveau)->order('code ASC');
|
|
|
|
$result = $nafM->fetchAll($sql)->toArray();
|
|
$tabNaf = array();
|
|
foreach($result as $item){
|
|
$structure = array(
|
|
'data' => $item['code'].' - '.$item['lib'],
|
|
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
|
);
|
|
if (in_array($item['code'], $valuesChecked)){
|
|
$structure['attr']['class'] = 'jstree-checked';
|
|
}
|
|
if (in_array($item['code'], $valuesUndetermined)){
|
|
$structure['attr']['class'] = 'jstree-undetermined';
|
|
}
|
|
if ($niveau<5){
|
|
$structure['state'] = 'closed';
|
|
$structure['children'] = array();
|
|
}
|
|
$tabNaf[] = $structure;
|
|
}
|
|
echo json_encode($tabNaf);
|
|
}
|
|
|
|
protected function getNafParent($value, $niveau1 = false)
|
|
{
|
|
$out = array();
|
|
if (strlen($value)>2) {
|
|
$niveau = strlen($value)-1;
|
|
$new = substr($value,0,$niveau);
|
|
$out = array_merge($out, array($new), $this->getNafParent($new, $niveau1));
|
|
} elseif (strlen($value)==2 && $niveau1 === true) {
|
|
$nafM = new Application_Model_Naf();
|
|
$sql = $nafM->select()
|
|
->from($nafM, array('parent'))
|
|
->where('code = ?', $value);
|
|
$result = $nafM->fetchRow($sql);
|
|
$out[] = $result->parent;
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
|
|
/* Geographiques */
|
|
public function geographiqueAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
$key = $this->getRequest()->getParam('key');
|
|
|
|
$fields = new Scores_Fields();
|
|
$val = $fields->getCritere($key);
|
|
$valuesChecked = array();
|
|
$valuesUndetermined = array();
|
|
|
|
if ($val != null){
|
|
$valuesChecked = $val['in'];
|
|
if (count($valuesChecked)>0) {
|
|
foreach($valuesChecked as $value) {
|
|
if ( substr($value,0,1)!='R' ) {
|
|
$valuesUndetermined = array_merge($valuesUndetermined, $this->getGeoParent($value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$regionsM = new Application_Model_Regions();
|
|
$sql = $regionsM->select()->order('NCCENR ASC');
|
|
$regions = $regionsM->fetchAll($sql)->toArray();
|
|
|
|
$tabRegions = array();
|
|
foreach($regions as $item) {
|
|
$structure = array(
|
|
'data' => $item['NCCENR'],
|
|
'attr' => array(
|
|
'id' => 'R'.$item['REGION'],
|
|
'niveau' => 0,
|
|
),
|
|
'state' => 'closed',
|
|
'children' => array()
|
|
);
|
|
if (in_array('R'.$item['REGION'], $valuesChecked)){
|
|
$structure['attr']['class'] = 'jstree-checked';
|
|
}
|
|
if (in_array('R'.$item['REGION'], $valuesUndetermined)){
|
|
$structure['attr']['class'] = 'jstree-undetermined';
|
|
}
|
|
$tabRegions[] = $structure;
|
|
}
|
|
|
|
$this->view->key = $key;
|
|
$this->view->regions = json_encode($tabRegions);
|
|
}
|
|
|
|
public function geographiqueajaxAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
$request = $this->getRequest();
|
|
$id = $request->getParam('id');
|
|
$niveau = $request->getParam('niveau');
|
|
|
|
//Récupération des valeurs enregistrées en session
|
|
$fields = new Scores_Fields();
|
|
$val = $fields->getCritere('geo');
|
|
$valuesChecked = array();
|
|
|
|
$valuesUndetermined = array();
|
|
|
|
if ($val != null){
|
|
$valuesChecked = $val['in'];
|
|
if (count($valuesChecked)>0) {
|
|
foreach($valuesChecked as $value){
|
|
$valuesUndetermined = array_merge($valuesUndetermined, $this->getGeoParent($value));
|
|
}
|
|
}
|
|
}
|
|
|
|
// R[code] => Régions => recherche département
|
|
if ( substr($id,0,1)=='R' ) {
|
|
|
|
$region = substr($id,1);
|
|
|
|
$departementsM = new Application_Model_Departements();
|
|
$sql = $departementsM->select()->where('codeRegionInsee = ?', $region);
|
|
$departements = $departementsM->fetchAll($sql)->toArray();
|
|
|
|
$tabDepartements = array();
|
|
foreach($departements as $item) {
|
|
$structure = array(
|
|
'data' => $item['libdep'].' ('.$item['numdep'].')',
|
|
'attr' => array(
|
|
'id' => 'D'.$item['numdep'],
|
|
'niveau' => 1,
|
|
),
|
|
'state' => 'closed',
|
|
'children' => array()
|
|
);
|
|
if (in_array('D'.$item['numdep'], $valuesChecked)){
|
|
$structure['attr']['class'] = 'jstree-checked';
|
|
}
|
|
if (in_array('D'.$item['numdep'], $valuesUndetermined)){
|
|
$structure['attr']['class'] = 'jstree-undetermined';
|
|
}
|
|
$tabDepartements[] = $structure;
|
|
}
|
|
echo json_encode($tabDepartements);
|
|
}
|
|
// D[code] => Départements => recherche commune
|
|
else if ( substr($id,0,1)=='D' ) {
|
|
|
|
$departement = substr($id,1);
|
|
|
|
$codePostauxM = new Application_Model_CodePostaux();
|
|
$sql = $codePostauxM->select()
|
|
->where('Codepos LIKE ?', $departement.'%')
|
|
->order('Commune ASC');
|
|
Zend_Registry::get('firebug')->info($sql->__toString());
|
|
$communes = $codePostauxM->fetchAll($sql)->toArray();
|
|
|
|
$tabCommunes = array();
|
|
foreach($communes as $item) {
|
|
$structure = array(
|
|
'data' => $item['Commune'],
|
|
'attr' => array(
|
|
'id' => 'C'.$item['INSEE'],
|
|
'niveau' => 1,
|
|
)
|
|
);
|
|
if (in_array('C'.$item['INSEE'], $valuesChecked)){
|
|
$structure['attr']['class'] = 'jstree-checked';
|
|
}
|
|
$tabCommunes[] = $structure;
|
|
}
|
|
echo json_encode($tabCommunes);
|
|
}
|
|
}
|
|
|
|
protected function getGeoParent($code)
|
|
{
|
|
if (substr($code,0,1)=='D') {
|
|
|
|
$departementsM = new Application_Model_Departements();
|
|
$sql = $departementsM->select()
|
|
->from($departementsM, array('codeRegionInsee'))
|
|
->where('numdep = ?', substr($code,1));
|
|
$departement = $departementsM->fetchRow($sql);
|
|
|
|
return array('R'.$departement->codeRegionInsee);
|
|
|
|
} elseif ( substr($code,0,1)=='C' ) {
|
|
|
|
$codePostauxM = new Application_Model_CodePostaux();
|
|
$sql = $codePostauxM->select()
|
|
->from($codePostauxM, array('Codepos'))
|
|
->where('INSEE = ?', substr($code,1));
|
|
$commune = $codePostauxM->fetchRow($sql);
|
|
|
|
$departement = 'D'.substr($commune->Codepos,0,2);
|
|
$region = $this->getGeoParent($departement);
|
|
|
|
return array_merge(array($departement), $region);
|
|
}
|
|
|
|
return array();
|
|
}
|
|
|
|
|
|
/* Forme Juridique */
|
|
public function juridiqueAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$fields = new Scores_Fields();
|
|
$val = $fields->getCritere('cj');
|
|
|
|
$valuesChecked = array();
|
|
$valuesUndetermined = array();
|
|
|
|
if ($val != null){
|
|
$valuesChecked = $val['in'];
|
|
if (count($valuesChecked)>0) {
|
|
foreach($valuesChecked as $value){
|
|
if (strlen($value)>1) {
|
|
$valuesUndetermined = array_merge($valuesUndetermined, array(substr($value,0,1)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$FormeJuridiqueM = new Application_Model_FormeJuridique();
|
|
$sql = $FormeJuridiqueM->select()
|
|
->where('LENGTH(fjCode) = 1')
|
|
->order('fjLibelle ASC');
|
|
$formes = $FormeJuridiqueM->fetchAll($sql)->toArray();
|
|
|
|
$tabFJ = array();
|
|
foreach($formes as $forme) {
|
|
$structure = array(
|
|
'data' => $forme['fjLibelle'],
|
|
'attr' => array( 'id' => $forme['fjCode'] ),
|
|
'state' => 'closed',
|
|
'children' => array(),
|
|
);
|
|
if (in_array($forme['fjCode'], $valuesChecked)){
|
|
$structure['attr']['class'] = 'jstree-checked';
|
|
}
|
|
if (in_array($forme['fjCode'], $valuesUndetermined)){
|
|
$structure['attr']['class'] = 'jstree-undetermined';
|
|
}
|
|
$tabFJ[] = $structure;
|
|
}
|
|
|
|
$key = $this->getRequest()->getParam('key');
|
|
|
|
$this->view->key = $key;
|
|
$this->view->formejuridiques = json_encode($tabFJ);
|
|
}
|
|
|
|
public function juridiqueajaxAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
$request = $this->getRequest();
|
|
$id = $request->getParam('id');
|
|
|
|
$length = strlen($id);
|
|
|
|
$followingLevel = 5;
|
|
if ( $length==1 ) {
|
|
$followingLevel = 2;
|
|
} elseif ( $length==2 ) {
|
|
$followingLevel = 4;
|
|
}
|
|
|
|
$fields = new Scores_Fields();
|
|
$val = $fields->getCritere('cj');
|
|
|
|
$valuesChecked = array();
|
|
$valuesUndetermined = array();
|
|
|
|
if ($val != null){
|
|
$valuesChecked = $val['in'];
|
|
if (count($valuesChecked)>0) {
|
|
foreach($valuesChecked as $value){
|
|
if (strlen($value)>$followingLevel) {
|
|
$valuesUndetermined = array_merge($valuesUndetermined, substr($value,0,$followingLevel));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Zend_Registry::get('firebug')->info($valuesChecked);
|
|
|
|
|
|
if ($length<4) {
|
|
$FormeJuridiqueM = new Application_Model_FormeJuridique();
|
|
$sql = $FormeJuridiqueM->select()
|
|
->where('fjCode LIKE "'.$id.'%"')
|
|
->where('LENGTH(fjCode)=?', $followingLevel);
|
|
$formes = $FormeJuridiqueM->fetchAll($sql)->toArray();
|
|
|
|
$tabFJ = array();
|
|
foreach($formes as $forme) {
|
|
|
|
$data = $forme['fjLibelle'];
|
|
if ( $followingLevel==4 ) {
|
|
$data = $forme['fjLibelle'].' ('.$forme['fjCode'].')';
|
|
}
|
|
|
|
$structure = array(
|
|
'data' => $data,
|
|
'attr' => array( 'id' => $forme['fjCode'] ),
|
|
);
|
|
|
|
if ( $length<2 ) {
|
|
$structure['state'] = 'closed';
|
|
$structure['children'] = array();
|
|
}
|
|
|
|
if (in_array($forme['fjCode'], $valuesChecked)){
|
|
$structure['attr']['class'] = 'jstree-checked';
|
|
}
|
|
if (in_array($forme['fjCode'], $valuesUndetermined)){
|
|
$structure['attr']['class'] = 'jstree-undetermined';
|
|
}
|
|
|
|
$tabFJ[] = $structure;
|
|
}
|
|
echo json_encode($tabFJ);
|
|
}
|
|
}
|
|
}
|