Date interval selection

This commit is contained in:
Michael RICOIS 2012-05-24 13:44:37 +00:00
commit 5e00bdf6d5
7 changed files with 419 additions and 137 deletions

View File

@ -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();

View File

@ -89,6 +89,12 @@ class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
$this->checkboxHTML($name, $options)
);
break;
case 'intervalDate':
$html.= $this->structureHTML(
$label,
$this->intervalDateHTML($name, $options)
);
break;
case 'interval':
$html.= $this->structureHTML(
$label,
@ -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.= '<select name="'.$name.'1_j" style="width:40px;">';
for ($i=1;$i<=31;$i++) {
$return.= '<option>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
}
$return.= '</select>';
$return.= '<select name="'.$name.'1_m" style="width:40px;">';
for ($i=1;$i<=12;$i++) {
$return.= '<option>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
}
$return.= '</select>';
$return.= '<select name="'.$name.'1_a" style="width:55px;">';
for ($i=1900;$i<=date('Y');$i++) {
$return.= '<option>'.$i.'</option>';
}
$return.= '</select>';
$return.= ' à ';
$return.= '<select name="'.$name.'2_j" style="width:40px;">';
for ($i=1;$i<=31;$i++) {
$select = '';
if ($i==date('d')) {
$select = ' selected';
}
$return.= '<option'.$select.'>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
}
$return.= '</select>';
$return.= '<select name="'.$name.'2_m" style="width:40px;">';
for ($i=1;$i<=12;$i++) {
$select = '';
if ($i==date('m')) {
$select = ' selected';
}
$return.= '<option'.$select.'>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
}
$return.= '</select>';
$return.= '<select name="'.$name.'2_a" style="width:55px;">';
$lastYear = date('Y');
for ($i=1900;$i<=$lastYear;$i++) {
$select = '';
if ($i==$lastYear) {
$select = ' selected';
}
$return.= '<option'.$select.'>'.$i.'</option>';
}
$return.= '</select>';
$return .= '<br/><a href="#" id="'.$name.'" class="intervalDate">Valider</a>';
return $return;
}
/* Interval */
private function intervalHTML($name, $field)
{

View File

@ -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,31 +73,36 @@ $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 )
{
$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/configuration.ini');
//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 = $opts->id.'_'.$profil['login'].'_'.date('YmdHis').'.csv';
$outFile = $profil['login'].'_'.$opts->id.'_'.date('YmdHis').'.csv';
require_once 'Scores/Enrichissement.php';
$dico = new Enrichissement();
$fields = $dico->getFields();
@ -107,7 +122,6 @@ if ( count($identifiants)>0 && count($dataProfil)>0 )
} else {
$sql.= ' '.$fields[$item]['column'].' AS '.$item.',';
}
}
//Ajouter le champ presentRcs
$tabEntete[] = 'presentRcs';
@ -121,6 +135,14 @@ if ( count($identifiants)>0 && count($dataProfil)>0 )
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.
@ -142,24 +164,16 @@ if ( count($identifiants)>0 && count($dataProfil)>0 )
}
fputcsv($fp, $tabSortie, ',', '"');
//Mise à jour des lignes traitées dans la base
if ($opts->id) {
$commandesM->update(array('nbLigneTraites'=>$row), "id = ".$commande->id);
}
$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);
if ($opts->id) {
$commandesM->update( array('dateStop' => date('Y-m-d H:i:s')) , "id = ".$commande->id);
}
@ -229,21 +243,3 @@ function siretValide($siret) {
}
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);
}

View File

@ -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);
@ -277,20 +279,50 @@ 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)
{
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('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===null || $max===null)
return;
$this->setFilterRange('nbActio', $min, $max);
}
}
@ -298,8 +330,23 @@ 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);
}
}
@ -307,6 +354,23 @@ class Ciblage
protected function nbMPubli($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);
}
}
@ -314,8 +378,23 @@ 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);
}
}
@ -323,8 +402,23 @@ class Ciblage
protected function age_entrep($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_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);
}
}
@ -332,8 +426,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);
}
}
@ -358,6 +467,82 @@ class Ciblage
}
}
protected function eff_etab($value)
{
if ( array_key_exists('in', $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;
}
$min = ($value['in'][0]=='') ? $valMin : $value['in'][0];
$max = ($value['in'][1]=='') ? $valMax : $value['in'][1];
if ($min===null || $max===null)
return;
$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)
{
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;
$this->setFilterRange('nbEtab', $min, $max);
}
}
protected function geo_domtom($value)
{
if( $value['in']==1 ) {
@ -442,6 +627,12 @@ class Ciblage
}
}
protected function dateImmat($value)
{
}
protected function bilType($value)
{
if ( array_key_exists('in', $value) ) {
@ -609,7 +800,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 +819,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 ) {

View File

@ -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,
@ -147,9 +148,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 +286,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 +294,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'))
),
@ -461,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,
@ -709,7 +709,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 +728,10 @@ class Scores_Fields
}
}
if ($types[0]=='interval') {
$value = explode(',', $value);
}
//Remove duplicate values
if (is_array($value) ) {
$value = array_unique($value);

View File

@ -140,16 +140,25 @@ $(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 = 0;
if(!val2)
val2 = 0;
if(!val1) val1 = '';
if(!val2) val2 = '';
var values = val1 + ',' + val2;
set(key, values);
return false;
@ -158,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(' <span id="'+key+'"><a href="" class="intervalSelect" id="'+key+'">Valider</a></span>');

View File

@ -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;
}