|
|
<?php
|
|
|
|
|
|
function tri_chap_1($a , $b)
|
|
|
{
|
|
|
if ('S'.$a['code'] < 'S'.$b['code']) return -1;
|
|
|
if ('S'.$a['code'] > 'S'.$b['code']) return 1;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
function tri_chap_2($a , $b)
|
|
|
{
|
|
|
if ('S'.$a['instruction'] < 'S'.$b['instruction']) return -1;
|
|
|
if ('S'.$a['instruction'] > 'S'.$b['instruction']) return 1;
|
|
|
|
|
|
if ('S'.$a['code'] < 'S'.$b['code']) return -1;
|
|
|
if ('S'.$a['code'] > 'S'.$b['code']) return 1;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
require_once('smeti_db.inc.php');
|
|
|
|
|
|
SMETI_db::init();
|
|
|
|
|
|
echo 'Chargement collectivités ';
|
|
|
$sql = SMETI_db::$pdo->prepare("SELECT code, item, libelle FROM v_items WHERE plugin = ( SELECT id FROM plugins WHERE libelle = 'Collectivités' )");
|
|
|
$sql->execute();
|
|
|
$coll = $sql->fetchAll(PDO::FETCH_NUM);
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
$libelle = 'Instructions Comptables';
|
|
|
|
|
|
echo 'VACUUM ';
|
|
|
SMETI_db::removePlugin($libelle);
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
echo "Ajout du plugin '$libelle' ";
|
|
|
SMETI_db::addPlugin($libelle);
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
echo "Plugin courant : '$libelle' ";
|
|
|
SMETI_db::setCurPlugin($libelle);
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
echo "Ajout d'une racine: '$libelle' ";
|
|
|
// Ajouter un item
|
|
|
SMETI_db::$libelle = $libelle;
|
|
|
SMETI_db::$code = 'INSC';
|
|
|
SMETI_db::$req1->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Ajouter un lien sur cet item
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Positionner ce lien comme parent
|
|
|
SMETI_db::$parent = SMETI_db::$item;
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
$pile_index = 0;
|
|
|
$pile_code[$pile_index] = SMETI_db::$code;
|
|
|
$pile_item[$pile_index] = SMETI_db::$item;
|
|
|
|
|
|
$libelle = 'Toutes Instructions';
|
|
|
echo "Ajout d'une racine: '$libelle' ";
|
|
|
// Ajouter un item
|
|
|
SMETI_db::$libelle = $libelle;
|
|
|
SMETI_db::$code = 'INSCGLOB';
|
|
|
SMETI_db::$req1->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Ajouter un lien sur cet item
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Positionner ce lien comme parent
|
|
|
SMETI_db::$parent = SMETI_db::$item;
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
$libelle = 'Chapitres';
|
|
|
echo "Ajout d'une racine: '$libelle' ";
|
|
|
// Ajouter un item
|
|
|
SMETI_db::$libelle = $libelle;
|
|
|
SMETI_db::$code = 'INSCGLOBCHAP';
|
|
|
SMETI_db::$req1->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Ajouter un lien sur cet item
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Positionner ce lien comme parent
|
|
|
SMETI_db::$parent = SMETI_db::$item;
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
echo 'Chargement des données (première passe)'.PHP_EOL;
|
|
|
$counter = 0;
|
|
|
$shipments = json_decode(file_get_contents("../data/json/BMO/04_CHAPITRES.json"), true);
|
|
|
$nb_shipments = count($shipments);
|
|
|
usort($shipments,'tri_chap_1');
|
|
|
// On conserve les chapitres dans un tableau
|
|
|
// Ils seront réutilisés plus tard
|
|
|
$chapitres = [];
|
|
|
$chapitres[] = ['BIDON','BIDON'];
|
|
|
foreach($shipments as $element)
|
|
|
{
|
|
|
// Gestion d'une barre de progression
|
|
|
progressBar($counter, $nb_shipments);
|
|
|
$counter += 1;
|
|
|
// Gestion d'une barre de progression
|
|
|
|
|
|
// On ne tient pas compte des données incorrectes
|
|
|
if (!isset($element['code'])) continue;
|
|
|
if (!isset($element['libelle'])) continue;
|
|
|
|
|
|
$n = count($chapitres);
|
|
|
for($i=0;$i<$n;$i++)
|
|
|
if ($chapitres[$i][0] == $element['code'])
|
|
|
break;
|
|
|
if ($i == $n)
|
|
|
{
|
|
|
// Rajouter un item
|
|
|
SMETI_db::$code = $element['code'];
|
|
|
SMETI_db::$libelle = $element['libelle'];
|
|
|
SMETI_db::$req1->execute();
|
|
|
// Rajouter un lien
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
|
|
|
$chapitres[] = [SMETI_db::$code, SMETI_db::$libelle, SMETI_db::$item];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Enlever la barre de progression
|
|
|
clearLine();
|
|
|
// Enlever la barre de progression
|
|
|
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
echo 'Chargement des données (deuxième passe)'.PHP_EOL;
|
|
|
$counter = 0;
|
|
|
|
|
|
// Décliner par instruction
|
|
|
// Commencer par empiler deux valeurs vides
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = '';
|
|
|
$pile_item[$pile_index] = 0;
|
|
|
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = '';
|
|
|
$pile_item[$pile_index] = 0;
|
|
|
|
|
|
usort($shipments,'tri_chap_2');
|
|
|
$n = count($chapitres);
|
|
|
foreach($shipments as $element)
|
|
|
{
|
|
|
// Gestion d'une barre de progression
|
|
|
progressBar($counter, $nb_shipments);
|
|
|
$counter += 1;
|
|
|
// Gestion d'une barre de progression
|
|
|
|
|
|
if (!isset($element['code'])) continue;
|
|
|
if (!isset($element['libelle'])) continue;
|
|
|
|
|
|
if ($element['instruction'] != $pile_code[$pile_index-1])
|
|
|
{
|
|
|
$pile_index = 0;
|
|
|
|
|
|
// Rajouter un item pour l'instruction
|
|
|
SMETI_db::$code = $element['instruction'];
|
|
|
SMETI_db::$libelle = 'Instruction '. $element['instruction'];
|
|
|
SMETI_db::$req1->execute();
|
|
|
// Rajouter un lien
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = SMETI_db::$code;
|
|
|
$pile_item[$pile_index] = SMETI_db::$item;
|
|
|
// Conserver l'instruction dans un tableau
|
|
|
$instructions[] = [SMETI_db::$code, SMETI_db::$item];
|
|
|
|
|
|
$code = 'CHAP'.$element['instruction'];
|
|
|
$libelle = 'Chapitres '.$element['instruction'];
|
|
|
// Rajouter un item pour les chapitres
|
|
|
SMETI_db::$code = 'CHAP'.$element['instruction'];
|
|
|
SMETI_db::$libelle = 'Chapitres '. $element['instruction'];
|
|
|
SMETI_db::$req1->execute();
|
|
|
// Rajouter un lien
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = SMETI_db::$code;
|
|
|
$pile_item[$pile_index] = SMETI_db::$item;
|
|
|
$last ='';
|
|
|
}
|
|
|
|
|
|
if ($element['code'] == $last) continue;
|
|
|
for($i=0;$i<$n;$i++)
|
|
|
if ($chapitres[$i][0] == $element['code'])
|
|
|
break;
|
|
|
if ($i == $n) continue;
|
|
|
|
|
|
// Rajouter un lien vers le chapitre
|
|
|
SMETI_db::$item = $chapitres[$i][2];
|
|
|
SMETI_db::$link = 1;
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
|
|
|
// NB : on pourrait s'en passer en plaçant le chapitre dans la pile
|
|
|
$last = $element['code'];
|
|
|
}
|
|
|
|
|
|
// Enlever la barre de progression
|
|
|
clearLine();
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
// Enlever la barre de progression
|
|
|
|
|
|
?>
|