| @ -0,0 +1,141 @@ | |||
| <?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 = 'Marchés'; | |||
| 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 = 'MARC'; | |||
| 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; | |||
| $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/09_MARCHES.json"), true); | |||
| $nb_shipments = count($shipments); | |||
| foreach($shipments as $element) | |||
| { | |||
| // Gestion d'une barre de progression | |||
| progressBar($counter, $nb_shipments); | |||
| // Gestion d'une barre de progression | |||
| // On ne reprend pas les vieux marchés | |||
| if (($element['marcdatlim']/10000) < 2019) continue; | |||
| // A-t-on changé de collectivité ? | |||
| if ($element['collcod'] != $pile_code[$pile_index-1]) | |||
| { | |||
| // 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 -= 2; | |||
| // 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 un élément vide dans la pile | |||
| $pile_index += 1; | |||
| $pile_code[$pile_index] = ''; | |||
| $pile_item[$pile_index] = 0; | |||
| } | |||
| // A-t-on changé de Catégorie de famille ? | |||
| if ($element['marcann'] != $pile_code[$pile_index]) | |||
| { | |||
| // Dépiler | |||
| $pile_index -= 1; | |||
| // Rajouter un item | |||
| SMETI_db::$code = 'MARC'.$pile_code[$pile_index].$element['mpcacod']; | |||
| SMETI_db::$libelle = 'Marchés '.$element['marcann']; | |||
| 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(); | |||
| // Empiler | |||
| $pile_index += 1; | |||
| $pile_code[$pile_index] = $element['marcann']; | |||
| $pile_item[$pile_index] = SMETI_db::$child; | |||
| } | |||
| // Rajouter un item | |||
| SMETI_db::$code = sprintf("%04d%06d",$element['marcnum'],$element['marcnum']); | |||
| SMETI_db::$libelle = $element['marcobj']; | |||
| 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; | |||
| ?> | |||