Tag and Tree fields
This commit is contained in:
parent
6252fb763e
commit
891ccb5d19
@ -34,236 +34,61 @@ class FieldsController extends Zend_Controller_Action
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage tag
|
||||
*/
|
||||
public function tagAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$request = $this->getRequest();
|
||||
|
||||
//Nom de la clé de ciblage
|
||||
$name = $request->getParam('name');
|
||||
//Clé pour le lancement de la fonction de recherche
|
||||
$key = $request->getParam('key');
|
||||
//Query
|
||||
$q = strtolower(trim($request->getParam('q')));
|
||||
|
||||
$scoresFields = new Scores_Ciblage_FieldList();
|
||||
$result = $scoresFields->getItemValues($name);
|
||||
|
||||
$values = array();
|
||||
foreach ( $result as $k => $v ) {
|
||||
$values[] = array(
|
||||
'label' => $v,
|
||||
'value' => $k,
|
||||
);
|
||||
$values = $scoresFields->searchValues($name, $q);
|
||||
Zend_Registry::get('firebug')->info($values);
|
||||
if (count($values) == 0) {
|
||||
$values[] = array('label' => 'Aucun résultat.', 'value' => '');
|
||||
}
|
||||
$this->view->values = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage autocomplete
|
||||
* Manage Tree
|
||||
*/
|
||||
public function autocompleteAction()
|
||||
public function treeAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$request = $this->getRequest();
|
||||
$name = $request->getParam('name');
|
||||
$q = strtolower($request->getParam('q'));
|
||||
|
||||
$output = array();
|
||||
$request = $this->getRequest();
|
||||
$key = $request->getParam('key');
|
||||
$this->view->key = $key;
|
||||
|
||||
switch ($name) {
|
||||
case 'ape_etab':
|
||||
case 'ape_entrep':
|
||||
/**
|
||||
* @todo : Ajouter la recherche par code
|
||||
*/
|
||||
$queries = explode(' ', $q);
|
||||
$separator = ' , ';
|
||||
$table = new Application_Model_CiblageNaf();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} elseif ($i < count($queries)) {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(lib) ".$where);
|
||||
}
|
||||
$sql->where('niveau = 5');
|
||||
$parent = $request->getParam('id');
|
||||
$level = $request->getParam('level');
|
||||
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->lib . $separator . $item->code,
|
||||
'value' => $item->code
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'geo':
|
||||
|
||||
//Replace characters ' and - in space
|
||||
$q = preg_replace("/['-]/", ' ', $q);
|
||||
|
||||
//Remove characters
|
||||
$q = preg_replace("/^[a-z]\s/i", '', $q);
|
||||
|
||||
//Detect if we have string
|
||||
if ( preg_match("/[a-zA-Z]+/", $q) )
|
||||
{
|
||||
$queries = explode(' ', $q);
|
||||
Zend_Registry::get('firebug')->info($queries);
|
||||
//Région
|
||||
$table = new Application_Model_CiblageRegions();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(NC) ".$where);
|
||||
}
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->NCCENR . ' (Région)',
|
||||
'value' => 'R'.$item->REGION
|
||||
);
|
||||
}
|
||||
|
||||
//Département
|
||||
$table = new Application_Model_CiblageDepartements();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(libdep) ".$where);
|
||||
}
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->libdep . ' (Département)',
|
||||
'value' => 'D'.$item->numdep
|
||||
);
|
||||
}
|
||||
|
||||
//Ville
|
||||
$table = new Application_Model_CiblageCodePostaux();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(Commune) ".$where);
|
||||
}
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->Commune . ', '. $item->Codepos .' (Ville)',
|
||||
'value' => 'C'.$item->INSEE
|
||||
);
|
||||
}
|
||||
|
||||
} elseif ( preg_match('/[0-9]{1,5}/', $q) ) {
|
||||
|
||||
//Code Département
|
||||
if (strlen($q)==2) {
|
||||
$table = new Application_Model_CiblageDepartements();
|
||||
$sql = $table->select()->where('numdep=?', $q);
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->libdep . ' (Département)',
|
||||
'value' => 'D'.$item->numdep
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Code Postal
|
||||
$table = new Application_Model_CiblageCodePostaux();
|
||||
$sql = $table->select()->where('Codepos LIKE "'.$q.'%"');
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->Commune . ', '. $item->Codepos .' (Ville)',
|
||||
'value' => 'C'.$item->INSEE
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case 'cj':
|
||||
$table = new Application_Model_CiblageFormeJuridique();
|
||||
$separator = ' , ';
|
||||
$sql = $table->select();
|
||||
|
||||
$queries = explode(' ', $q);
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>3) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where('LOWER(fjLibelle) '.$where);
|
||||
}
|
||||
$sql->where('LENGTH(fjCode) = 4');
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->fjLibelle . $separator . $item->fjCode,
|
||||
'value' => $item->fjCode
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Init
|
||||
if ( $parent === null ) {
|
||||
$this->view->init = true;
|
||||
$scoresFields = new Scores_Ciblage_FieldList();
|
||||
$values = $scoresFields->treeValues($key, $parent, $level);
|
||||
$this->view->values = $values;
|
||||
}
|
||||
//No results
|
||||
if (count($output) == 0) {
|
||||
$output[] = array('label' => 'Aucun résultat.', 'value' => '');
|
||||
// Get level
|
||||
else {
|
||||
|
||||
$level = $level + 1;
|
||||
|
||||
$scoresFields = new Scores_Ciblage_FieldList();
|
||||
$values = $scoresFields->treeValues($key, $parent, $level);
|
||||
$this->view->values = $values;
|
||||
|
||||
}
|
||||
$this->view->assign('output', $output);
|
||||
|
||||
}
|
||||
|
||||
public function checkvalue(){}
|
||||
|
||||
}
|
@ -1 +0,0 @@
|
||||
<?=json_encode($this->output)?>
|
28
application/views/default/scripts/fields/tree.phtml
Normal file
28
application/views/default/scripts/fields/tree.phtml
Normal file
@ -0,0 +1,28 @@
|
||||
<?php if ( $this->init) {?>
|
||||
|
||||
<div id="<?=$this->key?>" class="jstree jstree-default" style="overflow:auto;"></div>
|
||||
<script>
|
||||
$("div#<?=$this->key?>").jstree({
|
||||
"themes" : {
|
||||
"theme" : "default",
|
||||
"url" : "/libs/tree/themes/classic/style.css",
|
||||
"dots" : true,
|
||||
"icons" : false,
|
||||
},
|
||||
"plugins" : ["themes", "json_data", "checkbox"],
|
||||
"json_data" : {
|
||||
"data" : <?=json_encode($this->values)?>,
|
||||
"ajax" : {
|
||||
"url" : '<?=$this->url(array('controller'=>'fields', 'action'=>'tree', 'key'=> $this->key))?>',
|
||||
"data" : function(n) { return { id: n.attr ? n.attr("id") : '' , level : n.attr ? n.attr("level") : 1 }; },
|
||||
"cache" : true,
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php } else {?>
|
||||
|
||||
<?=json_encode($this->values)?>
|
||||
|
||||
<?php }?>
|
@ -22,11 +22,11 @@ class Scores_Ciblage_Field_Tag
|
||||
|
||||
$html.= '<div class="form-group">';
|
||||
$html.= '<label class="sr-only">Recherche</label>';
|
||||
$html.= '<input type="text" class="form-control" placeholder="Recherche" data-url="/fields/tag/name/'.$this->name.'">';
|
||||
$html.= '<input type="text" class="form-control tag" placeholder="Recherche" data-tagname="'.$this->name.'" data-tagkey="'.$this->name.'">';
|
||||
$html.= '</div>';
|
||||
|
||||
$html.= '</div>'.
|
||||
'<div class="col-md-5">' . '</div>' .
|
||||
'<div class="col-md-5 ciblage-tag-items" id="tagitems-' . $this->name . '">' . '</div>' .
|
||||
'<div class="col-md-3">' .
|
||||
'<button class="btn btn-primary btn-xs pull-right" type="button" data-ciblagename="'.$this->name.'">Ajouter à la selection</button>' .
|
||||
'</div>'.
|
||||
|
@ -20,7 +20,7 @@ class Scores_Ciblage_Field_Tree
|
||||
$html = '<div class="row ciblage-tree">' .
|
||||
'<div class="col-md-9">';
|
||||
|
||||
$html.= '<p><a href="#">Choisir dans une arboresence Région, Département, Ville</a></p>';
|
||||
$html.= '<p><a title="" href="/fields/tree" data-treename="'.$this->name.'" data-treekey="'.$this->name.'">Choisir dans une arboresence Région, Département, Ville</a></p>';
|
||||
|
||||
$html.= '</div>'.
|
||||
'<div class="col-md-3">' .
|
||||
|
@ -258,10 +258,6 @@ class Scores_Ciblage_FieldList
|
||||
'tree' => array( 'label' => 'Arborescence' ),
|
||||
'tag' => array( 'label' => 'Recherche' ),
|
||||
),
|
||||
/*'sql' => array(
|
||||
'columns' => array('Commune AS label', 'INSEE AS value'),
|
||||
'table' => 'fields_codepostaux',
|
||||
),*/
|
||||
'activated' => true,
|
||||
),
|
||||
|
||||
@ -322,8 +318,6 @@ class Scores_Ciblage_FieldList
|
||||
),
|
||||
'activated' => true,
|
||||
),
|
||||
|
||||
|
||||
'adr_reg' => array(
|
||||
'label' => "Liste de régions",
|
||||
'desc' => "Liste de régions",
|
||||
@ -335,8 +329,6 @@ class Scores_Ciblage_FieldList
|
||||
),
|
||||
'activated' => true,
|
||||
),
|
||||
|
||||
|
||||
'zus' => array(
|
||||
'label' => "Zones Urbaines Sensibles",
|
||||
'desc' => "Restreindre la sélection aux établissements situés en Zone Urbaine Sensible (ou ZUS). Les ZUS sont des territoire infra-urbain défini par les pouvoirs publics français bénéficiant d'aides spécifiques sous forme d'exonérations fiscales et sociales.",
|
||||
@ -385,7 +377,9 @@ class Scores_Ciblage_FieldList
|
||||
'values' => array('1' => 'Oui', '0' => 'Non'),
|
||||
'activated' => true,
|
||||
),
|
||||
|
||||
'cj' => array(),
|
||||
|
||||
'actifEco' => array(
|
||||
'label' => "Établissement économiquement actif",
|
||||
'desc' => "Restreindre la sélection aux établissements économiquement actif/inactifs : Etablissements présumés fermés (vendus sans formalités), Pli Non Distribué (NPAI).",
|
||||
@ -622,6 +616,12 @@ class Scores_Ciblage_FieldList
|
||||
|
||||
public function __construct(){}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $valueSelected
|
||||
* @return boolean|string
|
||||
*/
|
||||
public function getItemHtml($name, $valueSelected = null)
|
||||
{
|
||||
if ( !array_key_exists($name, $this->items) ) {
|
||||
@ -736,26 +736,51 @@ class Scores_Ciblage_FieldList
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getItemsStruct()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown $family
|
||||
* @return multitype:Ambigous
|
||||
*/
|
||||
public function getItemsByFamily($family)
|
||||
{
|
||||
return $this->__items(false, $family);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $withValues
|
||||
* @return multitype:Ambigous
|
||||
*/
|
||||
public function getItems($withValues = false)
|
||||
{
|
||||
return $this->__items($withValues);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown $key
|
||||
* @return multitype:multitype: multitype:string boolean multitype:string boolean multitype:string multitype:string boolean multitype:multitype:string multitype:string boolean multitype:string multitype:string
|
||||
*/
|
||||
public function getItem($key)
|
||||
{
|
||||
return $this->items[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tableaux des éléments internes
|
||||
* @param string $withValues
|
||||
* @param string $family
|
||||
* @return array
|
||||
*/
|
||||
protected function __items($withValues = false, $family = null)
|
||||
{
|
||||
$result = array();
|
||||
@ -809,6 +834,331 @@ class Scores_Ciblage_FieldList
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $query
|
||||
* @return array
|
||||
*/
|
||||
public function searchValues($key, $query)
|
||||
{
|
||||
return $this->searchValuesGeo($query);
|
||||
}
|
||||
|
||||
protected function searchValuesGeo($query)
|
||||
{
|
||||
//Replace characters ' and - in space
|
||||
$query = preg_replace("/['-]/", ' ', $query);
|
||||
|
||||
//Remove characters
|
||||
$query = preg_replace("/^[a-z0-9]\s/i", '', $query);
|
||||
|
||||
//Detect if we have string
|
||||
if ( preg_match("/[a-zA-Z]+/", $query) )
|
||||
{
|
||||
$queries = explode(' ', $query);
|
||||
Zend_Registry::get('firebug')->info($queries);
|
||||
//Région
|
||||
$table = new Application_Model_CiblageRegions();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(NC) ".$where);
|
||||
}
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->NCCENR . ' (Région)',
|
||||
'value' => 'R'.$item->REGION
|
||||
);
|
||||
}
|
||||
|
||||
//Département
|
||||
$table = new Application_Model_CiblageDepartements();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(libdep) ".$where);
|
||||
}
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->libdep . ' (Département)',
|
||||
'value' => 'D'.$item->numdep
|
||||
);
|
||||
}
|
||||
|
||||
//Ville
|
||||
$table = new Application_Model_CiblageCodePostaux();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(Commune) ".$where);
|
||||
}
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->Commune . ', '. $item->Codepos .' (Commune)',
|
||||
'value' => 'C'.$item->INSEE
|
||||
);
|
||||
}
|
||||
|
||||
} elseif ( preg_match('/[0-9]{1,5}/', $q) ) {
|
||||
|
||||
//Code Département
|
||||
if (strlen($q)==2) {
|
||||
$table = new Application_Model_CiblageDepartements();
|
||||
$sql = $table->select()->where('numdep=?', $q);
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->libdep . ' (Département)',
|
||||
'value' => 'D'.$item->numdep
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Code Postal
|
||||
$table = new Application_Model_CiblageCodePostaux();
|
||||
$sql = $table->select()->where('Codepos LIKE "'.$q.'%"');
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->Commune . ', '. $item->Codepos .' (Commune)',
|
||||
'value' => 'C'.$item->INSEE
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function searchValuesCj($query)
|
||||
{
|
||||
$output = array();
|
||||
$table = new Application_Model_CiblageFormeJuridique();
|
||||
$separator = ' , ';
|
||||
$sql = $table->select();
|
||||
|
||||
$queries = explode(' ', $q);
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} else {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>3) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where('LOWER(fjLibelle) '.$where);
|
||||
}
|
||||
$sql->where('LENGTH(fjCode) = 4');
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->fjLibelle . $separator . $item->fjCode,
|
||||
'value' => $item->fjCode
|
||||
);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function searchValuesNaf($query)
|
||||
{
|
||||
/**
|
||||
* @todo : Ajouter la recherche par code
|
||||
*/
|
||||
$queries = explode(' ', $query);
|
||||
$separator = ' , ';
|
||||
$table = new Application_Model_CiblageNaf();
|
||||
$sql = $table->select();
|
||||
if (count($queries)>0) {
|
||||
$where = '';
|
||||
$i = 0;
|
||||
foreach ($queries as $item) {
|
||||
$i++;
|
||||
if (empty($where)) {
|
||||
$op = 'LIKE ';
|
||||
} elseif ($i < count($queries)) {
|
||||
$op = ' OR ';
|
||||
}
|
||||
if (strlen($item)>2) {
|
||||
$where.= $op.'"%'.strtolower($item).'%"';
|
||||
}
|
||||
}
|
||||
$sql->where("LOWER(lib) ".$where);
|
||||
}
|
||||
$sql->where('niveau = 5');
|
||||
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
'label' => $item->lib . $separator . $item->code,
|
||||
'value' => $item->code
|
||||
);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function treeValues($key, $code = null, $level = null)
|
||||
{
|
||||
return $this->treeValuesGeo($code, $level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $level
|
||||
*/
|
||||
protected function treeValuesGeo($code = null, $level = null)
|
||||
{
|
||||
$output = array();
|
||||
if ( empty($level) ) {
|
||||
|
||||
$regionsM = new Application_Model_CiblageRegions();
|
||||
$sql = $regionsM->select()->order('NCCENR ASC');
|
||||
$regions = $regionsM->fetchAll($sql)->toArray();
|
||||
|
||||
foreach($regions as $item) {
|
||||
$structure = array(
|
||||
'data' => $item['NCCENR'],
|
||||
'attr' => array(
|
||||
'id' => 'R'.$item['REGION'],
|
||||
'level' => 0,
|
||||
),
|
||||
'state' => 'closed',
|
||||
'children' => array()
|
||||
);
|
||||
$output[] = $structure;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// R[code] => Régions => recherche département
|
||||
if ( substr($code,0,1)=='R' ) {
|
||||
|
||||
$region = substr($code,1);
|
||||
|
||||
$departementsM = new Application_Model_CiblageDepartements();
|
||||
$sql = $departementsM->select()->where('codeRegionInsee = ?', $region);
|
||||
$departements = $departementsM->fetchAll($sql)->toArray();
|
||||
|
||||
foreach($departements as $item) {
|
||||
$structure = array(
|
||||
'data' => $item['libdep'].' ('.$item['numdep'].')',
|
||||
'attr' => array(
|
||||
'id' => 'D'.$item['numdep'],
|
||||
'level' => 1,
|
||||
),
|
||||
'state' => 'closed',
|
||||
'children' => array()
|
||||
);
|
||||
$output[] = $structure;
|
||||
}
|
||||
}
|
||||
// D[code] => Départements => recherche commune
|
||||
else if ( substr($code,0,1)=='D' ) {
|
||||
|
||||
$departement = substr($id,1);
|
||||
|
||||
$codePostauxM = new Application_Model_CiblageCodePostaux();
|
||||
$sql = $codePostauxM->select()
|
||||
->where('Codepos LIKE ?', $departement.'%')
|
||||
->order('Commune ASC');
|
||||
$communes = $codePostauxM->fetchAll($sql)->toArray();
|
||||
|
||||
foreach($communes as $item) {
|
||||
$structure = array(
|
||||
'data' => $item['Commune'],
|
||||
'attr' => array(
|
||||
'id' => 'C'.$item['INSEE'],
|
||||
'level' => 1,
|
||||
)
|
||||
);
|
||||
$output[] = $structure;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function getGeoParent($code)
|
||||
{
|
||||
if (substr($code,0,1)=='D') {
|
||||
|
||||
$departementsM = new Application_Model_CiblageDepartements();
|
||||
$sql = $departementsM->select()
|
||||
->from($departementsM, array('codeRegionInsee'))
|
||||
->where('numdep = ?', substr($code,1));
|
||||
$departement = $departementsM->fetchRow($sql);
|
||||
|
||||
return array('R'.$departement->codeRegionInsee);
|
||||
|
||||
} elseif ( substr($code,0,1)=='C' ) {
|
||||
|
||||
$codePostauxM = new Application_Model_CiblageCodePostaux();
|
||||
$sql = $codePostauxM->select()
|
||||
->from($codePostauxM, array('Codepos'))
|
||||
->where('INSEE = ?', substr($code,1));
|
||||
$commune = $codePostauxM->fetchRow($sql);
|
||||
|
||||
$departement = 'D'.substr($commune->Codepos,0,2);
|
||||
$region = $this->getGeoParent($departement);
|
||||
|
||||
return array_merge(array($departement), $region);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Minimum and Maximum to display in fields
|
||||
* @param string $key
|
||||
@ -835,7 +1185,6 @@ class Scores_Ciblage_FieldList
|
||||
|
||||
} else {
|
||||
|
||||
//@todo : Faire fichier de cache des minmax
|
||||
$valuesM = new Application_Model_CiblageMinMax();
|
||||
$sql = $valuesM->select()->where('cle=?', $key);
|
||||
try {
|
||||
@ -855,6 +1204,11 @@ class Scores_Ciblage_FieldList
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Valeur de la base de données
|
||||
* @param unknown $key
|
||||
* @return array
|
||||
*/
|
||||
protected function getDbValues($key)
|
||||
{
|
||||
$info = $this->items[$key];
|
||||
@ -889,28 +1243,51 @@ class Scores_Ciblage_FieldList
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifier la valeur
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkValue($key, $value)
|
||||
{
|
||||
$info = $this->items[$key];
|
||||
$staticValuesLabel = $this->getItemValues($key);
|
||||
switch($info['type']) {
|
||||
case 'range':
|
||||
case 'rangedate':
|
||||
if ( floatval($value)>=floatval($staticValuesLabel['min']) && floatval($value)<=floatval($staticValuesLabel['max']) ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$staticValues = array_keys($staticValuesLabel);
|
||||
if ( in_array($value, $staticValues) ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
if ( is_array($info['type']) ) {
|
||||
|
||||
} else {
|
||||
|
||||
$staticValuesLabel = $this->getItemValues($key);
|
||||
switch ( $info['type'] ) {
|
||||
case 'range':
|
||||
case 'rangedate':
|
||||
if ( floatval($value)>=floatval($staticValuesLabel['min']) && floatval($value)<=floatval($staticValuesLabel['max']) ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$staticValues = array_keys($staticValuesLabel);
|
||||
if ( in_array($value, $staticValues) ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function checkValueGeo($key, $value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Labellisé la valeur
|
||||
* @param string $key
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function labelValue($key, $values)
|
||||
{
|
||||
$info = $this->items[$key];
|
||||
@ -935,6 +1312,11 @@ class Scores_Ciblage_FieldList
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function labelValueDetail($key, $value)
|
||||
{
|
||||
|
||||
|
@ -53,64 +53,81 @@ $(document).ready(function(){
|
||||
values[1] = moment(get[1], "DD/MM/YYYY").format("YYYYMMDD");
|
||||
set(key, values);
|
||||
});
|
||||
|
||||
$('input[type=text].autocomplete').bind('keydown', function( event ) {
|
||||
if ( event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active ) {
|
||||
event.preventDefault();
|
||||
|
||||
$('div.ciblage-tag button').click(function(e){
|
||||
e.preventDefault();
|
||||
var key = $(this).data('ciblagename');
|
||||
var list = $('#tagitems-'+key).find('span.label');
|
||||
var values = [];
|
||||
if (list.length>0) {
|
||||
list.each(function(){
|
||||
values.push($(this).data('value'));
|
||||
});
|
||||
}
|
||||
}).autocomplete({
|
||||
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,
|
||||
delay: 500,
|
||||
source: function(request, response) {
|
||||
var val = extractLast( request.term );
|
||||
$.getJSON('/fields/autocomplete', { q: val, name: this.element.attr('name') }, function(data) {
|
||||
$.getJSON('/fields/tag', { q: request.term, name: this.element.data('tagname'), key: this.element.data('tagkey') }, function(data) {
|
||||
response(data);
|
||||
});
|
||||
},
|
||||
focus: function() { return false; },
|
||||
select: function( event, ui ) {
|
||||
if (ui.item.value != '') {
|
||||
var name = $(this).parent().find('input.criteres').attr('name');
|
||||
var selectObject = $('ul.selectqueries#'+name);
|
||||
var oldhtml = selectObject.html();
|
||||
var newhtml = '<li name="' + ui.item.value + '">' + ui.item.label + '</li>';
|
||||
selectObject.html(oldhtml + newhtml);
|
||||
|
||||
|
||||
}
|
||||
if (ui.item.value != '') {
|
||||
var $items = $(this).parents('div.ciblage-tag').find('div.ciblage-tag-items');
|
||||
$('<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">×</span><span class="sr-only">Close</span></button>' +
|
||||
'</span>').appendTo($items);
|
||||
}
|
||||
this.value = '';
|
||||
return false;
|
||||
},
|
||||
close: function ( event, ui) { this.value = ''; },
|
||||
});
|
||||
|
||||
$('.panel-group').delegate('a.autocomplete', 'click', function(e){
|
||||
e.stopPropagation();
|
||||
var name = $(this).parent().find('input.criteres').attr('name');
|
||||
var ul = $(this).parent().find('ul.selectqueries');
|
||||
var values = new Array();
|
||||
if ($('li', ul).length>0) {
|
||||
$('li', ul).each(function(){
|
||||
values.push($(this).attr('name'));
|
||||
});
|
||||
set(name, values.join(','));
|
||||
}
|
||||
ul.empty();
|
||||
$('div.ciblage-tree a').click(function(e) {
|
||||
e.preventDefault();
|
||||
var title = $(this).attr('title');
|
||||
var href = $(this).attr('href');
|
||||
var name = $(this).data('treename');
|
||||
var key = $(this).data('treekey');
|
||||
var dialogOpts = {
|
||||
bgiframe: true,
|
||||
title: title,
|
||||
width: 900,
|
||||
height: 500,
|
||||
modal: true,
|
||||
open: function(event, ui) {
|
||||
$(this).html('Chargement...');
|
||||
$(this).load(href, { name: name, key: key });
|
||||
},
|
||||
buttons: {
|
||||
Valider: function() {
|
||||
var key = $('div.jstree').attr('id');
|
||||
var elements = [];
|
||||
$('div.jstree').jstree("get_checked").each(function(){
|
||||
elements.push(this.id);
|
||||
});
|
||||
set(key, elements.join(","));
|
||||
$(this).dialog('close');
|
||||
},
|
||||
Fermer: function() { $(this).dialog('close'); }
|
||||
},
|
||||
close: function() { $('#dialogtree').remove(); }
|
||||
};
|
||||
$('<div id="dialogtree"></div>').dialog(dialogOpts);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.panel-group').delegate('a.autocompleteEx', 'click', function(e){
|
||||
e.stopPropagation();
|
||||
var name = $(this).parent().find('input.criteres').attr('name');
|
||||
var ul = $(this).parent().find('ul.selectqueries');
|
||||
var values = new Array();
|
||||
if ($('li', ul).length>0) {
|
||||
$('li', ul).each(function(){
|
||||
values.push($(this).attr('name'));
|
||||
});
|
||||
set(name, values.join(','), 1);
|
||||
}
|
||||
ul.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function set(key, value, ex) {
|
||||
@ -135,12 +152,4 @@ function set(key, value, ex) {
|
||||
$('div#actionMessage').html('<div class="alert alert-danger"><strong>Erreur !</strong> Un problème inconnu est survenu.</div>');
|
||||
isCount = false;
|
||||
});
|
||||
}
|
||||
|
||||
function split( val ) {
|
||||
return val.split( /,\s*/ );
|
||||
}
|
||||
|
||||
function extractLast( term ) {
|
||||
return split( term ).pop();
|
||||
}
|
@ -44,4 +44,9 @@ code {
|
||||
|
||||
#panel div.alert {
|
||||
margin-bottom:0 !important;
|
||||
}
|
||||
|
||||
div.ciblage-tag-items span.label {
|
||||
display:inline-block;
|
||||
margin:2px;
|
||||
}
|
Loading…
Reference in New Issue
Block a user