176 lines
5.7 KiB
PHP
176 lines
5.7 KiB
PHP
<?php
|
|
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
|
|
|
|
// Define path to application directory
|
|
defined('APPLICATION_PATH')
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
|
|
|
|
// Define application environment
|
|
defined('APPLICATION_ENV')
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
// Ensure library/ is on include_path
|
|
set_include_path(implode(PATH_SEPARATOR, array(
|
|
realpath(APPLICATION_PATH . '/../library'),
|
|
get_include_path(),
|
|
)));
|
|
|
|
//Use classmap autoloader - useful with opcode and realpath cache
|
|
require_once 'Zend/Loader/AutoloaderFactory.php';
|
|
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
|
Zend_Loader_AutoloaderFactory::factory(array(
|
|
'Zend_Loader_ClassMapAutoloader' => array(
|
|
__DIR__ . '/../../library/Zend/autoload_classmap.php',
|
|
__DIR__ . '/../../library/Application/autoload_classmap.php',
|
|
__DIR__ . '/../../library/Scores/autoload_classmap.php',
|
|
__DIR__ . '/../../application/autoload_classmap.php',
|
|
),
|
|
'Zend_Loader_StandardAutoloader' => array(
|
|
'prefixes' => array(
|
|
'Zend' => __DIR__ . '/../../library/Zend',
|
|
'Application' => __DIR__ . '/../../library/Application',
|
|
'Scores' => __DIR__ . '/../../library/Scores',
|
|
'SdMetier' => __DIR__ . '/../../library/SdMetier',
|
|
'Metier' => __DIR__ . '/../../library/Metier',
|
|
),
|
|
'fallback_autoloader' => true
|
|
)
|
|
));
|
|
|
|
// Create application, bootstrap, and run
|
|
$application = new Zend_Application(
|
|
APPLICATION_ENV,
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
);
|
|
|
|
try {
|
|
$opts = new Zend_Console_Getopt(
|
|
//Options
|
|
array(
|
|
'help|?' => "Displays usage information.",
|
|
'cron' => "Mandatory option for launch the cli in cron",
|
|
)
|
|
);
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
echo $e->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
//Usage
|
|
if( isset($opts->help) || count($opts->getOptions())==0 )
|
|
{
|
|
echo "Orone Table.\n";
|
|
echo $opts->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
$db = Zend_Db::factory($c->profil->db->metier);
|
|
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
|
|
|
$requests = array(
|
|
'REF_CodeJournal_' => array(
|
|
'header' => array('id', 'nomJALedition', 'parution', 'parutionJours', 'aboDateDeb', 'aboDateFin', 'aboVecteur'),
|
|
'columns' => array('id', 'nomJALedition', 'parution', 'parutionJours', 'aboDateDeb', 'aboDateFin', 'aboVecteur'),
|
|
'sql' => "SELECT id, nomJALedition, parution, parutionJours, aboDateDeb, aboDateFin, aboVecteur FROM jo.tabJALed;",
|
|
),
|
|
'REF_CodeFormeJuridique_' => array(
|
|
'header' => array('code', 'libelle'),
|
|
'columns' => array('code', 'libelle'),
|
|
'sql' => array(
|
|
"SET @sumSirene := (SELECT SUM(nbSirene) FROM jo.tabFJur);",
|
|
"SELECT code, libelle, (nbSirene/@sumSirene )*100 AS pourcentage
|
|
FROM jo.tabFJur
|
|
WHERE code>999 AND libelle <> ''
|
|
ORDER BY pourcentage DESC;"
|
|
),
|
|
),
|
|
'REF_CodeTribunal_' => array(
|
|
'header' => array('triId', 'triCode', 'triType', 'triNom', 'triVille'),
|
|
'columns' => array('triId', 'triCode', 'triType', 'triNom', 'triVille'),
|
|
'sql' => "SELECT triId, triCode, triType, triNom, triVille
|
|
FROM jo.tribunaux
|
|
WHERE triType IN ('L', 'C', 'I', 'G', 'M');",
|
|
)
|
|
);
|
|
|
|
$dateBegin = date('Ymd');
|
|
|
|
//Output path
|
|
$client = 'orone';
|
|
$pathOut = $c->profil->path->storage . '/clients/' . $client . '/recv';
|
|
|
|
foreach($requests as $n => $r) {
|
|
|
|
$fileOptionsOut = array(
|
|
'dir' => $pathOut,
|
|
'type' => 'csv',
|
|
'delimiter' => ';',
|
|
'enclosure' => '"',
|
|
'header' => $r['header'],
|
|
'columns' => $r['columns'],
|
|
'name' => $n,
|
|
//'encoding' => 'ISO-8859-15',
|
|
);
|
|
|
|
// --- Requete SQL
|
|
if (is_array($r['sql'])){
|
|
$i = 0;
|
|
foreach ($r['sql'] as $request)
|
|
{
|
|
$sql = $request;
|
|
if ($i > count($r['sql']) - 1 ) {
|
|
break;
|
|
}
|
|
$db->query($sql);
|
|
$i++;
|
|
}
|
|
} else {
|
|
$sql = $r['sql'];
|
|
}
|
|
$result = $db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
|
|
if ($result === null) {
|
|
echo date('Y-m-d H:i:s')." - Pas de résultats\n";
|
|
} else {
|
|
|
|
// --- Ecriture du fichier
|
|
$file = $fileOptionsOut['dir'] . '/' .$fileOptionsOut['name'] . $dateBegin . '.' . $fileOptionsOut['type'];
|
|
// --- Ouverture fichier
|
|
$fp = fopen($file, 'w');
|
|
if ( $fp === false ) {
|
|
echo date('Y-m-d H:i:s')." - ERREUR Impossible de créer le fichier ".$file."\n";
|
|
exit;
|
|
}
|
|
// --- Header
|
|
if ( count($fileOptionsOut['header']) > 0 ) {
|
|
fputcsv($fp, $fileOptionsOut['header'], $fileOptionsOut['delimiter'], $fileOptionsOut['enclosure']);
|
|
}
|
|
|
|
foreach ($result as $item) {
|
|
|
|
$values = (array)$item;
|
|
|
|
// --- Trier données
|
|
$line = array();
|
|
foreach ( $fileOptionsOut['columns'] as $i => $column ) {
|
|
$line[] = $values[$column];
|
|
}
|
|
// --- Ecrire ligne
|
|
if ( empty($fileOptionsOut['enclosure']) ) {
|
|
fwrite($fp, join($fileOptionsOut['delimiter'], $line)."\n");
|
|
} else {
|
|
fputcsv($fp, $line, $fileOptionsOut['delimiter'], $fileOptionsOut['enclosure']);
|
|
}
|
|
|
|
}
|
|
|
|
// --- Fermeture fichier
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|