Arborescence des Nafs sans Ajax
This commit is contained in:
parent
8a27029e42
commit
ed0a2d2f3a
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
class ArborescenceController extends Zend_Controller_Action
|
class ArborescenceController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Enter description here ...
|
* Enter description here ...
|
||||||
@ -17,30 +15,23 @@ class ArborescenceController extends Zend_Controller_Action
|
|||||||
$niveau = $request->getParam('niveau', 1);
|
$niveau = $request->getParam('niveau', 1);
|
||||||
|
|
||||||
$nafM = new Application_Model_Naf();
|
$nafM = new Application_Model_Naf();
|
||||||
|
//Niveau 1
|
||||||
$sql = $nafM->select()->where('niveau = ?', $niveau)->order('code ASC');
|
$sql = $nafM->select()->where('niveau = ?', $niveau)->order('code ASC');
|
||||||
$result = $nafM->fetchAll($sql)->toArray();
|
$result = $nafM->fetchAll($sql)->toArray();
|
||||||
|
|
||||||
$tabNaf = array();
|
$tabNaf = array();
|
||||||
foreach($result as $item){
|
foreach($result as $item){
|
||||||
$tabNaf[] = array(
|
$tabNaf[] = array(
|
||||||
'data' => $item['code'].' - '.$item['lib'],
|
'data' => $item['code'].' - '.$item['lib'],
|
||||||
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
||||||
'state' => 'closed',
|
'state' => 'closed',
|
||||||
'children' => array(),
|
'children' => $this->getNaf(2, $item['code']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->view->assign('naf', json_encode($tabNaf));
|
$this->view->assign('naf', json_encode($tabNaf));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nafajaxAction()
|
protected function getNaf($niveau, $parent = '')
|
||||||
{
|
{
|
||||||
$this->_helper->layout()->disableLayout();
|
|
||||||
$this->_helper->viewRenderer->setNoRender();
|
|
||||||
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$niveau = $request->getParam('niveau', 1);
|
|
||||||
$niveau++;
|
|
||||||
$parent = $request->getParam('parent', '');
|
|
||||||
$nafM = new Application_Model_Naf();
|
$nafM = new Application_Model_Naf();
|
||||||
$sql = $nafM->select();
|
$sql = $nafM->select();
|
||||||
if (!empty($parent) && $niveau==2) {
|
if (!empty($parent) && $niveau==2) {
|
||||||
@ -49,7 +40,6 @@ class ArborescenceController extends Zend_Controller_Action
|
|||||||
$sql->where("code LIKE '".$parent."%'");
|
$sql->where("code LIKE '".$parent."%'");
|
||||||
}
|
}
|
||||||
$sql->where('niveau = ?', $niveau)->order('code ASC');
|
$sql->where('niveau = ?', $niveau)->order('code ASC');
|
||||||
|
|
||||||
$result = $nafM->fetchAll($sql)->toArray();
|
$result = $nafM->fetchAll($sql)->toArray();
|
||||||
$tabNaf = array();
|
$tabNaf = array();
|
||||||
foreach($result as $item){
|
foreach($result as $item){
|
||||||
@ -58,16 +48,16 @@ class ArborescenceController extends Zend_Controller_Action
|
|||||||
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
||||||
);
|
);
|
||||||
if ($niveau<5){
|
if ($niveau<5){
|
||||||
|
$niveau++;
|
||||||
$naf['state'] = 'closed';
|
$naf['state'] = 'closed';
|
||||||
$naf['children'] = array();
|
$naf['children'] = $this->getNaf($niveau, $item['code']);
|
||||||
}
|
}
|
||||||
$tabNaf[] = $naf;
|
$tabNaf[] = $naf;
|
||||||
}
|
}
|
||||||
echo json_encode($tabNaf);
|
return $tabNaf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Enter description here ...
|
* Enter description here ...
|
||||||
|
Loading…
Reference in New Issue
Block a user