getCritere('adr_cp'); $valuesCheckeds = explode(',', $val); if(count($valuesCheckeds) > 0) { for($i=0;count($valuesCheckeds) > $i;$i++) { $valuesCheckeds[$i] = substr($valuesCheckeds[$i], 1); } } $valuesUndetermined = array(); if($val != null) { $values = explode(',', $val); foreach($values as $valuesChecked) { if(strlen($valuesChecked) == 5) { $dept = substr($valuesChecked, 0, 2); $table = new Table_Departements(); $sql = $table->select()->from('departements', array('codeRegionInsee'))->where('numdep = ?',$dept); $results = $table->fetchAll($sql)->toArray(); foreach($results as $result) { $valuesUndetermined[] = $result['codeRegionInsee']; } } if(substr($valuesChecked, 0, 1) == 'R') { $valuesCheckeds[] = substr($valuesChecked, 1); } else if (substr($valuesChecked, 0, 1) == 'D') { $table = new Table_Departements(); $sql = $table->select()->from('departements', array('codeRegionInsee'))->where('numdep = ?', substr($valuesChecked, 1)); $result = $table->fetchAll($sql)->toArray(); foreach($result as $item) { $valuesUndetermined[] = $item['codeRegionInsee']; } } } } $regionsM = new Table_Regions(); $sql = $regionsM->select()->from('regions'); $regions = $regionsM->fetchAll()->toArray(); $structure = array(); foreach($regions as $region) { $structure = array( 'data' => $region['NCCENR'], 'attr' => array('id' => 'R'.$region['REGION'], 'niveau' => 0), 'state' => 'closed', 'children' => array() ); if(in_array($region['REGION'], $valuesCheckeds)) { $structure['attr']['class'] = 'jstree-checked'; } if(in_array($region['REGION'], $valuesUndetermined)) { $structure['attr']['class'] = 'jstree-undetermined'; } $tabAdrDep[] = $structure; } return (json_encode($tabAdrDep)); } }