|
|
<?php
|
|
|
|
|
|
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 = 'Services';
|
|
|
|
|
|
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 = 'SERV';
|
|
|
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;
|
|
|
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = '';
|
|
|
$pile_item[$pile_index] = 0;
|
|
|
|
|
|
echo 'Chargement des données'.PHP_EOL;
|
|
|
$counter = 0;
|
|
|
$shipments = json_decode(file_get_contents("../data/json/BMO/03_SERVICES.json"), true);
|
|
|
$nb_shipments = count($shipments);
|
|
|
foreach($shipments as $element)
|
|
|
{
|
|
|
// Gestion d'une barre de progression
|
|
|
progressBar($counter, $nb_shipments);
|
|
|
if (5000 == $counter++) break;
|
|
|
// Gestion d'une barre de progression
|
|
|
|
|
|
// A-t-on changé de collectivité ?
|
|
|
if ($element['collcod'] != $pile_code[$pile_index])
|
|
|
{
|
|
|
// chercher la collectivité
|
|
|
$n = count($coll);
|
|
|
for($i=0;$i<$n;$i++)
|
|
|
if ($element['collcod'] == $coll[$i][0])
|
|
|
break;
|
|
|
if ($i == $n) continue;
|
|
|
// Revenir au niveau 'plugin' de la pile
|
|
|
$pile_index -= 1;
|
|
|
|
|
|
// Ajout d'un lien (symbolique)
|
|
|
SMETI_db::$link = 1;
|
|
|
SMETI_db::$item = $coll[$i][1];
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Ajout d'un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
|
|
|
// Conserver ce noeud dans la pile
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = $element['collcod'];
|
|
|
$pile_item[$pile_index] = SMETI_db::$child;
|
|
|
}
|
|
|
|
|
|
// Rajouter le service
|
|
|
SMETI_db::$code = $element['servcod'];
|
|
|
SMETI_db::$libelle = $element['servcod'];
|
|
|
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();
|
|
|
}
|
|
|
|
|
|
// Enlever la barre de progression
|
|
|
clearLine();
|
|
|
// Enlever la barre de progression
|
|
|
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
?>
|