Intégration des tables statiques
This commit is contained in:
parent
e14c56a220
commit
74774b2696
@ -241,9 +241,9 @@ $cache = Zend_Cache::factory('Core','Apc', $frontendOptions, $backendOptions);
|
||||
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
|
||||
|
||||
//Définition bdd local
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
$config = new Zend_Config($application->getOptions());
|
||||
try {
|
||||
$db = Zend_Db::factory($c->profil->db);
|
||||
$db = Zend_Db::factory($config->profil->db);
|
||||
} catch ( Exception $e ) {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
@ -258,7 +258,7 @@ if ($opts->id) {
|
||||
$extension = strrchr($file,'.');
|
||||
$file = str_replace($extension, '', $file);
|
||||
|
||||
if (!file_exists($c->profil->path->data.'/export')) mkdir($c->profil->path->data.'/export');
|
||||
if (!file_exists($config->profil->path->data.'/export')) mkdir($config->profil->path->data.'/export');
|
||||
|
||||
if ($opts->id) {
|
||||
$profilM = new Application_Model_Profil($db);
|
||||
@ -305,7 +305,7 @@ $tabData = array();
|
||||
$posKeySiren = $posKeySiret = $posKeyNic = false;
|
||||
|
||||
//Fichier de définition
|
||||
$inFile = $c->profil->path->data.'/clients/'.$file.'.csv';
|
||||
$inFile = $config->profil->path->data.'/clients/'.$file.'.csv';
|
||||
|
||||
//Lire le fichier csv
|
||||
$row = 0;
|
||||
@ -411,33 +411,62 @@ foreach($tabExtract as $key)
|
||||
foreach($keys as $item){
|
||||
$tabEntete[] = $item;
|
||||
}
|
||||
|
||||
//Traitement pour les clé BDD
|
||||
} else {
|
||||
$tabEntete[] = $key;
|
||||
|
||||
//Add original key
|
||||
$tabEntete[] = $key;
|
||||
|
||||
//Ajout à la requete SQL
|
||||
foreach($tabDico as $element => $select)
|
||||
{
|
||||
if ( array_key_exists('db', $select) && array_key_exists($key, $select['cle']) )
|
||||
{
|
||||
$elementsup = $select['cle'][$key];
|
||||
|
||||
if ( is_array($elementsup) && array_key_exists('table', $elementsup) ) {
|
||||
|
||||
//Specify supplemental head
|
||||
$tabEntete[] = $key.'Lib';
|
||||
|
||||
//Load generic table - alway return array('code', 'label')
|
||||
if ( is_array($elementsup['table']) ) {
|
||||
${'tab'.ucfirst($key)} = $elementsup['table'];
|
||||
} else {
|
||||
|
||||
$stmt = $dbMetier->query($elementsup['table']);
|
||||
$result = $stmt->fetchAll();
|
||||
${'tab'.ucfirst($key)} = $result;
|
||||
|
||||
}
|
||||
|
||||
} elseif ( $select['cle'][$key]!='' ) {
|
||||
|
||||
$strKey = $select['cle'][$key];
|
||||
|
||||
}
|
||||
|
||||
//If string exist add supplemental fields for the sql request
|
||||
if (isset(${$element.'Fields'})){ ${$element.'Fields'}.= ', '; }
|
||||
|
||||
if ($strKey!==false){
|
||||
${$element.'Fields'}.= $strKey;
|
||||
} else {
|
||||
${$element.'Fields'}.= $key;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
if ( $element == 'data' && in_array($key, $select) )
|
||||
{
|
||||
${$key.'Data'} = $values;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Ajout à la requete SQL
|
||||
foreach($tabDico as $element => $select)
|
||||
{
|
||||
if ( array_key_exists('db', $select) && array_key_exists($key, $select['cle']) )
|
||||
{
|
||||
if (isset(${$element.'Fields'})){ ${$element.'Fields'}.= ', '; }
|
||||
|
||||
if ($select['cle'][$key]!=''){
|
||||
$strKey = $select['cle'][$key];
|
||||
}
|
||||
|
||||
if ($strKey!==false){
|
||||
${$element.'Fields'}.= $strKey;
|
||||
} else {
|
||||
${$element.'Fields'}.= $key;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( $element == 'data' && in_array($key, $select) )
|
||||
{
|
||||
${$key.'Data'} = $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
//Ajout colonne obligatoire
|
||||
$tabEntete[] = 'SiretValide';
|
||||
@ -462,7 +491,7 @@ if (count($tabEntete)>0){
|
||||
|
||||
//Définition du fichier de sortie
|
||||
if ( $opts->reprise ) {
|
||||
$outFile = $c->profil->path->data.'/export/'.$commande->fichierOut;
|
||||
$outFile = $config->profil->path->data.'/export/'.$commande->fichierOut;
|
||||
|
||||
$rowReprise = 0;
|
||||
$fp = fopen($outFile, 'r+');
|
||||
@ -471,7 +500,7 @@ if ( $opts->reprise ) {
|
||||
}
|
||||
|
||||
} else {
|
||||
$outFile = $c->profil->path->data.'/export/'.$file.'-'.date('YmdHis').'.csv';
|
||||
$outFile = $config->profil->path->data.'/export/'.$file.'-'.date('YmdHis').'.csv';
|
||||
|
||||
//Ecriture de l'entete du fichier
|
||||
$fp = fopen($outFile, 'w');
|
||||
@ -593,8 +622,10 @@ foreach($tabIdentifiant as $item)
|
||||
{
|
||||
//Traitement par requete SQL
|
||||
if (isset(${$element.'Fields'})){
|
||||
$where = $select['where'];
|
||||
|
||||
$where = $select['where'];
|
||||
eval( "\$where = \"$where\";" );
|
||||
|
||||
${$element.'SQL'} = 'SELECT '.${$element.'Fields'}.' FROM '.$select['db'].$where;
|
||||
try {
|
||||
$stmt = $dbMetier->query(${$element.'SQL'});
|
||||
@ -614,12 +645,13 @@ foreach($tabIdentifiant as $item)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Traitement par fonction
|
||||
if( $element == 'data' )
|
||||
{
|
||||
foreach($select as $item)
|
||||
{
|
||||
if (isset(${$item.'Data'}))
|
||||
if ( isset(${$item.'Data'}) )
|
||||
{
|
||||
$values = false;
|
||||
if( ${$item.'Data'}!=false ){
|
||||
@ -632,6 +664,23 @@ foreach($tabIdentifiant as $item)
|
||||
}
|
||||
}
|
||||
|
||||
//Traitement des libellés génériques
|
||||
foreach($select as $item)
|
||||
{
|
||||
if ( in_array($item.'Lib', $tabEntete) && isset(${'tab'.ucfirst($item)}) )
|
||||
{
|
||||
$retour = 'Non trouvé';
|
||||
$codeFromData = $tabData[$row][$item];
|
||||
foreach( ${'tab'.ucfirst($item)} as $code => $label ) {
|
||||
if ( $codeFromData == $code ) {
|
||||
$retour = $label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$tabData[$row] = $tabData[$row] + $retour;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Enregistrement clés de doublon pour rappel
|
||||
|
Loading…
Reference in New Issue
Block a user