getCritere($key); $valuesChecked = array(); $valuesUndetermined = array(); if ($val != null){ $valuesChecked = explode(',',$val); foreach($valuesChecked as $value){ $valuesUndetermined = array_merge($valuesUndetermined, $this->getNafParent($value, true)); } } $nafM = new Table_Nafs(); $sql = $nafM->select()->where('niveau = ?', $niveau)->order('code ASC'); $result = $nafM->fetchAll($sql)->toArray(); $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; } return (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; } public function ajax($parent, $niveau, $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 = array_merge($valuesUndetermined, $this->getNafParent($value)); } } $niveau++; $nafM = new Table_Nafs(); $sql = $nafM->select(); if (!empty($parent) && $niveau==2) { $sql->where('parent = ?', $parent); } elseif (!empty($parent) && $niveau>2) { $sql->where("code LIKE '".$parent."%'"); } $sql->where('niveau = ?', $niveau)->order('code ASC'); $result = $nafM->fetchAll($sql)->toArray(); $tabNaf = array(); foreach($result as $item){ $structure = array( 'data' => $item['code'].' - '.$item['lib'], 'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']), ); if (in_array($item['code'], $valuesChecked)){ $structure['attr']['class'] = 'jstree-checked'; } if (in_array($item['code'], $valuesUndetermined)){ $structure['attr']['class'] = 'jstree-undetermined'; } if ($niveau<5){ $structure['state'] = 'closed'; $structure['children'] = array(); } $tabNaf[] = $structure; } echo 'cool';exit; return (json_encode($tabNaf)); } }