Gestion arborescence juridique

This commit is contained in:
Michael RICOIS 2012-05-15 15:20:09 +00:00
parent b939e9604e
commit 12a1930b1c
4 changed files with 305 additions and 105 deletions

View File

@ -32,6 +32,10 @@ class ArborescenceController extends Zend_Controller_Action
);
}
/* Geographiques */
public function geographiqueAction()
{
@ -66,22 +70,126 @@ class ArborescenceController extends Zend_Controller_Action
{
$this->_helper->layout()->disableLayout();
$object = new Object_Formejuridique();
$fields = new Scores_Fields();
$val = $fields->getCritere('cj');
$valuesChecked = array();
$valuesUndetermined = array();
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) {
$valuesUndetermined = array_merge($valuesUndetermined, array(substr($value,0,1)));
}
}
}
}
$FormeJuridiqueM = new Application_Model_FormeJuridique();
$sql = $FormeJuridiqueM->select()
->where('LENGTH(fjCode) = 1')
->order('fjLibelle ASC');
$formes = $FormeJuridiqueM->fetchAll($sql)->toArray();
$tabFJ = array();
foreach($formes as $forme) {
$structure = array(
'data' => $forme['fjLibelle'],
'attr' => array( 'id' => $forme['fjCode'] ),
'state' => 'closed',
'children' => array(),
);
if (in_array($forme['fjCode'], $valuesChecked)){
$structure['attr']['class'] = 'jstree-checked';
}
if (in_array($forme['fjCode'], $valuesUndetermined)){
$structure['attr']['class'] = 'jstree-undetermined';
}
$tabFJ[] = $structure;
}
$key = $this->getRequest()->getParam('key');
$this->view->key = $key;
$this->view->formejuridiques = $object->_getParents();
$this->view->key = $key;
$this->view->formejuridiques = json_encode($tabFJ);
}
public function juridiqueajaxAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$object = new Object_Formejuridique();
$request = $this->getRequest();
$id = $request->getParam('id');
echo $object->_getFils($id);
$request = $this->getRequest();
$id = $request->getParam('id');
$length = strlen($id);
$followingLevel = 5;
if ( $length==1 ) {
$followingLevel = 2;
} elseif ( $length==2 ) {
$followingLevel = 4;
}
$fields = new Scores_Fields();
$val = $fields->getCritere('cj');
$valuesChecked = array();
$valuesUndetermined = array();
if ($val != null){
$valuesChecked = $val['in'];
if (count($valuesChecked)>0) {
foreach($valuesChecked as $value){
if (strlen($value)>$followingLevel) {
$valuesUndetermined = array_merge($valuesUndetermined, substr($value,0,$followingLevel));
}
}
}
}
Zend_Registry::get('firebug')->info($valuesChecked);
if ($length<4) {
$FormeJuridiqueM = new Application_Model_FormeJuridique();
$sql = $FormeJuridiqueM->select()
->where('fjCode LIKE "'.$id.'%"')
->where('LENGTH(fjCode)=?', $followingLevel);
$formes = $FormeJuridiqueM->fetchAll($sql)->toArray();
$tabFJ = array();
foreach($formes as $forme) {
$data = $forme['fjLibelle'];
if ( $followingLevel==4 ) {
$data = $forme['fjLibelle'].' ('.$forme['fjCode'].')';
}
$structure = array(
'data' => $data,
'attr' => array( 'id' => $forme['fjCode'] ),
);
if ( $length<2 ) {
$structure['state'] = 'closed';
$structure['children'] = array();
}
if (in_array($forme['fjCode'], $valuesChecked)){
$structure['attr']['class'] = 'jstree-checked';
}
if (in_array($forme['fjCode'], $valuesUndetermined)){
$structure['attr']['class'] = 'jstree-undetermined';
}
$tabFJ[] = $structure;
}
echo json_encode($tabFJ);
}
}
}

View File

@ -1 +1,18 @@
<?php
<div>
<ul>
<li>Champs de sélection simple
<p>Texte</p>
</li>
<li>
Champs de sélection multiple
<p>Texte</p>
</li>
<li>Arborescence
<p>Texte</p>
</li>
</ul>
</div>

View File

@ -185,96 +185,6 @@ class Ciblage
}
}
protected function getChildNaf($list)
{
$lastLevel = array();
if ( count($list)>0 ) {
$nafM = new Application_Model_Naf();
foreach ( $list as $item ) {
$childItem = array();
$result = array();
//First code level is letter, length 1
if ( !is_numeric($item) && strlen($item)==1 ) {
$sql = $nafM->select()->from($nafM, array('code'))->where('parent = ?', strtoupper($item));
Zend_Registry::get('firebug')->info($sql->__toString());
$result = $nafM->fetchAll($sql)->toArray();
}
//Other code level is number, length 2 to 5 => go directy to the last level
$sql = $nafM->select()->from($nafM, array('code'))->where('niveau = 5');
if (count($result)>0) {
$countResult = 0;
$where = '';
foreach ( $result as $r ) {
$where.= 'code LIKE "'.$r['code'].'%"';
$countResult++;
if ( count($result)!=$countResult ) $where.= ' OR ';
}
$sql->where($where);
} else {
$sql->where('code LIKE "'.$item.'%"');
}
Zend_Registry::get('firebug')->info($sql->__toString());
$result = $nafM->fetchAll($sql)->toArray();
if ( count($result)>0 ) {
foreach ( $result as $i ) {
$lastLevel[] = $i['code'];
}
}
}
}
return $lastLevel;
}
/**
*
* @param array $value
* @return string
*/
protected function transformNAF($value)
{
//Search children for all item given
$valueIn = $valueEx = array();
if ( array_key_exists('in', $value) && is_array($value['in']) && count($value['in'])>0 ) {
$valueIn = $this->getChildNaf($value['in']);
}
if ( array_key_exists('ex', $value) && is_array($value['ex']) && count($value['ex'])>0 ) {
$valueEx = $this->getChildNaf($value['ex']);
}
//Construct alpha request for sphinx
$req = '';
if ( count($valueIn)>0 ) {
$req.= '('.implode('|', $valueIn).')';
}
if ( count($valueEx)>0 ) {
if (empty($req)) {
//Get all NAFs and remove excluded
$nafM = new Application_Model_Naf();
$sql = $nafM->select()->from($nafM, array('code'))->where('niveau = 5');
$allnaf = $nafM->fetchAll()->toArray();
$value = array_diff($allnaf, $valueEx);
$req.= '('.implode('|', $value).')';
} else {
//Simply exclude
$req.= ' -('.implode('|', $valueEx).')';
}
}
return $req;
}
/**
*
* @param unknown_type $value
@ -672,9 +582,101 @@ class Ciblage
}
}
/**
* Get the last child of NAF in the tree
* @param unknown_type $list
*/
protected function getChildNaf($list)
{
$lastLevel = array();
if ( count($list)>0 ) {
$nafM = new Application_Model_Naf();
foreach ( $list as $item ) {
$childItem = array();
$result = array();
//First code level is letter, length 1
if ( !is_numeric($item) && strlen($item)==1 ) {
$sql = $nafM->select()->from($nafM, array('code'))->where('parent = ?', strtoupper($item));
Zend_Registry::get('firebug')->info($sql->__toString());
$result = $nafM->fetchAll($sql)->toArray();
}
//Other code level is number, length 2 to 5 => go directy to the last level
$sql = $nafM->select()->from($nafM, array('code'))->where('niveau = 5');
if (count($result)>0) {
$countResult = 0;
$where = '';
foreach ( $result as $r ) {
$where.= 'code LIKE "'.$r['code'].'%"';
$countResult++;
if ( count($result)!=$countResult ) $where.= ' OR ';
}
$sql->where($where);
} else {
$sql->where('code LIKE "'.$item.'%"');
}
Zend_Registry::get('firebug')->info($sql->__toString());
$result = $nafM->fetchAll($sql)->toArray();
if ( count($result)>0 ) {
foreach ( $result as $i ) {
$lastLevel[] = $i['code'];
}
}
}
}
return $lastLevel;
}
/**
* Make the string request of NAFs
* @param array $value
* @return string
*/
protected function transformNAF($value)
{
//Search children for all item given
$valueIn = $valueEx = array();
if ( array_key_exists('in', $value) && is_array($value['in']) && count($value['in'])>0 ) {
$valueIn = $this->getChildNaf($value['in']);
}
if ( array_key_exists('ex', $value) && is_array($value['ex']) && count($value['ex'])>0 ) {
$valueEx = $this->getChildNaf($value['ex']);
}
//Construct alpha request for sphinx
$req = '';
if ( count($valueIn)>0 ) {
$req.= '('.implode('|', $valueIn).')';
}
if ( count($valueEx)>0 ) {
if (empty($req)) {
//Get all NAFs and remove excluded
$nafM = new Application_Model_Naf();
$sql = $nafM->select()->from($nafM, array('code'))->where('niveau = 5');
$allnaf = $nafM->fetchAll()->toArray();
$value = array_diff($allnaf, $valueEx);
$req.= '('.implode('|', $value).')';
} else {
//Simply exclude
$req.= ' -('.implode('|', $valueEx).')';
}
}
return $req;
}
/**
*
* @param unknown_type $value
* @param array $value
*/
protected function ape_etab($value)
{
@ -682,14 +684,85 @@ class Ciblage
$this->setAlpha('ape_etab', $req);
}
/**
*
* @param array $value
*/
protected function ape_entrep($value)
{
$req = $this->transformNAF($value);
$this->setAlpha('ape_entrep', $req);
}
/**
* Add geographic filter
* R[code] => Region (Region need to be transform as Departements)
* D[code] => Departement
* C[code] => Code Commune Insee
* @param array $value
*/
protected function geo($value)
{
}
protected function getChildCJ($list)
{
$lastLevel = array();
if ( count($list)>0 ) {
foreach ( $list as $item ) {
$childItem = array();
$result = array();
$fjM = new Application_Model_FormeJuridique();
//Only code with a length between 1 and 3
if ( strlen($item)<4 ) {
$sql = $fjM->select()->from($fjM, array('fjCode'))
->where('fjCode LIKE "'.$fjcode.'%"')
->where('LENGTH(fjCode)=4');
$result = $fjM->fetchAll($sql)->toArray();
if ( count($result)>0 ) {
foreach ( $result as $i ) {
$lastLevel[] = $i['fjCode'];
}
}
} else {
$lastLevel[] = $item;
}
}
}
return $lastLevel;
}
/**
* Add filter for forme juridique
* @param array $value
*/
protected function cj($value)
{
//Search children for all item given
$valueIn = $valueEx = array();
if ( array_key_exists('in', $value) && is_array($value['in']) && count($value['in'])>0 ) {
$valueIn = $this->getChildCJ($value['in']);
}
if ( array_key_exists('ex', $value) && is_array($value['ex']) && count($value['ex'])>0 ) {
$valueEx = $this->getChildCJ($value['ex']);
}
if ( count($valueIn)>0 ) {
Zend_Registry::get('firebug')->info($valueIn);
$this->setFilter('cj', $valueIn);
}
if ( count($valueEx)>0 ) {
$this->setFilter('cj', $valueEx, true);
}
}
}

View File

@ -716,10 +716,12 @@ class Scores_Fields
$value = $matches[1];
}
//Add value to the existing
if ($ex) {
$value = array_merge($this->ciblage[$key]['ex'], $value);
} else {
$value = array_merge($this->ciblage[$key]['in'], $value);
if (array_key_exists($key, $this->ciblage)) {
if ($ex) {
$value = array_merge($this->ciblage[$key]['ex'], $value);
} else {
$value = array_merge($this->ciblage[$key]['in'], $value);
}
}
}
@ -878,7 +880,7 @@ class Scores_Fields
protected function getMinMax($name)
{
$MinMaxM = new Application_Model_MinMax();
$minmax = $table->fetchAll($table->select()->where('cle = ?', $name))->toArray();
$minmax = $MinMaxM->fetchAll($MinMaxM->select()->where('cle = ?', $name))->toArray();
return $minmax;
}