| Line 21... |
Line 21... |
| 21 |
try {
|
21 |
try {
|
| 22 |
$cmd = $this->getParametre('a');
|
22 |
$cmd = $this->getParametre('a');
|
| 23 |
switch ($cmd) {
|
23 |
switch ($cmd) {
|
| 24 |
case "unitebase" :
|
24 |
case "unitebase" :
|
| 25 |
$this->desontologiserUniteBase(); break;
|
25 |
$this->desontologiserUniteBase(); break;
|
| - |
|
26 |
default :
|
| - |
|
27 |
case "uniterangement" :
|
| - |
|
28 |
$this->desontologiserUniteRangement(); break;
|
| 26 |
default :
|
29 |
default :
|
| 27 |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
|
30 |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
|
| 28 |
}
|
31 |
}
|
| 29 |
} catch (Exception $erreur) {
|
32 |
} catch (Exception $erreur) {
|
| 30 |
$this->traiterErreur($erreur->getMessage());
|
33 |
$this->traiterErreur($erreur->getMessage());
|
| Line 35... |
Line 38... |
| 35 |
$requete = "SELECT ccb_id_collection, ccb_truk_unite_base ".
|
38 |
$requete = "SELECT ccb_id_collection, ccb_truk_unite_base ".
|
| 36 |
"FROM coel_collection_botanique ".
|
39 |
"FROM coel_collection_botanique ".
|
| 37 |
"WHERE ccb_truk_unite_base IS NOT NULL AND ccb_truk_unite_base != ''";
|
40 |
"WHERE ccb_truk_unite_base IS NOT NULL AND ccb_truk_unite_base != ''";
|
| Line 38... |
Line 41... |
| 38 |
|
41 |
|
| 39 |
$infos_truk = $this->bdd->recupererTous($requete);
|
- |
|
| 40 |
|
- |
|
| Line 41... |
Line 42... |
| 41 |
$resultats_fmt = array();
|
42 |
$infos_truk = $this->bdd->recupererTous($requete);
|
| Line 42... |
Line 43... |
| 42 |
|
43 |
|
| Line 56... |
Line 57... |
| 56 |
|
57 |
|
| 57 |
$truk_unite_infos = explode('||', $truk_unite_infos);
|
58 |
$truk_unite_infos = explode('||', $truk_unite_infos);
|
| 58 |
$nb_planches_herbiers = $truk_unite_infos[0];
|
59 |
$nb_planches_herbiers = $truk_unite_infos[0];
|
| Line 59... |
Line -... |
| 59 |
$nb_especes = $truk_unite_infos[5];
|
- |
|
| 60 |
|
- |
|
| 61 |
$resultats_fmt[$id_collection] = array(
|
- |
|
| 62 |
'brut' => $truk_unite_infos,
|
- |
|
| 63 |
'nb_planches_herbier' => $nb_planches_herbiers,
|
- |
|
| 64 |
'nb_especes' => $nb_especes
|
- |
|
| 65 |
);
|
60 |
$nb_especes = $truk_unite_infos[5];
|
| 66 |
|
61 |
|
| 67 |
$update = 'UPDATE coel_collection_botanique '.
|
62 |
$update = 'UPDATE coel_collection_botanique '.
|
| 68 |
'SET '.
|
63 |
'SET '.
|
| 69 |
'cccb_nb_planches_herbiers = "'.$nb_planches_herbiers.'", '.
|
64 |
'ccb_nb_planches_herbiers = "'.$nb_planches_herbiers.'", '.
|
| Line 70... |
Line 65... |
| 70 |
'cccb_nb_especes = "'.$nb_especes.'" '.
|
65 |
'ccb_nb_especes = "'.$nb_especes.'" '.
|
| 71 |
'WHERE ccb_id_collection = "'.$id_collection.'"';
|
66 |
'WHERE ccb_id_collection = "'.$id_collection.'"';
|
| 72 |
|
67 |
|
| 73 |
$this->bdd->executer($update);
|
68 |
$this->bdd->executer($update);
|
| 74 |
}
|
69 |
}
|
| - |
|
70 |
}
|
| - |
|
71 |
}
|
| - |
|
72 |
}
|
| - |
|
73 |
|
| - |
|
74 |
private function desontologiserUniteRangement() {
|
| - |
|
75 |
|
| - |
|
76 |
$requete = "SELECT ccb_id_collection, ccb_truk_unite_rangement ".
|
| - |
|
77 |
"FROM coel_collection_botanique ".
|
| - |
|
78 |
"WHERE ccb_truk_unite_rangement IS NOT NULL AND ccb_truk_unite_rangement != '' ";
|
| - |
|
79 |
|
| - |
|
80 |
$infos_truk = $this->bdd->recupererTous($requete);
|
| - |
|
81 |
|
| - |
|
82 |
// Récupération de la liste des termes d'ontologies pour les types de rangement
|
| - |
|
83 |
$requete_onto = "SELECT * FROM coel_meta_liste_valeur ".
|
| - |
|
84 |
"WHERE cmlv_ce_parent = 1044";
|
| - |
|
85 |
|
| - |
|
86 |
$infos_onto = $this->bdd->recupererTous($requete_onto);
|
| - |
|
87 |
|
| - |
|
88 |
// Pour associer facilement chaque id d'ontologie à sa signification
|
| - |
|
89 |
$ontologie_rangement = array();
|
| - |
|
90 |
foreach($infos_onto as $onto) {
|
| - |
|
91 |
$ontologie_rangement[$onto['cmlv_id_valeur']] = $onto;
|
| - |
|
92 |
}
|
| - |
|
93 |
|
| - |
|
94 |
foreach($infos_truk as $truk) {
|
| - |
|
95 |
|
| - |
|
96 |
$id_collection = $truk['ccb_id_collection'];
|
| - |
|
97 |
$unite_rangement_des = array('cartons' => array(), 'liasses' => array(), 'autres' => array());
|
| - |
|
98 |
|
| - |
|
99 |
// Séparation de chaque catégorie d'unite de truk
|
| - |
|
100 |
$categories_unite_rangement = explode(';;', $truk['ccb_truk_unite_rangement']);
|
| - |
|
101 |
|
| - |
|
102 |
// Pour éviter de modifier une collection où seul un "squelette" de truk serait présent
|
| - |
|
103 |
$collection_a_modifier = false;
|
| - |
|
104 |
|
| - |
|
105 |
// Iteration sur toutes les catégories de rangement trouvées
|
| - |
|
106 |
foreach($categories_unite_rangement as $unite_rangement) {
|
| - |
|
107 |
// extraction du numéro d'ontologie de la liste concernée
|
| - |
|
108 |
list($id_ontologie_rangement, $infos_unite_rangement) = explode('##', $unite_rangement);
|
| - |
|
109 |
$tableau_unite_rangement = $this->parserUniteRangement($infos_unite_rangement);
|
| - |
|
110 |
|
| - |
|
111 |
if($tableau_unite_rangement['nombre'] > 0) {
|
| - |
|
112 |
$collection_a_modifier = true;
|
| - |
|
113 |
switch($id_ontologie_rangement) {
|
| - |
|
114 |
// Liasses : 2256
|
| - |
|
115 |
case "2256":
|
| - |
|
116 |
$unite_rangement_des['liasses'] = $tableau_unite_rangement;
|
| - |
|
117 |
break;
|
| - |
|
118 |
// Cartons d'herbier : 2255
|
| - |
|
119 |
case "2255":
|
| - |
|
120 |
$unite_rangement_des['cartons'] = $tableau_unite_rangement;
|
| - |
|
121 |
break;
|
| - |
|
122 |
// Autres
|
| - |
|
123 |
default:
|
| - |
|
124 |
$unite_rangement_des['autres'][] = $this->formaterLigneAutreUniteRangement($id_ontologie_rangement, $ontologie_rangement, $tableau_unite_rangement);
|
| - |
|
125 |
}
|
| - |
|
126 |
}
|
| - |
|
127 |
}
|
| - |
|
128 |
|
| - |
|
129 |
// Pas la peine de modifier une collection qui ne content ni liasse, ni carton d'herbier, ni autre
|
| - |
|
130 |
// (on ne le sait qu'à ce moment là après analyse par le script car la colonne ccb_truk_unite_rangement
|
| - |
|
131 |
// est tout de même quelquefois remplie par une syntaxe d'ontologie vide quand il n'y a rien)
|
| - |
|
132 |
if($collection_a_modifier) {
|
| - |
|
133 |
$update = "UPDATE coel_collection_botanique ".
|
| - |
|
134 |
"SET ";
|
| - |
|
135 |
|
| - |
|
136 |
$champs = array();
|
| - |
|
137 |
|
| - |
|
138 |
if(!empty($unite_rangement_des['liasses'])) {
|
| - |
|
139 |
$champs[] = "ccb_nb_liasses = ".$this->bdd->proteger($unite_rangement_des['liasses']['nombre']).", ".
|
| - |
|
140 |
"ccb_format_liasses = ".$this->bdd->proteger($unite_rangement_des['liasses']['format'])." ";
|
| - |
|
141 |
}
|
| - |
|
142 |
|
| - |
|
143 |
if(!empty($unite_rangement_des['cartons'])) {
|
| - |
|
144 |
$champs[] = "ccb_nb_cartons_herbier = ".$this->bdd->proteger($unite_rangement_des['cartons']['nombre']).", ".
|
| - |
|
145 |
"ccb_format_cartons_herbier = ".$this->bdd->proteger($unite_rangement_des['cartons']['format'])." ";
|
| - |
|
146 |
}
|
| - |
|
147 |
|
| - |
|
148 |
if(!empty($unite_rangement_des['autres'])) {
|
| - |
|
149 |
// Pour éviter de casser les sauts de lignes il faut les remplacer après avoir protégé la valeur
|
| - |
|
150 |
$champs[] = "ccb_autres_unites_rangement = ".str_replace('NEWLINE', "\r\n", $this->bdd->proteger(implode('NEWLINE', $unite_rangement_des['autres'])));
|
| - |
|
151 |
}
|
| - |
|
152 |
|
| - |
|
153 |
$update .= implode(', ', $champs)." ".
|
| - |
|
154 |
"WHERE ccb_id_collection = '".$id_collection."'";
|
| - |
|
155 |
|
| - |
|
156 |
$this->bdd->executer($update);
|
| - |
|
157 |
}
|
| - |
|
158 |
}
|
| - |
|
159 |
}
|
| - |
|
160 |
|
| - |
|
161 |
private function parserUniteRangement($unite_rangement) {
|
| - |
|
162 |
$tableau_unite_rangement = explode('||', $unite_rangement);
|
| - |
|
163 |
return array(
|
| - |
|
164 |
'nombre' => $tableau_unite_rangement[0],
|
| - |
|
165 |
'precision' => $tableau_unite_rangement[1],
|
| - |
|
166 |
'format' => $tableau_unite_rangement[2]
|
| - |
|
167 |
);
|
| - |
|
168 |
}
|
| - |
|
169 |
|
| - |
|
170 |
private function formaterLigneAutreUniteRangement($id_ontologie, $ontologie_rangement, $tableau_unite_rangement) {
|
| - |
|
171 |
$nom_rangement = $id_ontologie;
|
| - |
|
172 |
|
| - |
|
173 |
// Des fois on a un numéro d'ontologie des fois un nom de type de rangement
|
| - |
|
174 |
if(!is_numeric($id_ontologie)) {
|
| - |
|
175 |
$nom_rangement = $id_ontologie;
|
| - |
|
176 |
} else if(!empty($ontologie_rangement[$id_ontologie])) {
|
| - |
|
177 |
$nom_rangement = $ontologie_rangement[$id_ontologie]['cmlv_nom'];
|
| - |
|
178 |
} else {
|
| - |
|
179 |
$nom_rangement = 'Type de rangement inconnu';
|
| - |
|
180 |
}
|
| - |
|
181 |
|
| - |
|
182 |
// Le nombre d'unités est directement accolé au type
|
| - |
|
183 |
$tab_autre_ligne_rangement = array($nom_rangement);
|
| - |
|
184 |
if(!empty($tableau_unite_rangement['nombre'])) {
|
| - |
|
185 |
$tab_autre_ligne_rangement[0] .= ' : '.$tableau_unite_rangement['nombre'];
|
| - |
|
186 |
}
|
| - |
|
187 |
|
| - |
|
188 |
// La précision est soit exacte soit approximative
|
| - |
|
189 |
if(!empty($tableau_unite_rangement['precision'])) {
|
| - |
|
190 |
$precision = $tableau_unite_rangement['precision'] == 'E' ? 'exacte' : 'appromixative';
|
| - |
|
191 |
$tab_autre_ligne_rangement[] = 'Précision '.$precision;
|
| - |
|
192 |
}
|
| - |
|
193 |
|
| - |
|
194 |
// Le format est une suite de de type YxZ ou Y et Z sont des longueurs et largeurs
|
| - |
|
195 |
// eventuellement séparés par des virgules s'il y a différents formats
|
| - |
|
196 |
if(!empty($tableau_unite_rangement['format'])) {
|
| - |
|
197 |
$tab_autre_ligne_rangement[] = 'Format '.$tableau_unite_rangement['format'];
|
| - |
|
198 |
}
|
| 75 |
}
|
199 |
// On retourne une ligne de la forme "type de rangement : nombre - Précision précision - Format format"
|
| 76 |
}
|
200 |
return implode(' - ', $tab_autre_ligne_rangement);
|
| 77 |
}
|
201 |
}
|