Surcharge de la configuration, ajour particularité des champs

This commit is contained in:
Michael RICOIS 2011-11-16 13:47:10 +00:00
parent 9bb5d78d5d
commit 5208c398f9

View File

@ -25,7 +25,7 @@ $application = new Zend_Application(
APPLICATION_PATH . '/configs/application.ini'
);
require_once realpath(dirname(__FILE__)).'/../config/config.php';
try {
$opts = new Zend_Console_Getopt(
@ -49,17 +49,26 @@ if(isset($opts->help) || !isset($opts->file))
exit;
}
define('MYSQL_HOST', '192.168.78.230');
define('MYSQL_USER', 'wsuser');
define('MYSQL_PASS', 'scores');
define('MYSQL_DEFAULT_DB', 'jo');
//Définition bdd
$dbConfig = array(
'host' => '192.168.78.230',
'username' => 'wsuser',
'password' => 'scores',
'dbname' => 'jo',
'host' => MYSQL_HOST,
'username' => MYSQL_USER,
'password' => MYSQL_PASS,
'dbname' => MYSQL_DEFAULT_DB,
);
$db = Zend_Db::factory('PDO_MYSQL', $dbConfig);
//Chargement des classes metier
require_once realpath(dirname(__FILE__)).'/../config/config.php';
$tabExtract = array();
$tabEntete = array();
$tabIdentifiant = array();
$tabData = array();
@ -124,10 +133,83 @@ $tabDico = array(
'etablissements' => array(
'db' => 'jo.etablissements',
'cle' => array(
'idSd', 'source', 'triCode', 'autre_id', 'actif', 'siege', 'raisonSociale', 'enseigne', 'sigle',
'marques', 'adr_num', 'adr_btq', 'adr_typeVoie', 'adr_libVoie', 'adr_comp', 'adr_cp', 'adr_ville',
'adr_dep', 'adr_codeCom', 'tel', 'fax', 'cj', 'capital', 'capitalDev', 'ape_etab', 'ape_entrep'
)
'idSd' => "CONCAT(source,'-',source_id) AS idSd",
'source' => '',
'triCode' => '',
'autre_id' => '',
'actif' => '',
'siege' => '',
'raisonSociale' => '',
'enseigne' => '',
'sigle' => '',
'marques' => '',
'adr_num' => '',
'adr_btq' => '',
'adr_typeVoie' => '',
'adr_libVoie' => '',
'adr_comp' => '',
'adr_cp' => '',
'adr_ville' => '',
'adr_dep' => '',
'adr_codeCom' => 'CONCAT(if (adr_dep>100,round(adr_dep/10),adr_dep*1),adr_com) AS adr_codeCom',
'telEtab' => 'tel as telEtab',
'faxEtab' => 'fax as faxEtab',
'cj' => '',
'capital' => '',
'capitalDev' => '',
'ape_etab' => '',
'ape_entrep' => '',
),
'where' => ' WHERE siren=$siren AND nic=$nic',
),
'identite' => array(
'db' => 'insee.identite',
'cle' => array(
'etActifInsee' => 'ACTIF as etActifInsee',
'nomInsee' => 'NOM as nomInsee',
'nomInsee2' => 'NOM2 as nomInsee2',
'sigleInsee' => 'SIGLE as sigleInsee',
'enseigneInsee' => 'ENSEIGNE as enseigneInsee',
'adrNumVoieInsee' => 'ADR_NUMVOIE as adrNumVoieInsee',
'adrBtqInsee' => 'ADR_BTQ as adrBtqInsee',
'adrTypeVoieInsee' => 'ADR_TYPVOIE as adrTypeVoieInsee',
'adrVoieInsee' => 'ADR_LIBVOIE as adrVoieInsee',
'adrCompInsee' => 'ADR_COMP as adrCompInsee',
'adrCPInsee' => 'ADR_CP as adrCPInsee',
'adrVilleInsee' => 'ADR_LIBCOM as adrVilleInsee',
'adrDistSPInsee' => 'ADR_DISTSP as adrDistSPInsee',
'CjInsee' => 'CJ as CjInsee',
'nafEnInsee' => 'APE_ENT as nafEnInsee',
'nafEtInsee' => 'APE_ETAB as nafEtInsee',
'APRM' => '',
'ACTIVNAT' => '',
'ORIGINE' => '',
'MODET' => '',
'EXPLET' => '',
'LIEUACT' => '',
'ACTISURF' => '',
'MODEN' => '',
'PRODPART' => '',
'EXPLEN' => '',
'MONOREG' => '',
'REGIMP' => '',
'MONOACT' => '',
'DCREN' => '',
'AUXILT' => '',
'SAISONAT' => '',
'CIVILITE' => '',
'TCA' => '',
'TCAEXP' => '',
'EFF_ENT' => '',
'DCRET' => '',
'EFF_ET' => '',
'CODEVOIE' => '',
'dateMajInsee' => 'dateUpdate as dateMajInsee',
),
'where' => ' WHERE SIREN=$siren AND nic=$nicSiege',
),
'data' => array(
'SituationJuridique',
),
);
@ -135,20 +217,28 @@ $tabDico = array(
foreach($tabExtract as $key)
{
$strKey = false;
//Traitement spécial pour le champs
//Traitement spécial pour le champs, ajout et remplacement sur entete
switch($key){
case 'idSd':
break;
case 'adr_codeCom':
break;
default:
$tabEntete[] = $key;
break;
}
//Ajout à la requete
//Ajout à la requete SQL
foreach($tabDico as $element => $select)
{
if (in_array($key, $select['cle']))
if ( array_key_exists('db', $select) && in_array($key, $select['cle']) )
{
if (isset(${$element.'Fields'})){ ${$element.'Fields'}.= ', '; }
if ($select['cle'][$key]!=''){
$strKey = $select['cle'][$key];
}
if ($strKey!==false){
${$element.'Fields'}.= $strKey;
} else {
@ -212,8 +302,8 @@ foreach($tabIdentifiant as $item)
$result = $stmt->fetchAll();
if (count($result)==0){
$nic = 0;
}
}
}
}
if (intval($nic)==0){
$strNic = ' AND nic>-1 AND actif>-1 ORDER BY siege DESC, actif DESC, nicTmp DESC LIMIT 0,1';
@ -231,12 +321,13 @@ foreach($tabIdentifiant as $item)
$tabData[$row-1]['nic'] = $nic;
}
//Création de la condition pour la requete SQL
$where = ' WHERE siren='.$siren.' AND nic='.$nic;
//Création des requêtes SQL
//Récupération des données
foreach($tabDico as $element => $select)
{
//Traitement par requete SQL
if (isset(${$element.'Fields'})){
$where = $select['where'];
eval( "\$where = \"$where\";" );
${$element.'SQL'} = 'SELECT '.${$element.'Fields'}.' FROM '.$select['db'].$where;
$stmt = $db->query(${$element.'SQL'});
$result = $stmt->fetchAll();
@ -244,7 +335,12 @@ foreach($tabIdentifiant as $item)
$tabData[$row-1] = array_merge( $tabData[$row-1] , $result[0]);
}
}
//Traitement par fonction
else
{
}
}
echo "\n";
$row++;
@ -268,7 +364,18 @@ foreach($tabData as $data){
writeCSV($tabSortie, $tabEntete, 'enrichissement.csv');
/* FUNCTION */
/* == FUNCTION DATA == */
function dataSituationJuridique() {
}
/* == FUNCTION == */
/**
* Verifie si un SIREN est valide
@ -299,7 +406,7 @@ function sirenValide($siren) {
$estValide = false;
}
return $estValide;
}
}
/**
* Verifie si un SIRET est valide
@ -335,9 +442,12 @@ function siretValide($siret) {
return $estValide;
}
/**
* writeCSV
* @param array $list
* @param array $entete
* @param string $filename
*/
function writeCSV($list, $entete, $filename)
{
$fp = fopen($filename, 'w');