issue #0001784 : Backport amélioration 2.0

This commit is contained in:
Michael RICOIS 2014-06-26 08:09:26 +00:00
parent 65c8980eb7
commit 3fe1ffa0e6
2 changed files with 100 additions and 74 deletions

View File

@ -164,10 +164,7 @@ class ComptageController extends Zend_Controller_Action
'error'=>0, 'error'=>0,
'msg'=> "Vos critères ont été sauvegardés sous la référence $ref", 'msg'=> "Vos critères ont été sauvegardés sous la référence $ref",
'href' => $this->view->url(array('controller'=>'dashboard', 'action'=>'ciblage', 'id'=>$id)) 'href' => $this->view->url(array('controller'=>'dashboard', 'action'=>'ciblage', 'id'=>$id))
)); ));
//cache remove
$cache = Zend_Cache::factory('Output','File',array(),array('cache_dir' => '../data/cache/'));
$cache->remove($user->username);
} else { } else {
echo json_encode(array( echo json_encode(array(
'error'=>1, 'error'=>1,
@ -250,80 +247,100 @@ class ComptageController extends Zend_Controller_Action
$result = $profilsM->fetchRow($sql); $result = $profilsM->fetchRow($sql);
$profil = json_decode($result['criteres'], true); $profil = json_decode($result['criteres'], true);
//No profil, define it //No profil, define it
if (count($profil)==0) { if (count($profil)==0) {
$profil = array('raisonSociale'); $profil = array('raisonSociale');
} }
$extractSql = $extractLabel = array(); $tabEntete = $tabEnteteLabel = array();
//$extractSql[] = "CONCAT(LPAD(siren, 9, '000000000'), LPAD(nic, 5, '00000')) AS siret";
//$extractLabel[] = 'SIRET';
require_once 'Scores/Enrichissement.php'; require_once 'Scores/Enrichissement.php';
$enrichissement = new Enrichissement(); $enrichissement = new Enrichissement();
$data = $enrichissement->getFields(); $fields = $enrichissement->getFields();
foreach ( $data as $key => $item ) { $columns = array();
if (in_array($key, $profil)) { $joins = array();
if ( array_key_exists('sql', $item) ) { foreach ( $profil as $item ) {
$extractSql[] = $item['sql'];
} else { //Get item
$extractSql[] = $item['column']; if ( array_key_exists($item, $fields) ) {
} $field = $fields[$item];
$extractLabel[] = $item['label'];
} //Définition de l'entete
/*if ( array_key_exists('join', $item) ) { $tabEnteteLabel[] = $field['label'];
$tabEntete[] = $item;
//Automatic column name .Lib
$joinColumn = $data[$item]['join']['column']; //Construction de la requete SQL
$colName = $data[$item]['column'].$joinColumn; if ( array_key_exists('sql', $field) ) {
$tabEntete[] = $colName; $columns[] = $field['sql'];
//label } else {
$extractLabel[] = $data[$item]['join']['label']; $columns[] = $field['column'].' AS '.$item;
//Sql }
$tableAlias = array($data[$item]['column'].'_'.$joinColumn=>$data[$item]['join']['table']);
$extractSql[] = $data[$item]['column'].'_'.$joinColumn.'.'.$joinColumn.' AS '.$colName.','; //Pour les champs de type "code", ajouter le libellé
$join[]= array($tableAlias,$data[$item]['join']['stat']); if ( array_key_exists('join', $field) ) {
}*/ $tabEnteteLabel[] = $field['join']['label'];
} $joinColumn = $item.'Lib';
$tabEntete[] = $joinColumn;
//Sql
$tableAlias = $item.'L';
$join['name'] = $field['join']['table'].' AS '.$tableAlias;
$join['col'] = $field['join']['column'].' AS '.$joinColumn;
$join['cond'] = $field['join']['cond'];
$joins[] = $join;
}
}
}
$db = Zend_Db_Table::getDefaultAdapter(); $db = Zend_Db_Table::getDefaultAdapter();
$sql = $db->select() $sql = $db->select()->from('jo.etablissements_act', $columns);
->from(array('jo_act' => 'jo.etablissements_act'), $extractSql);
if($join){
foreach ($join as $params ){
$sql->joinLeft($params[0], $params[1], array());
}
}
$i = 0; $i = 0;
$where = ''; foreach ( $sirets as $siret ) {
foreach($sirets as $siret) { if ( $i>0 ) {
if ($i>0) { $sql->orWhere("siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."'");
$where.=' OR '; } else {
$sql->where("siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."'");
} }
$where.= "(siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."')";
$i++; $i++;
} }
$sql->where($where);
$result = $db->fetchAll($sql); if (count($joins)) {
foreach ( $joins as $join ) {
$liste = array(); $sql->joinLeft($join['name'], $join['cond'], $join['col']);
foreach ($result as $l => $line) {
$tmp = array();
foreach($line as $column => $data) {
$valuesPredefine = $enrichissement->getColumnValue($column);
if ($valuesPredefine!==false) {
$tmp[] = $valuesPredefine[$data];
} else {
$tmp[] = $data;
}
} }
$liste[] = $tmp;
} }
$this->view->assign('label', $extractLabel); try {
$result = $db->fetchAll($sql);
} catch(Zend_Db_Exception $e) {
if (APPLICATION_ENV=='development') {
echo $e->getMessage();
echo "<br/>";
echo $sql->__toString();
}
}
$liste = array();
if ( count($result)>0 ) {
foreach ($result as $l => $line) {
$tmp = array();
foreach($line as $column => $data) {
$valuesPredefine = $enrichissement->getColumnValue($column);
if ($valuesPredefine!==false) {
$tmp[] = $valuesPredefine[$data];
} else {
$tmp[] = $data;
}
}
$liste[] = $tmp;
}
}
$this->view->assign('label', $tabEnteteLabel);
$this->view->assign('liste', $liste); $this->view->assign('liste', $liste);
} }
} }

View File

@ -103,9 +103,8 @@ $fields = $dico->getFields();
//Entete, Valeur de remplacement et Requete SQL //Entete, Valeur de remplacement et Requete SQL
$tabEntete = array('siren', 'nic'); $tabEntete = array('siren', 'nic');
$tabEnteteLabel = array('SIREN', 'NIC'); $tabEnteteLabel = array('SIREN', 'NIC');
$sql = 'SELECT LPAD(siren, 9, 000000000) AS siren, LPAD(nic,5,00000) AS nic,'; $columns = array('LPAD(siren, 9, 000000000) AS siren', 'LPAD(nic,5,00000) AS nic');
$from = 'jo.etablissements_act'; $joins = array();
$addWhere = '';
foreach ( $dataProfil as $item ) { foreach ( $dataProfil as $item ) {
//Get item //Get item
@ -118,9 +117,9 @@ foreach ( $dataProfil as $item ) {
//Construction de la requete SQL //Construction de la requete SQL
if ( array_key_exists('sql', $field) ) { if ( array_key_exists('sql', $field) ) {
$sql.= ' '.$field['sql'].', '; $columns[] = $field['sql'];
} else { } else {
$sql.= ' '.$field['column'].' AS '.$item.','; $columns[] = $field['column'].' AS '.$item;
} }
//Pour les champs de type "code", ajouter le libellé //Pour les champs de type "code", ajouter le libellé
@ -131,17 +130,20 @@ foreach ( $dataProfil as $item ) {
//Sql //Sql
$tableAlias = $item.'L'; $tableAlias = $item.'L';
$sql.= $tableAlias.'.'.$field['join']['column'].' AS '.$joinColumn; $join['name'] = $field['join']['table'].' AS '.$tableAlias;
$from.= ','.$field['join']['column'].' AS '.$tableAlias; $join['col'] = $field['join']['column'].' AS '.$joinColumn;
$addWhere = ' AND WHERE '.$field['join']['cond']; $join['cond'] = $field['join']['cond'];
}
$joins[] = $join;
}
} }
} }
//Ajouter le champ presentRcs //Ajouter le champ presentRcs
$columns = 'presentRcs';
$tabEntete[] = 'presentRcs'; $tabEntete[] = 'presentRcs';
$tabEnteteLabel[] = 'RCS'; $tabEnteteLabel[] = 'RCS';
$sql .= ' presentRcs'; $sqlFrom .= ' presentRcs';
//Pour chaque identifiant traiter les données //Pour chaque identifiant traiter les données
$row = 0; $row = 0;
@ -159,13 +161,20 @@ if ($opts->id) {
"id = ".$commande->id); "id = ".$commande->id);
} }
$model = $sql;
$traite = 0; $traite = 0;
//Date de debut de traitement. //Date de debut de traitement.
$dateStart = date('YmdHms'); $dateStart = date('YmdHms');
foreach ($identifiants as $siret ) foreach ($identifiants as $siret )
{ {
$sql = $model.' FROM jo.etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5);
$sql = $db->select()->from('jo.etablissements_act', $columns);
$sql->where("siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."'");
if (count($joins)) {
foreach ( $joins as $join ) {
$sql->joinLeft($join['name'], $join['cond'], $join['col']);
}
}
try { try {
$result = $db->fetchRow($sql); $result = $db->fetchRow($sql);
$traite++; $traite++;