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,
'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))
));
//cache remove
$cache = Zend_Cache::factory('Output','File',array(),array('cache_dir' => '../data/cache/'));
$cache->remove($user->username);
));
} else {
echo json_encode(array(
'error'=>1,
@ -250,80 +247,100 @@ class ComptageController extends Zend_Controller_Action
$result = $profilsM->fetchRow($sql);
$profil = json_decode($result['criteres'], true);
//No profil, define it
if (count($profil)==0) {
$profil = array('raisonSociale');
}
$extractSql = $extractLabel = array();
//$extractSql[] = "CONCAT(LPAD(siren, 9, '000000000'), LPAD(nic, 5, '00000')) AS siret";
//$extractLabel[] = 'SIRET';
$tabEntete = $tabEnteteLabel = array();
require_once 'Scores/Enrichissement.php';
$enrichissement = new Enrichissement();
$data = $enrichissement->getFields();
foreach ( $data as $key => $item ) {
if (in_array($key, $profil)) {
if ( array_key_exists('sql', $item) ) {
$extractSql[] = $item['sql'];
} else {
$extractSql[] = $item['column'];
}
$extractLabel[] = $item['label'];
}
/*if ( array_key_exists('join', $item) ) {
//Automatic column name .Lib
$joinColumn = $data[$item]['join']['column'];
$colName = $data[$item]['column'].$joinColumn;
$tabEntete[] = $colName;
//label
$extractLabel[] = $data[$item]['join']['label'];
//Sql
$tableAlias = array($data[$item]['column'].'_'.$joinColumn=>$data[$item]['join']['table']);
$extractSql[] = $data[$item]['column'].'_'.$joinColumn.'.'.$joinColumn.' AS '.$colName.',';
$join[]= array($tableAlias,$data[$item]['join']['stat']);
}*/
}
$fields = $enrichissement->getFields();
$columns = array();
$joins = array();
foreach ( $profil as $item ) {
//Get item
if ( array_key_exists($item, $fields) ) {
$field = $fields[$item];
//Définition de l'entete
$tabEnteteLabel[] = $field['label'];
$tabEntete[] = $item;
//Construction de la requete SQL
if ( array_key_exists('sql', $field) ) {
$columns[] = $field['sql'];
} else {
$columns[] = $field['column'].' AS '.$item;
}
//Pour les champs de type "code", ajouter le libellé
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();
$sql = $db->select()
->from(array('jo_act' => 'jo.etablissements_act'), $extractSql);
if($join){
foreach ($join as $params ){
$sql->joinLeft($params[0], $params[1], array());
}
}
$sql = $db->select()->from('jo.etablissements_act', $columns);
$i = 0;
$where = '';
foreach($sirets as $siret) {
if ($i>0) {
$where.=' OR ';
foreach ( $sirets as $siret ) {
if ( $i>0 ) {
$sql->orWhere("siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."'");
} 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++;
}
$sql->where($where);
$result = $db->fetchAll($sql);
$liste = array();
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;
}
if (count($joins)) {
foreach ( $joins as $join ) {
$sql->joinLeft($join['name'], $join['cond'], $join['col']);
}
$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);
}
}

View File

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