Ajout des champs NAFs

This commit is contained in:
Michael RICOIS 2014-07-17 15:29:13 +00:00
parent 3bcf15e2d7
commit 1b6df19364
7 changed files with 144 additions and 47 deletions

View File

@ -87,9 +87,6 @@ class FieldsController extends Zend_Controller_Action
}
// Get level
else {
//Update the level
$level = $level + 1;
$scoresFields = new Scores_Ciblage_FieldList();
$session = new Scores_Ciblage_Session($scoresFields);
$values = $session->getTreeValues($key, $parent, $level);

View File

@ -12,8 +12,12 @@ $("div#<?=$this->key?>").jstree({
'url' : '/fields/tree/key/<?=$this->key?>',
'dataType': 'json',
'data' : function (node) {
console.log(node);
return { 'id' : node.id ? node.id : '', 'level': '' };
var level = 0;
if ( node.id != '#' ) {
console.log(node.li_attr.level);
level = node.li_attr.level ? node.li_attr.level : 0;
}
return { 'id' : node.id ? node.id : '', 'level': level };
},
},
},

View File

@ -8,7 +8,7 @@
<?php echo $this->headScript()?>
</head>
<body>
<div id="wrap">
<div id="wrap" class="clearfix">
<?php echo $this->render('header.phtml')?>
<?php echo $this->layout()->content?>

View File

@ -3,16 +3,18 @@ class Scores_Ciblage_Field_Tree
{
protected $name = null;
protected $data = null;
protected $title = null;
/**
*
* @param string $name
* @param array $data
*/
public function __construct($name, $data)
public function __construct($name, $data, $title)
{
$this->name = $name;
$this->data = $data;
$this->title = $title;
}
public function getHTML($valueSelected = '')
@ -20,7 +22,8 @@ class Scores_Ciblage_Field_Tree
$html = '<div class="row ciblage-tree">' .
'<div class="col-md-12">';
$html.= '<p><a title="" class="btn btn-primary btn-xs" href="/fields/tree" data-treename="'.$this->name.'" data-treekey="'.$this->name.'">Choisir dans une arboresence Région, Département, Ville</a></p>';
$html.= '<p><a title="" class="btn btn-primary btn-xs" href="/fields/tree" data-treename="'.$this->name.'" data-treekey="'.$this->name.'">' .
$this->title . '</a></p>';
$html.= '</div>'.
'</div>';

View File

@ -140,17 +140,28 @@ class Scores_Ciblage_FieldList
'minmax' => 'number',
'activated' => true,
),
'ape_etab' => array(),
'ape_entrep' => array(),
'ape_etab' => array(
'label' => "Activité de l'établissement (Code NAF)",
'desc' => "",
'family' => 'entreprise',
'type' => array(
'tree' => array( 'label' => 'Arborescence', 'title' => "Choisir dans l'arborescence des NAFs" ),
'tag' => array( 'label' => 'Recherche' ),
),
'activated' => true,
),
'ape_entrep' => array(
'label' => "Activité de l'entreprise (Code NAF)",
'desc' => "",
'family' => 'entreprise',
'type' => array(
'tree' => array( 'label' => 'Arborescence', 'title' => "Choisir dans l'arborescence des NAFs" ),
'tag' => array( 'label' => 'Recherche' ),
),
'activated' => true,
),
'NaceEtab' => array(),
'NaceEntrep' => array(),
'age_etab' => array(
'label' => "Age de l'établissement",
'desc' => "Restreindre la sélection suivant l'age des établissements.",
@ -255,7 +266,7 @@ class Scores_Ciblage_FieldList
'desc' => "",
'family' => 'geographique',
'type' => array(
'tree' => array( 'label' => 'Arborescence' ),
'tree' => array( 'label' => 'Arborescence', 'title' => "Choisir dans une arboresence Région, Département, Ville" ),
'tag' => array( 'label' => 'Recherche' ),
),
'activated' => true,
@ -673,7 +684,8 @@ class Scores_Ciblage_FieldList
$field = new Scores_Ciblage_Field_Search($name, $values);
break;
case 'tree':
$field = new Scores_Ciblage_Field_Tree($name, $values);
$title = $label['title'];
$field = new Scores_Ciblage_Field_Tree($name, $values, $title);
break;
case 'tag':
$field = new Scores_Ciblage_Field_Tag($name, $values);
@ -852,7 +864,15 @@ class Scores_Ciblage_FieldList
*/
public function searchValues($key, $query)
{
return $this->searchValuesGeo($query);
switch ($key) {
case 'geo':
return $this->searchValuesGeo($query);
break;
case 'ape_etab':
case 'ape_ent':
return $this->searchValuesNaf($query);
break;
}
}
protected function searchValuesGeo($query)
@ -1072,6 +1092,7 @@ class Scores_Ciblage_FieldList
$structure = array(
'id' => 'R'.$item['REGION'],
'text' => $item['NCCENR'],
'li_attr' => array('data-level' => 1),
'children' => true,
);
$output[] = $structure;
@ -1092,6 +1113,7 @@ class Scores_Ciblage_FieldList
$structure = array(
'id' => 'D'.$item['numdep'],
'text' => $item['libdep'].' ('.$item['numdep'].')',
'li_attr' => array('data-level' => 2),
'children' => true,
);
$output[] = $structure;
@ -1126,7 +1148,7 @@ class Scores_Ciblage_FieldList
* @param string $code
* @return array
*/
public function treeGeoParent($code)
public function treeParentGeo($code)
{
if (substr($code,0,1)=='D') {
@ -1147,7 +1169,7 @@ class Scores_Ciblage_FieldList
$commune = $codePostauxM->fetchRow($sql);
$departement = 'D'.substr($commune->Codepos,0,2);
$region = $this->treeGeoParent($departement);
$region = $this->treeParentGeo($departement);
return array_merge(array($departement), $region);
}
@ -1156,6 +1178,53 @@ class Scores_Ciblage_FieldList
}
public function treeValuesNaf($code = null, $level = 0)
{
$level = $level+1;
$nafM = new Application_Model_CiblageNaf();
$sql = $nafM->select()->where('niveau=?', $level)->order('code ASC');
if ( $level==2 ) {
$sql->where('parent=?', $code);
} elseif ( $level>2 ) {
$sql->where('code LIKE ?', $code.'%');
}
Zend_Registry::get('firebug')->info($sql->__toString());
try {
$result = $nafM->fetchAll($sql)->toArray();
} catch (Zend_Db_Exception $e) {
Zend_Registry::get('firebug')->info($e->getMessage());
}
$output = array();
foreach($result as $item)
{
if ( $item['niveau']==1 ) {
$data = $item['lib'];
} else {
$data = $item['lib'].' ('.$item['code'].')';
}
$children = true;
if ( $level==5 ) {
$children = false;
}
$structure = array(
'id' => $item['code'],
'text' => $data,
'li_attr' => array('level' => $level),
'children' => $children,
);
$output[] = $structure;
}
return $output;
}
public function treeParentNaf()
{
return array();
}
/**
* Get Minimum and Maximum to display in fields

View File

@ -180,26 +180,56 @@ class Scores_Ciblage_Session
{
$values = $this->getSelectedValue($key);
$valuesChecked = $values['in'];
if (count($valuesChecked)>0) {
foreach($valuesChecked as $value) {
if ( substr($value,0,1)!='R' ) {
$valuesUndetermined = array_merge($valuesUndetermined, $this->fields->treeGeoParent($value));
}
}
}
switch ( $key ) {
case 'geo':
$staticValues = $this->fields->treeValuesGeo($code, $level);
Zend_Registry::get('firebug')->info($valuesChecked);
if ( count($staticValues)>0 ) {
foreach ( $staticValues as $i => $value ) {
if (in_array($value['id'], $valuesChecked)){
$staticValues[$i]['state'] = array('selected' => true);
$valuesChecked = $values['in'];
if (count($valuesChecked)>0) {
foreach($valuesChecked as $value) {
if ( substr($value,0,1)!='R' ) {
$valuesUndetermined = array_merge($valuesUndetermined, $this->fields->treeParentGeo($value));
}
}
}
if (in_array($value['id'], $valuesUndetermined)){
$staticValues[$i]['state'] = array('undetermined' => true);
$staticValues = $this->fields->treeValuesGeo($code, $level);
Zend_Registry::get('firebug')->info($valuesChecked);
if ( count($staticValues)>0 ) {
foreach ( $staticValues as $i => $value ) {
if (in_array($value['id'], $valuesChecked)){
$staticValues[$i]['state'] = array('selected' => true);
}
if (in_array($value['id'], $valuesUndetermined)){
$staticValues[$i]['state'] = array('undetermined' => true);
}
}
}
}
break;
case 'ape_ent':
case 'ape_etab':
$valuesChecked = $values['in'];
if (count($valuesChecked)>0) {
foreach($valuesChecked as $value) {
$valuesUndetermined = array_merge($valuesUndetermined, $this->fields->treeParentNaf($value));
}
}
$staticValues = $this->fields->treeValuesNaf($code, $level);
Zend_Registry::get('firebug')->info($valuesChecked);
if ( count($staticValues)>0 ) {
foreach ( $staticValues as $i => $value ) {
if (in_array($value['id'], $valuesChecked)){
$staticValues[$i]['state'] = array('selected' => true);
}
if (in_array($value['id'], $valuesUndetermined)){
$staticValues[$i]['state'] = array('undetermined' => true);
}
}
}
break;
}
return $staticValues;

View File

@ -46,10 +46,6 @@ $(document).ready(function(){
console.log(values);
set(key, values);
});
$('div.ciblage-tagitems').on('click', 'span.label button', function(){
$(this).parent('span.label').remove();
});
$('div.ciblage-tag input[type=text].tag').autocomplete({
minLength:2,
@ -63,10 +59,8 @@ $(document).ready(function(){
select: function( event, ui ) {
if (ui.item.value != '') {
var $items = $(this).parents('div.ciblage-tag').find('div.ciblage-tagitems');
$('<span class="label label-success" data-value="' + ui.item.value + '">' +
ui.item.label +
'<button type="button" class="close" style="float:none;"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' +
'</span>').appendTo($items);
$('<span class="label label-success" style="display:inline-block;" data-value="' +
ui.item.value + '">' + ui.item.label + '</span>').appendTo($items);
}
this.value = '';
return false;