Suppression objet
This commit is contained in:
parent
c0c6df3346
commit
5fb0a6c8a0
@ -6,15 +6,52 @@ class ArborescenceController extends Zend_Controller_Action
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$request = $this->getRequest();
|
||||
$key = $request->getParam('key');
|
||||
$niveau = $request->getParam('niveau', 1);
|
||||
|
||||
|
||||
|
||||
|
||||
$key = $request->getParam('key');
|
||||
$object = new Object_Naf();
|
||||
|
||||
$fields = new Scores_Fields();
|
||||
$val = $fields->getCritere($key);
|
||||
$valuesChecked = array();
|
||||
$valuesUndetermined = array();
|
||||
|
||||
if ($val != null){
|
||||
$valuesChecked = $val['in'];
|
||||
if (count($valuesChecked)>0) {
|
||||
foreach($valuesChecked as $value){
|
||||
$valuesUndetermined = array_merge($valuesUndetermined, $this->getNafParent($value, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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)
|
||||
{
|
||||
if ( $item['niveau']==1 ) {
|
||||
$data = $item['lib'];
|
||||
} else {
|
||||
$data = $item['lib'].' ('.$item['code'].')';
|
||||
}
|
||||
|
||||
$structure = array(
|
||||
'data' => $data,
|
||||
'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->key = $key;
|
||||
$this->view->naf = $object->naf($request->getParam('niveau', 1), $key);
|
||||
$this->view->naf = json_encode($tabNaf);
|
||||
}
|
||||
|
||||
public function nafajaxAction()
|
||||
@ -22,18 +59,77 @@ class ArborescenceController extends Zend_Controller_Action
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$key = $request->getParam('key');
|
||||
$object = new Object_Naf();
|
||||
$request = $this->getRequest();
|
||||
$key = $request->getParam('key');
|
||||
$niveau = $request->getParam('niveau', 1);
|
||||
$niveau = $niveau + 1;
|
||||
|
||||
echo $object->ajax($request->getParam('parent', ''),
|
||||
$request->getParam('niveau', 1),
|
||||
$request->getParam('key')
|
||||
);
|
||||
//Récupération des valeurs enregistrées en session
|
||||
$fields = new Scores_Fields();
|
||||
$val = $fields->getCritere($key);
|
||||
$valuesChecked = array();
|
||||
|
||||
$valuesUndetermined = array();
|
||||
|
||||
if ($val != null){
|
||||
$valuesChecked = $val['in'];
|
||||
if (count($valuesChecked)>0) {
|
||||
foreach($valuesChecked as $value){
|
||||
$valuesUndetermined = array_merge($valuesUndetermined, $this->getNafParent($value, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$niveau++;
|
||||
$nafM = new Application_Model_Naf();
|
||||
$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 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;
|
||||
}
|
||||
|
||||
|
||||
/* Geographiques */
|
||||
@ -78,8 +174,6 @@ class ArborescenceController extends Zend_Controller_Action
|
||||
|
||||
if ($val != null){
|
||||
$valuesChecked = $val['in'];
|
||||
Zend_Registry::get('firebug')->info($val);
|
||||
Zend_Registry::get('firebug')->info($valuesChecked);
|
||||
if (count($valuesChecked)>0) {
|
||||
foreach($valuesChecked as $value){
|
||||
if (strlen($value)>1) {
|
||||
@ -192,8 +286,3 @@ class ArborescenceController extends Zend_Controller_Action
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
class Object_Formejuridique
|
||||
{
|
||||
protected function _jstree_checked()
|
||||
{
|
||||
//@todo : A faire
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function _jstree_undetermined()
|
||||
{
|
||||
//@todo : A faire
|
||||
return array();
|
||||
}
|
||||
|
||||
public function _getClass($valeur)
|
||||
{
|
||||
if(in_array($valeur, $this->_jstree_checked()))
|
||||
return 'jstree-checked';
|
||||
else if (in_array($valeur, $this->_jstree_undetermined()))
|
||||
return 'jstree-undetermined';
|
||||
}
|
||||
|
||||
public function _getParents()
|
||||
{
|
||||
$formes = new Application_Model_FormeJuridique();
|
||||
$sql = $formes->select()->where('LENGTH(fjCode) = 1');
|
||||
$formes = $formes->fetchAll($sql)->toArray();
|
||||
|
||||
$structure = array();
|
||||
foreach($formes as $forme) {
|
||||
$structure[] = array(
|
||||
'data' => $forme['fjCode'].' : '.$forme['fjLibelle'],
|
||||
'attr' => array( 'id' => $forme['fjCode'], 'class' => $this->_getClass($forme['fjCode']) ),
|
||||
'state' => 'closed',
|
||||
//@todo : Requete Ajax
|
||||
'children' => array($this->_getFils($forme['fjCode'])),
|
||||
);
|
||||
}
|
||||
return json_encode($structure);
|
||||
}
|
||||
|
||||
public function _getFils($fjcode)
|
||||
{
|
||||
$lenth = ((strlen($fjcode) == 2)?4:2);
|
||||
$formes = new Application_Model_FormeJuridique();
|
||||
$sql = $formes->select()->from('formejuridique', array(
|
||||
'size' => new Zend_Db_Expr('LENGTH(fjCode)'),
|
||||
'fjCode',
|
||||
'fjLibelle'))
|
||||
->where('fjCode LIKE "'.$fjcode.'%"')
|
||||
->having('size = ?', $lenth);
|
||||
$formes = $formes->fetchAll($sql)->toArray();
|
||||
$structure = array();
|
||||
foreach($formes as $forme) {
|
||||
$structure = array(
|
||||
'data' => $forme['fjCode'].' : '.$forme['fjLibelle'],
|
||||
'attr' => array( 'id' => $forme['fjCode'], 'class' => $this->_getClass($forme['fjCode']) ),
|
||||
'state' => 'close',
|
||||
'children' => (($lenth < 6)?$this->_getFils($forme['fjCode']):array())
|
||||
);
|
||||
$tabfj[] = $structure;
|
||||
}
|
||||
|
||||
return $tabfj;
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
<?php
|
||||
class Object_Naf
|
||||
{
|
||||
public function naf($niveau, $key)
|
||||
{
|
||||
|
||||
$fields = new Scores_Fields();
|
||||
$val = $fields->getCritere($key);
|
||||
$valuesChecked = array();
|
||||
$valuesUndetermined = array();
|
||||
|
||||
if ($val != null){
|
||||
$valuesChecked = $val['in'];
|
||||
if (count($valuesChecked)>0) {
|
||||
foreach($valuesChecked as $value){
|
||||
$valuesUndetermined = array_merge($valuesUndetermined, $this->getNafParent($value, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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)
|
||||
{
|
||||
if ( $item['niveau']==1 ) {
|
||||
$data = $item['lib'];
|
||||
} else {
|
||||
$data = $item['lib'].' ('.$item['code'].')';
|
||||
}
|
||||
|
||||
$structure = array(
|
||||
'data' => $data,
|
||||
'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
|
||||
$fields = new Scores_Fields();
|
||||
$val = $fields->getCritere($key);
|
||||
$valuesChecked = array();
|
||||
|
||||
$valuesUndetermined = array();
|
||||
|
||||
if ($val != null){
|
||||
$valuesChecked = $val['in'];
|
||||
if (count($valuesChecked)>0) {
|
||||
foreach($valuesChecked as $value){
|
||||
$valuesUndetermined = array_merge($valuesUndetermined, $this->getNafParent($value, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$niveau++;
|
||||
$nafM = new Application_Model_Naf();
|
||||
$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;
|
||||
}
|
||||
return json_encode($tabNaf);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user