batch enrichissement à tester
This commit is contained in:
parent
189a519597
commit
ecc492c1ce
@ -30,7 +30,7 @@ try {
|
||||
array(
|
||||
'help|?' => "Aide.",
|
||||
'id=s' => "Identifiant du traitement",
|
||||
'file=s' => "Traitement manuel avec spécification du fichier"
|
||||
'file=s' => "Identifiant pour les traitements par fichier"
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
@ -60,17 +60,82 @@ try {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
|
||||
$liste = array();
|
||||
|
||||
if ($opts->id) {
|
||||
|
||||
$commandesM = new Table_EnrichissementCommandes($db);
|
||||
$commande = $commandesM->find(intval($opts->id))->current();
|
||||
|
||||
$identifiants = json_decode($commande->identifiants, true);
|
||||
|
||||
$profilM = new Table_EnrichissementProfils();
|
||||
$profil = $profilM->find($commande->idProfil);
|
||||
|
||||
} else {
|
||||
$dataProfil = json_decode($profil->criteres, true);
|
||||
|
||||
$file = $opts->file;
|
||||
} else if ($opts->file) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ( count($identifiants)>0 && count($dataProfil)>0 )
|
||||
{
|
||||
$outFile = uniqid($commande->reference.'-');
|
||||
|
||||
require_once 'Scores/Enrichissement.php';
|
||||
$dico = new Enrichissement();
|
||||
$fields = $dico->getFields();
|
||||
|
||||
//Entete, Valeur de remplacement et Requete SQL
|
||||
$tabEntete = array('siren', 'nic');
|
||||
$tabEnteteLabel = array('SIREN', 'NIC');
|
||||
$sql = 'SELECT siren, nic,';
|
||||
foreach ( $dataProfil as $item ) {
|
||||
//Définition de l'entete
|
||||
$tabEnteteLabel[] = $fields[$item]['label'];
|
||||
$tabEntete[] = $item;
|
||||
|
||||
//Construction de la requete SQL
|
||||
if ( array_key_exists('sql', $fields[$item]) ) {
|
||||
$sql.= ' '.$sql;
|
||||
} else {
|
||||
$sql.= ' '.$fields[$item]['column'].' AS '.$item.',';
|
||||
}
|
||||
|
||||
}
|
||||
//Ajouter le champ presentRcs
|
||||
$tabEntete[] = 'presentRcs';
|
||||
$tabEnteteLabel[] = 'RCS';
|
||||
$sql.= ' presentRcs';
|
||||
|
||||
//Pour chaque identifiant traiter les données
|
||||
$row = 0;
|
||||
$fp = fopen($outFile, 'w');
|
||||
//Ecrire l'entete
|
||||
if (count($tabEnteteLabel)>0){
|
||||
fputcsv($fp, $tabEnteteLabel, ',', '"');
|
||||
}
|
||||
|
||||
foreach ($identifiants as $siret )
|
||||
{
|
||||
$sql.= ' FROM etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5);
|
||||
|
||||
$result = $dbMetier->fetchAssoc($sql);
|
||||
$tabData = $result[0];
|
||||
|
||||
//Trier pour la sortie
|
||||
$tabSortie = array();
|
||||
foreach($tabEntete as $key){
|
||||
$tabSortie[] = isset($tabData[$key]) ? $tabData[$key] : '';
|
||||
}
|
||||
fputcsv($fp, $tabSortie, ',', '"');
|
||||
|
||||
$row++;
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
|
||||
/* == FUNCTION == */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user