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
|
class ArborescenceController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
* Affiche l'arborescence des NAFs de premier niveau
|
||||||
* Enter description here ...
|
|
||||||
*/
|
*/
|
||||||
public function nafAction()
|
public function nafAction()
|
||||||
{
|
{
|
||||||
@ -13,27 +12,67 @@ class ArborescenceController extends Zend_Controller_Action
|
|||||||
$key = $request->getParam('key');
|
$key = $request->getParam('key');
|
||||||
$this->view->assign('key', $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);
|
$niveau = $request->getParam('niveau', 1);
|
||||||
$nafM = new Application_Model_Naf();
|
$nafM = new Application_Model_Naf();
|
||||||
$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(
|
{
|
||||||
|
$structure = 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' => 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));
|
$this->view->assign('naf', json_encode($tabNaf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne l'arborecence des NAFs de niveau supérieur à 1
|
||||||
|
*/
|
||||||
public function nafajaxAction()
|
public function nafajaxAction()
|
||||||
{
|
{
|
||||||
$this->_helper->layout()->disableLayout();
|
$this->_helper->layout()->disableLayout();
|
||||||
$this->_helper->viewRenderer->setNoRender();
|
$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();
|
$request = $this->getRequest();
|
||||||
$niveau = $request->getParam('niveau', 1);
|
$niveau = $request->getParam('niveau', 1);
|
||||||
$niveau++;
|
$niveau++;
|
||||||
@ -50,19 +89,43 @@ class ArborescenceController extends Zend_Controller_Action
|
|||||||
$result = $nafM->fetchAll($sql)->toArray();
|
$result = $nafM->fetchAll($sql)->toArray();
|
||||||
$tabNaf = array();
|
$tabNaf = array();
|
||||||
foreach($result as $item){
|
foreach($result as $item){
|
||||||
$naf = array(
|
$structure = 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']),
|
||||||
);
|
);
|
||||||
if ($niveau<5){
|
if (in_array($item['code'], $valuesChecked)){
|
||||||
$naf['state'] = 'closed';
|
$structure['attr']['class'] = 'jstree-checked';
|
||||||
$naf['children'] = array();
|
|
||||||
}
|
}
|
||||||
$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);
|
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 ...
|
* Enter description here ...
|
||||||
|
@ -11,7 +11,7 @@ $("#<?=$this->key?>").jstree({
|
|||||||
"json_data" : {
|
"json_data" : {
|
||||||
"data" : <?=$this->naf?>,
|
"data" : <?=$this->naf?>,
|
||||||
"ajax" : {
|
"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 }; },
|
"data" : function(n) { return { parent: n.attr ? n.attr("id") : '' , niveau : n.attr ? n.attr("niveau") : 1 }; },
|
||||||
"cache" : true,
|
"cache" : true,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user