odea/application/controllers/ArborescenceController.php

200 lines
5.1 KiB
PHP
Raw Normal View History

2012-02-02 17:29:14 +00:00
<?php
2012-05-02 18:19:07 +00:00
class ArborescenceController extends Zend_Controller_Action
2012-02-02 17:29:14 +00:00
{
2012-02-15 09:25:21 +00:00
/* Nafs */
2012-02-02 17:29:14 +00:00
public function nafAction()
{
$this->_helper->layout()->disableLayout();
2012-05-15 11:38:51 +00:00
$request = $this->getRequest();
2012-02-02 17:29:14 +00:00
$key = $request->getParam('key');
$object = new Object_Naf();
2012-04-12 08:07:35 +00:00
2012-02-02 17:29:14 +00:00
$this->view->key = $key;
$this->view->naf = $object->naf($request->getParam('niveau', 1), $key);
}
public function nafajaxAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
2012-05-02 18:19:07 +00:00
2012-02-02 17:29:14 +00:00
$request = $this->getRequest();
$key = $request->getParam('key');
$object = new Object_Naf();
2012-05-02 18:19:07 +00:00
echo $object->ajax($request->getParam('parent', ''),
$request->getParam('niveau', 1),
2012-02-02 17:29:14 +00:00
$request->getParam('key')
);
}
2012-05-15 15:20:09 +00:00
2012-02-15 09:25:21 +00:00
/* Geographiques */
2012-02-02 17:29:14 +00:00
public function geographiqueAction()
{
$this->_helper->layout()->disableLayout();
2012-05-02 18:19:07 +00:00
2012-02-15 09:25:21 +00:00
$object = new Object_Codepostaux();
$key = $this->getRequest()->getParam('key');
2012-05-02 18:19:07 +00:00
2012-02-15 09:25:21 +00:00
$this->view->key = $key;
$this->view->regions = $object->_getRegions();
2012-02-02 17:29:14 +00:00
}
2012-05-02 18:19:07 +00:00
2012-02-02 17:29:14 +00:00
public function geographiqueajaxAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
2012-05-02 18:19:07 +00:00
2012-02-02 17:29:14 +00:00
$request = $this->getRequest();
$id = $request->getParam('id');
2012-02-15 09:25:21 +00:00
$niveau = $request->getParam('niveau');
$object = new Object_Codepostaux();
2012-05-02 18:19:07 +00:00
2012-02-15 09:25:21 +00:00
if($niveau == 0) {
echo ($object->_getDepartements($id));
} else if ($niveau == 1) {
echo ($object->_getCommunes($id));
2012-02-02 17:29:14 +00:00
}
}
2012-02-15 09:25:21 +00:00
/* Forme Juridique */
public function juridiqueAction()
{
$this->_helper->layout()->disableLayout();
2012-05-02 18:19:07 +00:00
2012-05-15 15:20:09 +00:00
$fields = new Scores_Fields();
$val = $fields->getCritere('cj');
$valuesChecked = array();
$valuesUndetermined = array();
if ($val != null){
$valuesChecked = $val['in'];
Zend_Registry::get('firebug')->info($val);
Zend_Registry::get('firebug')->info($valuesChecked);
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;
}
2012-05-15 11:38:51 +00:00
$key = $this->getRequest()->getParam('key');
2012-05-02 18:19:07 +00:00
2012-05-15 15:20:09 +00:00
$this->view->key = $key;
$this->view->formejuridiques = json_encode($tabFJ);
2012-02-15 09:25:21 +00:00
}
2012-05-02 18:19:07 +00:00
2012-02-15 09:25:21 +00:00
public function juridiqueajaxAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
2012-05-02 18:19:07 +00:00
2012-05-15 15:20:09 +00:00
$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);
}
2012-02-15 09:25:21 +00:00
}
2012-02-02 17:29:14 +00:00
}