On retrouve les valeurs dans l'arborescence des NAFs
This commit is contained in:
parent
f01ba975c7
commit
1a7e1a113b
@ -2,8 +2,7 @@
|
||||
class ArborescenceController extends Zend_Controller_Action
|
||||
{
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* Affiche l'arborescence des NAFs de premier niveau
|
||||
*/
|
||||
public function nafAction()
|
||||
{
|
||||
@ -13,27 +12,67 @@ class ArborescenceController extends Zend_Controller_Action
|
||||
$key = $request->getParam('key');
|
||||
$this->view->assign('key', $key);
|
||||
|
||||
//Récupération des valeurs enregistrées en session
|
||||
require_once 'Scores/SessionCiblage.php';
|
||||
$sessionCiblage = new SessionCiblage();
|
||||
$val = $sessionCiblage->getCritere($key);
|
||||
$valuesChecked = array();
|
||||
$valuesUndetermined = array();
|
||||
if ($val != null){
|
||||
$valuesChecked = explode(',',$val);
|
||||
foreach($valuesChecked as $value){
|
||||
$valuesUndetermined = $this->getNafParent($value, true);
|
||||
}
|
||||
}
|
||||
|
||||
$niveau = $request->getParam('niveau', 1);
|
||||
$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){
|
||||
$tabNaf[] = array(
|
||||
foreach($result as $item)
|
||||
{
|
||||
$structure = array(
|
||||
'data' => $item['code'].' - '.$item['lib'],
|
||||
'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->assign('naf', json_encode($tabNaf));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne l'arborecence des NAFs de niveau supérieur à 1
|
||||
*/
|
||||
public function nafajaxAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$key = $request->getParam('key');
|
||||
|
||||
//Récupération des valeurs enregistrées en session
|
||||
require_once 'Scores/SessionCiblage.php';
|
||||
$sessionCiblage = new SessionCiblage();
|
||||
$val = $sessionCiblage->getCritere($key);
|
||||
$valuesChecked = array();
|
||||
$valuesUndetermined = array();
|
||||
if ($val != null){
|
||||
$valuesChecked = explode(',',$val);
|
||||
foreach($valuesChecked as $value){
|
||||
$valuesUndetermined = $this->getNafParent($value);
|
||||
}
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
$niveau = $request->getParam('niveau', 1);
|
||||
$niveau++;
|
||||
@ -50,19 +89,43 @@ class ArborescenceController extends Zend_Controller_Action
|
||||
$result = $nafM->fetchAll($sql)->toArray();
|
||||
$tabNaf = array();
|
||||
foreach($result as $item){
|
||||
$naf = array(
|
||||
$structure = array(
|
||||
'data' => $item['code'].' - '.$item['lib'],
|
||||
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
||||
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
|
||||
);
|
||||
if ($niveau<5){
|
||||
$naf['state'] = 'closed';
|
||||
$naf['children'] = array();
|
||||
if (in_array($item['code'], $valuesChecked)){
|
||||
$structure['attr']['class'] = 'jstree-checked';
|
||||
}
|
||||
$tabNaf[] = $naf;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
|
@ -11,7 +11,7 @@ $("#<?=$this->key?>").jstree({
|
||||
"json_data" : {
|
||||
"data" : <?=$this->naf?>,
|
||||
"ajax" : {
|
||||
"url" : '<?=$this->url(array('controller'=>'arborescence', 'action'=>'nafajax'))?>',
|
||||
"url" : '<?=$this->url(array('controller'=>'arborescence', 'action'=>'nafajax', 'key'=> $this->key))?>',
|
||||
"data" : function(n) { return { parent: n.attr ? n.attr("id") : '' , niveau : n.attr ? n.attr("niveau") : 1 }; },
|
||||
"cache" : true,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user