Arborescence des Nafs sans Ajax

This commit is contained in:
Michael RICOIS 2012-01-16 16:01:02 +00:00
parent 8a27029e42
commit ed0a2d2f3a

View File

@ -1,8 +1,6 @@
<?php
class ArborescenceController extends Zend_Controller_Action
{
/**
*
* Enter description here ...
@ -17,30 +15,23 @@ class ArborescenceController extends Zend_Controller_Action
$niveau = $request->getParam('niveau', 1);
$nafM = new Application_Model_Naf();
//Niveau 1
$sql = $nafM->select()->where('niveau = ?', $niveau)->order('code ASC');
$result = $nafM->fetchAll($sql)->toArray();
$tabNaf = array();
foreach($result as $item){
$tabNaf[] = array(
'data' => $item['code'].' - '.$item['lib'],
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
'state' => 'closed',
'children' => array(),
'children' => $this->getNaf(2, $item['code']),
);
}
$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();
$sql = $nafM->select();
if (!empty($parent) && $niveau==2) {
@ -49,7 +40,6 @@ class ArborescenceController extends Zend_Controller_Action
$sql->where("code LIKE '".$parent."%'");
}
$sql->where('niveau = ?', $niveau)->order('code ASC');
$result = $nafM->fetchAll($sql)->toArray();
$tabNaf = array();
foreach($result as $item){
@ -58,16 +48,16 @@ class ArborescenceController extends Zend_Controller_Action
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
);
if ($niveau<5){
$niveau++;
$naf['state'] = 'closed';
$naf['children'] = array();
$naf['children'] = $this->getNaf($niveau, $item['code']);
}
$tabNaf[] = $naf;
}
echo json_encode($tabNaf);
return $tabNaf;
}
/**
*
* Enter description here ...