From c343c5197a6ee4132f4d2cdd8c9ae6d854b40e85 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 23 May 2012 13:35:29 +0000 Subject: [PATCH 1/5] Change SQL request to display preview --- application/controllers/ComptageController.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/application/controllers/ComptageController.php b/application/controllers/ComptageController.php index ae84d231..b074d3d3 100644 --- a/application/controllers/ComptageController.php +++ b/application/controllers/ComptageController.php @@ -222,8 +222,18 @@ class ComptageController extends Zend_Controller_Action } $sql = $dbMetier->select() - ->from('etablissements_act', $extractSql) - ->where('concat(siren, nic) IN('.join(',', $sirets).')'); + ->from('etablissements_act', $extractSql); + + $i = 0; + $where = ''; + foreach($sirets as $siret) { + if ($i>0) { + $where.=' OR '; + } + $where.= "(siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."')"; + $i++; + } + $sql->where($where); $result = $dbMetier->fetchAll($sql); $liste = array(); From a6f17922bdd245e3c4f2c385b5e3ee374138858f Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 23 May 2012 14:07:24 +0000 Subject: [PATCH 2/5] Modification du batch d'enrichissement --- batch/enrichissement.php | 208 +++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 106 deletions(-) diff --git a/batch/enrichissement.php b/batch/enrichissement.php index eddc0d0b..e51789a9 100644 --- a/batch/enrichissement.php +++ b/batch/enrichissement.php @@ -45,16 +45,26 @@ if(isset($opts->help) || !isset($opts->id) && !isset($opts->file) ) exit; } +$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/configuration.ini'); + +//MetadataCache pour la base de données +$frontendOptions = array( + 'lifetime' => 14400, + 'automatic_serialization' => true +); +$backendOptions = array(); +$cache = Zend_Cache::factory('Core','Apc', $frontendOptions, $backendOptions); +Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); + //Définition bdd -$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases'); try { - $db = Zend_Db::factory($dbConfig->db); + $db = Zend_Db::factory($config->databases->db); } catch ( Exception $e ) { exit ( $e->getMessage() ); } //Définition bdd metier try { - $dbMetier = Zend_Db::factory($dbConfig->jo); + $dbMetier = Zend_Db::factory($config->databases->jo); } catch ( Exception $e ) { exit ( $e->getMessage() ); } @@ -63,103 +73,107 @@ $liste = array(); if ($opts->id) { - $sql = $db->select() - ->from('enrichissement_identifiants') - ->where('id = ?', intval($opts->id)); - $commande = $db->fetchRow($sql); - $identifiants = json_decode($commande['identifiants'], true); + //Read SIRETs + $commandesM = new Application_Model_EnrichissementIdentifiants($db); + $commande = $commandesM->find(intval($opts->id))->current(); + $identifiants = json_decode($commande->identifiants, true); - $sql = $db->select() - ->from('enrichissement_profils') - ->where('id = ?', $commande['idProfil']); - $profil = $db->fetchRow($sql); - $dataProfil = json_decode($profil['criteres'], true); + //Read profil for data extract + $profilM = new Application_Model_EnrichissementProfils($db); + $profil = $profilM->find(intval($commande->idProfil))->current(); + $dataProfil = json_decode($profil->criteres, true); } else if ($opts->file) { } -if ( count($identifiants)>0 && count($dataProfil)>0 ) +//Something is needed +if ( count($identifiants)==0 || count($dataProfil)==0 ) { + + exit; +} + +//Let's go +$mois = date('Y-m'); + +if(!file_exists($config->path->data.'/'.$mois)) + mkdir($config->path->data.'/'.$mois); + +$path = $config->path->data.'/'.$mois; +$outFile = $profil['login'].'_'.$opts->id.'_'.date('YmdHis').'.csv'; + +require_once 'Scores/Enrichissement.php'; +$dico = new Enrichissement(); +$fields = $dico->getFields(); + +//Entete, Valeur de remplacement et Requete SQL +$tabEntete = array('siren', 'nic'); +$tabEnteteLabel = array('SIREN', 'NIC'); +$sql = 'SELECT LPAD(siren, 9, 000000000) AS siren, LPAD(nic,5,00000) AS nic,'; +foreach ( $dataProfil as $item ) { + //Définition de l'entete + $tabEnteteLabel[] = $fields[$item]['label']; + $tabEntete[] = $item; + + //Construction de la requete SQL + if ( array_key_exists('sql', $fields[$item]) ) { + $sql.= ' '.$fields[$item]['sql'].', '; + } else { + $sql.= ' '.$fields[$item]['column'].' AS '.$item.','; + } +} +//Ajouter le champ presentRcs +$tabEntete[] = 'presentRcs'; +$tabEnteteLabel[] = 'RCS'; +$sql .= ' presentRcs'; + +//Pour chaque identifiant traiter les données +$row = 0; +$fp = fopen($path.'/'.$outFile, 'w'); +//Ecrire l'entete +if (count($tabEnteteLabel)>0){ + fputcsv($fp, $tabEnteteLabel, ',', '"'); +} +//Mise à jour des éléments +if ($opts->id) { + $commandesM->update('enrichissement_identifiants', array( + 'dateStart'=>date('Y-m-d H:i:s'), + 'fichier' => basename($outFile)), + "id = ".$commande->id); +} + +$model = $sql; +$traite = 0; +//Date de debut de traitement. +$dateStart = date('YmdHms'); +foreach ($identifiants as $siret ) { - $config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/configuration.ini'); - $mois = date('Y-m'); - if(!file_exists($config->path->data.'/'.$mois)) - mkdir($config->path->data.'/'.$mois); - $path = $config->path->data.'/'.$mois; - $outFile = $opts->id.'_'.$profil['login'].'_'.date('YmdHis').'.csv'; - require_once 'Scores/Enrichissement.php'; - $dico = new Enrichissement(); - $fields = $dico->getFields(); - - //Entete, Valeur de remplacement et Requete SQL - $tabEntete = array('siren', 'nic'); - $tabEnteteLabel = array('SIREN', 'NIC'); - $sql = 'SELECT LPAD(siren, 9, 000000000) AS siren, LPAD(nic,5,00000) AS nic,'; - foreach ( $dataProfil as $item ) { - //Définition de l'entete - $tabEnteteLabel[] = $fields[$item]['label']; - $tabEntete[] = $item; - - //Construction de la requete SQL - if ( array_key_exists('sql', $fields[$item]) ) { - $sql.= ' '.$fields[$item]['sql'].', '; - } else { - $sql.= ' '.$fields[$item]['column'].' AS '.$item.','; - } - + $sql = $model.' FROM etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5); + try { + $result = $dbMetier->fetchAll($sql); + $traite++; + } catch(Exception $e) { + echo $sql; } - //Ajouter le champ presentRcs - $tabEntete[] = 'presentRcs'; - $tabEnteteLabel[] = 'RCS'; - $sql .= ' presentRcs'; + $tabData = $result[0]; + //Trier pour la sortie + $tabSortie = array(); + foreach($tabEntete as $key){ + $tabSortie[] = isset($tabData[$key]) ? $tabData[$key] : ''; + } + fputcsv($fp, $tabSortie, ',', '"'); - //Pour chaque identifiant traiter les données - $row = 0; - $fp = fopen($path.'/'.$outFile, 'w'); - //Ecrire l'entete - if (count($tabEnteteLabel)>0){ - fputcsv($fp, $tabEnteteLabel, ',', '"'); + //Mise à jour des lignes traitées dans la base + if ($opts->id) { + $commandesM->update(array('nbLigneTraites'=>$row), "id = ".$commande->id); } - $model = $sql; - $traite = 0; - //Date de debut de traitement. - $dateStart = date('YmdHms'); - foreach ($identifiants as $siret ) - { - $sql = $model.' FROM etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5); - try { - $result = $dbMetier->fetchAll($sql); - $traite++; - } catch(Exception $e) { - echo $sql; - } - $tabData = $result[0]; - //Trier pour la sortie - $tabSortie = array(); - foreach($tabEntete as $key){ - $tabSortie[] = isset($tabData[$key]) ? $tabData[$key] : ''; - } - fputcsv($fp, $tabSortie, ',', '"'); - $row++; - } - //Gestion de l'erreur - $error = 0; - if($traite < $commande['nbLigneTotales']) - $error = 1; - //date de fin de traitement. - $dateStop = date('YmdHms'); - //Update de la ligne dans la base de donnée. - $datas = array( - 'nbLigneTraites' => $traite, - 'dateStart' => $dateStart, - 'dateStop' => $dateStop, - 'error' => $error, - 'fichier' => $outFile - ); - $db->update('enrichissement_identifiants', $datas, 'id = '.$opts->id); - fclose($fp); + $row++; +} +fclose($fp); +if ($opts->id) { + $commandesM->update( array('dateStop' => date('Y-m-d H:i:s')) , "id = ".$commande->id); } @@ -228,22 +242,4 @@ function siretValide($siret) { $estValide = false; } return $estValide; -} - -/** - * writeCSV - * @param array $list - * @param array $entete - * @param string $filename - */ -function writeCSV($list, $entete, $filename) -{ - $fp = fopen($filename, 'w'); - if (count($entete)>0){ - fputcsv($fp, $entete, ',', '"'); - } - foreach ($list as $fields) { - fputcsv($fp, $fields, ',', '"'); - } - fclose($fp); } \ No newline at end of file From 42cf983eb50b21583486c8eebec73c08c0def6f9 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 23 May 2012 19:40:49 +0000 Subject: [PATCH 3/5] Interval works on some fields --- library/Scores/Ciblage.php | 114 ++++++++++++++++++++++-- library/Scores/Fields.php | 13 +-- public/themes/default/scripts/fields.js | 6 +- 3 files changed, 119 insertions(+), 14 deletions(-) diff --git a/library/Scores/Ciblage.php b/library/Scores/Ciblage.php index cb55b083..3a2e14c5 100644 --- a/library/Scores/Ciblage.php +++ b/library/Scores/Ciblage.php @@ -54,6 +54,8 @@ class Ciblage foreach($structure as $key => $valeur) { if ($key!= 'NB' && method_exists($this, $key)) { $this->{$key}($valeur); + } else { + Zend_Registry::get('firebug')->info('KEY:'.$key); } } } @@ -182,7 +184,7 @@ class Ciblage } else { $this->sphinx->SetLimits(0, 1); - Zend_Registry::get('firebug')->info("Sphinx : ".$this->alpha); + //Zend_Registry::get('firebug')->info("Sphinx : ".$this->alpha); $resSphinx = $this->sphinx->Query($this->alpha, $this->index); Zend_Registry::get('firebug')->info($resSphinx); @@ -288,9 +290,24 @@ class Ciblage protected function nbActio($value) { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('nbActio')->current(); + + $valMin = ''; + $valMax = ''; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + if ($min=='' || $max=='') + return; + $this->setFilterRange('nbActio', $min, $max); } } @@ -358,6 +375,87 @@ class Ciblage } } + protected function eff_etab($value) + { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('eff_etab')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + if ( array_key_exists('in', $value) ) { + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + Zend_Registry::get('firebug')->info('eff_etab Min : '.$min.', Max : '.$max); + + if ($min===null || $max===null) + return; + + Zend_Registry::get('firebug')->info('Min : '.$min.', Max : '.$max); + + $this->setFilterRange('eff_etab', $min, $max); + } + } + + protected function eff_entrep($value) + { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('eff_entrep')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + if ( array_key_exists('in', $value) ) { + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + Zend_Registry::get('firebug')->info('Min : '.$min.', Max : '.$max); + + if ($min===null || $max===null) + return; + + $this->setFilterRange('eff_entrep', $min, $max); + } + } + + protected function nbEtab($value) + { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('nbEtab')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + if ( array_key_exists('in', $value) ) { + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + if ($min===null || $max===null) + return; + + Zend_Registry::get('firebug')->info('Min : '.$min.', Max : '.$max); + + $this->setFilterRange('nbEtab', $min, $max); + } + } + + protected function geo_domtom($value) { if( $value['in']==1 ) { @@ -442,6 +540,12 @@ class Ciblage } } + protected function dateImmat($value) + { + + + } + protected function bilType($value) { if ( array_key_exists('in', $value) ) { @@ -609,7 +713,7 @@ class Ciblage //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()); + //Zend_Registry::get('firebug')->info($sql->__toString()); $result = $nafM->fetchAll($sql)->toArray(); } @@ -628,7 +732,7 @@ class Ciblage $sql->where('code LIKE "'.$item.'%"'); } - Zend_Registry::get('firebug')->info($sql->__toString()); + //Zend_Registry::get('firebug')->info($sql->__toString()); $result = $nafM->fetchAll($sql)->toArray(); if ( count($result)>0 ) { diff --git a/library/Scores/Fields.php b/library/Scores/Fields.php index 0538b2a1..c19a5212 100644 --- a/library/Scores/Fields.php +++ b/library/Scores/Fields.php @@ -147,9 +147,8 @@ class Scores_Fields 'activated' => true, ), 'nbActio' => array( - 'label' => 'Nombre d\'actionnaires connus', + 'label' => "Nombre d'actionnaires connus", 'fields' => array( - //@todo : getMinMax 'interval' => array('value' => null) ), 'famille' => 'entreprise', @@ -286,7 +285,7 @@ class Scores_Fields 'activated' => true, ), 'eff_entrep' => array( - 'label' => 'Effectif réel de l\'entreprise', + 'label' => "Effectif réel de l'entreprise", 'fields' => array( 'interval' => array('value' => array('0', '10000000')) ), @@ -294,7 +293,7 @@ class Scores_Fields 'activated' => true, ), 'eff_etab' => array( - 'label' => 'Effectif réel de l\'établissement', + 'label' => "Effectif réel de l'établissement", 'fields' => array( 'interval' => array('value' => array('0', '10000000')) ), @@ -709,7 +708,7 @@ class Scores_Fields $types = array_keys($this->fields[$key]['fields']); - if ( !is_array($value) && !in_array($types[0], array('select', 'checkbox')) ) { + if ( !is_array($value) && !in_array($types[0], array('select', 'checkbox', 'interval')) ) { //Remove all space in string value $value = str_replace(' ', '', $value); //Try to detect separator and transform as array @@ -728,6 +727,10 @@ class Scores_Fields } } + if ($types[0]=='interval') { + $value = explode(',', $value); + } + //Remove duplicate values if (is_array($value) ) { $value = array_unique($value); diff --git a/public/themes/default/scripts/fields.js b/public/themes/default/scripts/fields.js index cd7e6ca0..51fae517 100644 --- a/public/themes/default/scripts/fields.js +++ b/public/themes/default/scripts/fields.js @@ -146,10 +146,8 @@ $(document).ready(function() var key = $(this).attr('id'); //Remove id to find all input value var val1 = $('input[name='+key+'1]').val(); var val2 = $('input[name='+key+'2]').val(); - if(!val1) - val1 = 0; - if(!val2) - val2 = 0; + if(!val1) val1 = ''; + if(!val2) val2 = ''; var values = val1 + ',' + val2; set(key, values); return false; From 5f412b2315078a0834ad26fa684a1c9dfcce37c5 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 24 May 2012 07:34:12 +0000 Subject: [PATCH 4/5] Define min max for interval value --- library/Scores/Ciblage.php | 174 ++++++++++++++++++++++++++----------- 1 file changed, 123 insertions(+), 51 deletions(-) diff --git a/library/Scores/Ciblage.php b/library/Scores/Ciblage.php index 3a2e14c5..b31752ee 100644 --- a/library/Scores/Ciblage.php +++ b/library/Scores/Ciblage.php @@ -290,22 +290,22 @@ class Ciblage protected function nbActio($value) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('nbActio')->current(); - - $valMin = ''; - $valMax = ''; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - if ( array_key_exists('in', $value) ) { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('nbActio')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; - if ($min=='' || $max=='') + if ($min===null || $max===null) return; $this->setFilterRange('nbActio', $min, $max); @@ -315,15 +315,47 @@ class Ciblage protected function nbPart($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('nbPart')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + if ($min===null || $max===null) + return; + $this->setFilterRange('nbPart', $min, $max); } } protected function nbMPubli($value) { - if ( array_key_exists('in', $value) ) { + if ( array_key_exists('in', $value) ) { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('nbMPubli')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + if ($min===null || $max===null) + return; + $this->setFilter('nbMPubli', $value); } } @@ -331,17 +363,47 @@ class Ciblage protected function capital($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('capital')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + if ($min===null || $max===null) + return; + $this->setFilterRange('capital', $min, $max); } } protected function age_entrep($value) { - if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + if ( array_key_exists('in', $value) ) { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('age_entrep')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + if ($min===null || $max===null) + return; + $this->setFilterRange('age_entrep', $min, $max); } } @@ -349,8 +411,23 @@ class Ciblage protected function age_etab($value) { if ( array_key_exists('in', $value) ) { - $min = $value['in'][0]; - $max = $value['in'][1]; + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('age_etab')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + + if ($min===null || $max===null) + return; + $this->setFilterRange('age_etab', $min, $max); } } @@ -377,27 +454,24 @@ class Ciblage protected function eff_etab($value) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('eff_etab')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } if ( array_key_exists('in', $value) ) { - $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; - $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('eff_etab')->current(); - Zend_Registry::get('firebug')->info('eff_etab Min : '.$min.', Max : '.$max); + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } - if ($min===null || $max===null) - return; + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; + $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; - Zend_Registry::get('firebug')->info('Min : '.$min.', Max : '.$max); + if ($min===null || $max===null) + return; $this->setFilterRange('eff_etab', $min, $max); } @@ -431,26 +505,24 @@ class Ciblage protected function nbEtab($value) { - //Read min max - $minmaxM = new Application_Model_MinMax(); - $minmax = $minmaxM->find('nbEtab')->current(); - - $valMin = 0; - $valMax = null; - if ($minmax!==false) { - $valMin = $minmax->min; - $valMax = $minmax->max; - } - if ( array_key_exists('in', $value) ) { + //Read min max + $minmaxM = new Application_Model_MinMax(); + $minmax = $minmaxM->find('nbEtab')->current(); + + $valMin = 0; + $valMax = null; + if ($minmax!==false) { + $valMin = $minmax->min; + $valMax = $minmax->max; + } + $min = ($value['in'][0]=='') ? $valMin : $value['in'][0]; $max = ($value['in'][1]=='') ? $valMax : $value['in'][1]; if ($min===null || $max===null) return; - Zend_Registry::get('firebug')->info('Min : '.$min.', Max : '.$max); - $this->setFilterRange('nbEtab', $min, $max); } } From 5c74b398f5e1b6a4467f536568bee6e2aff164e1 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 24 May 2012 13:43:15 +0000 Subject: [PATCH 5/5] Date interval selection --- application/views/default/helpers/Field.php | 70 +++++++++++++++++++++ library/Scores/Ciblage.php | 15 +++++ library/Scores/Fields.php | 7 ++- public/themes/default/scripts/fields.js | 15 ++++- public/themes/default/styles/main.css | 2 + 5 files changed, 104 insertions(+), 5 deletions(-) diff --git a/application/views/default/helpers/Field.php b/application/views/default/helpers/Field.php index f416d228..ffb59298 100644 --- a/application/views/default/helpers/Field.php +++ b/application/views/default/helpers/Field.php @@ -87,6 +87,12 @@ class Zend_View_Helper_Field extends Zend_View_Helper_Abstract $html.= $this->structureHTML( $label, $this->checkboxHTML($name, $options) + ); + break; + case 'intervalDate': + $html.= $this->structureHTML( + $label, + $this->intervalDateHTML($name, $options) ); break; case 'interval': @@ -204,6 +210,11 @@ class Zend_View_Helper_Field extends Zend_View_Helper_Abstract return ($return); } + /** + * + * @param unknown_type $name + * @param unknown_type $options + */ protected function checkboxHTML($name, $options) { $session = new Scores_Fields(); @@ -271,6 +282,65 @@ class Zend_View_Helper_Field extends Zend_View_Helper_Abstract return $return; } + protected function intervalDateHTML($name, $options) + { + $session = new Scores_Fields(); + $sessionValeur = $session->getCritere($name); + + $return = ''; + + $return.= ''; + $return.= ''; + $return.= ''; + + $return.= ' à '; + + $return.= ''; + $return.= ''; + $return.= ''; + $return .= '
Valider'; + + return $return; + } + + /* Interval */ private function intervalHTML($name, $field) { diff --git a/library/Scores/Ciblage.php b/library/Scores/Ciblage.php index b31752ee..b0d14a6d 100644 --- a/library/Scores/Ciblage.php +++ b/library/Scores/Ciblage.php @@ -279,13 +279,28 @@ class Ciblage //Don't work protected function dateCrea_etab($value) { + if ( array_key_exists('in', $value) ) { + $min = $value['in'][0]; + $max = $value['in'][1]; + + if ($min===null || $max===null) + return; + + $this->setFilterRange('dateCrea_etab', $min, $max); + } } //Don't work protected function dateCrea_ent($value) { + $min = $value['in'][0]; + $max = $value['in'][1]; + if ($min===null || $max===null) + return; + + $this->setFilterRange('dateCrea_ent', $min, $max); } protected function nbActio($value) diff --git a/library/Scores/Fields.php b/library/Scores/Fields.php index c19a5212..9eaa2aa0 100644 --- a/library/Scores/Fields.php +++ b/library/Scores/Fields.php @@ -114,6 +114,7 @@ class Scores_Fields 'famille' => 'entreprise', 'activated' => true, ), + 'nbMPubli' => array( 'label' => 'Marchés publiques remportés', 'fields' => array( @@ -125,7 +126,7 @@ class Scores_Fields 'dateCrea_ent' => array( 'label' => "Date de création de l'entreprise", 'fields' => array( - 'interval' => array('value' => array('0', '1000')) + 'intervalDate' => array('value' => null) ), 'famille' => 'entreprise', 'activated' => true, @@ -133,7 +134,7 @@ class Scores_Fields 'dateCrea_etab' => array( 'label' => "Date de création de l'établissement", 'fields' => array( - 'interval' => array('value' => array('0', '1000')) + 'intervalDate' => array('value' => null ) ), 'famille' => 'entreprise', 'activated' => true, @@ -460,7 +461,7 @@ class Scores_Fields 'dateImmat' => array( 'label' => 'Date d\'immatriculation', 'fields' => array( - 'interval' => array('value' => array('0', '1000')) + 'intervalDate' => array('value' => null) ), 'famille' => 'juridique', 'activated' => true, diff --git a/public/themes/default/scripts/fields.js b/public/themes/default/scripts/fields.js index 51fae517..9623dfbd 100644 --- a/public/themes/default/scripts/fields.js +++ b/public/themes/default/scripts/fields.js @@ -140,10 +140,21 @@ $(document).ready(function() set(obj.attr('name'), obj.val(), 1); }); + $('#tabs').delegate('a.intervalDate', 'click', function(e){ + e.preventDefault(); + var key = $(this).attr('id'); + var val1 = $('select[name='+key+'1_a]').val() + $('select[name='+key+'1_m]').val() + $('select[name='+key+'1_j]').val(); + var val2 = $('select[name='+key+'2_a]').val() + $('select[name='+key+'2_m]').val() + $('select[name='+key+'2_j]').val(); + if(!val1) val1 = ''; + if(!val2) val2 = ''; + var values = val1 + ',' + val2; + set(key, values); + return false; + }); $('#tabs').delegate('a.interval', 'click', function(e){ e.preventDefault(); - var key = $(this).attr('id'); //Remove id to find all input value + var key = $(this).attr('id'); var val1 = $('input[name='+key+'1]').val(); var val2 = $('input[name='+key+'2]').val(); if(!val1) val1 = ''; @@ -156,7 +167,7 @@ $(document).ready(function() //@todo : We have two event bind on each element why ? $('.intervalSelect').change(function(){ - var key = $(this).attr('id'); //Remove id to find all input value + var key = $(this).attr('id'); var number = $(this).attr('number'); if(number == 1) { $('span#'+key).html(' Valider'); diff --git a/public/themes/default/styles/main.css b/public/themes/default/styles/main.css index 7e5e499a..65c85467 100644 --- a/public/themes/default/styles/main.css +++ b/public/themes/default/styles/main.css @@ -319,6 +319,8 @@ ul#fieldsblock li div.fieldgrp div.field input[type="checkbox"] { } ul#fieldsblock li div.fieldgrp div.field select { + font-size: 0.9em; + margin: 2px 0; width:265px; }