Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 233 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
225 jpm 1
<?php
2
/**
3
 * Exemple de lancement du script : /opt/lampp/bin/php cli.php ontologie -a analyser
4
 *
5
 */
233 jpm 6
require_once dirname(__FILE__).DS.'Traduction.php';
7
 
232 jpm 8
class Prometheus extends EfloreScript {
225 jpm 9
 
233 jpm 10
	private $projetDossier = '';
225 jpm 11
	private $lecteur = null;
12
	private $fichier = '';
13
	private $lotsTermes = array();
14
	private $lotsRelations = array();
226 jpm 15
	private $lotsImages = array();
16
	private $lotsPublications = array();
17
	private $lotsAuteurs = array();
18
	private $lotsHierarchie = array();
225 jpm 19
	private $baseIdGroupe = 10000;
20
	private $baseIdSousGroupe = 20000;
21
	private $types = array(
22
		'FREQUENCY_MODIFIERS' => 2,
23
		'QUALIFIERS' => 3,
24
		'RELATIVE_MODIFIERS' => 4,
25
		'RELATIVE_VALUES' => 5,
26
		'SPATIAL_MODIFIERS' => 6,
27
		'LOCATER_REGIONS' => 7,
28
		'TEMPORAL_MODIFIERS' => 8,
29
		'UNIT_TERMS' => 9,
30
		'QUANTITATIVE_PROPERTIES' => 10,
31
		'NEW_QUALITATIVE_PROPERTIES' => 11,
32
		'DISALLOWED_TERMS' => 20,
226 jpm 33
		'QUALITATIVE_STATES' => 13,
34
		'TYPE_OF_STRUCTURE_TERMS' => 14,
35
		'STRUCTURE_TERMS' => 15,
36
		'REGION_TERMS' => 16,
37
		'GENERIC_STRUCTURES' => 17);
225 jpm 38
 
39
	public function executer() {
40
		try {
232 jpm 41
			$this->initialiserProjet('prometheus');
233 jpm 42
			$this->projetDossier = Config::get('dossierTsv');
232 jpm 43
 
233 jpm 44
			$this->fichier = $this->projetDossier.'Ontology.xml';
225 jpm 45
			// Lancement de l'action demandée
46
			$cmd = $this->getParametre('a');
47
		    switch ($cmd) {
232 jpm 48
		    	case 'chargerTous' :
49
		    		$this->chargerStructureSql();
50
		    		$this->lireFichierXml();
51
		    		break;
52
		    	case 'chargerStructureSql' :
53
		    		$this->chargerStructureSql();
54
		    		break;
225 jpm 55
		    	case 'analyser' :
56
					$this->vider();
57
		    		$this->lireFichierXml();
58
					break;
233 jpm 59
				case 'chargerTraductions' :
60
					$this->viderTraductions();
61
					$this->chargerTraductions();
62
					break;
225 jpm 63
		    	case 'vider' :
64
		    		$this->vider();
233 jpm 65
		    	case 'viderTraductions' :
66
		    		$this->viderTraductions();
67
		    		break;
232 jpm 68
		    	case 'supprimerTous' :
69
		    		$this->supprimerTous();
70
		    		break;
225 jpm 71
				default :
72
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
73
			}
74
		} catch (Exception $e) {
75
			$this->traiterErreur($e->getMessage());
76
		}
77
    }
78
 
79
 
80
    /**
81
	 * Lit le fichier OSM et lance l'analyse des noeuds xml en fonction de leur type.
82
	 */
83
	private function lireFichierXml() {
84
		$termes = array_keys($this->types);
85
		$this->lecteur = new XMLReader();
86
		if ($this->ouvrirFichierXml()) {
87
			while ($this->lecteur->read()) {
88
				if ($this->lecteur->nodeType == XMLREADER::ELEMENT) {
89
					if (in_array($this->lecteur->localName, $termes)) {
90
						$noeud = $this->obtenirNoeudSimpleXml();
91
						$type = $this->lecteur->localName;
92
						$this->traiterTermes($this->types[$type], $noeud->children());
93
					} else if ($this->lecteur->localName == 'STATE_GROUPS') {
94
						$noeud = $this->obtenirNoeudSimpleXml();
95
						$this->traiterGroupes($noeud->children());
226 jpm 96
					} else if ($this->lecteur->localName == 'NewQualitativeProperties') {
97
						$noeud = $this->obtenirNoeudSimpleXml();
98
						$this->traiterNouvellesQualites($noeud->children());
99
					} else if ($this->lecteur->localName == 'RELATIONSHIPS') {
100
						$noeud = $this->obtenirNoeudSimpleXml();
101
						$this->traiterRelations($noeud->children());
102
					} else if ($this->lecteur->localName == 'PICTURES') {
103
						$noeud = $this->obtenirNoeudSimpleXml();
104
						$this->traiterImages($noeud->children());
105
					} else if ($this->lecteur->localName == 'CITATIONS') {
106
						$noeud = $this->obtenirNoeudSimpleXml();
107
						$this->traiterCitations($noeud->children());
108
					} else if ($this->lecteur->localName == 'AUTHORS') {
109
						$noeud = $this->obtenirNoeudSimpleXml();
110
						$this->traiterAuteurs($noeud->children());
111
					} else if ($this->lecteur->localName == 'TreeNode') {
112
						$noeud = $this->obtenirNoeudSimpleXml();
113
						$this->traiterHierarchie($noeud);
225 jpm 114
					}
115
				}
116
			}
117
			if (count($this->lotsTermes) > 0) {
118
				$this->insererLotDeTermes();
119
			}
120
			if (count($this->lotsRelations) > 0) {
121
				$this->insererLotDeRelations();
122
			}
226 jpm 123
			if (count($this->lotsImages) > 0) {
124
				$this->insererLotImages();
125
			}
126
			if (count($this->lotsPublications) > 0) {
127
				$this->insererLotDePublications();
128
			}
129
			if (count($this->lotsAuteurs) > 0) {
130
				$this->insererLotAuteurs();
131
			}
132
			if (count($this->lotsHierarchie) > 0) {
133
				$this->insererLotHierarchie();
134
			}
225 jpm 135
		}
136
	}
137
 
138
	private function ouvrirFichierXml() {
139
		if ($this->lecteur->open($this->fichier) === false) {
140
			throw new Exception("Impossible d'ouvrir le fichier XML : $this->fichier");
141
		}
142
		return true;
143
	}
144
 
145
	private function obtenirNoeudSimpleXml() {
146
		$doc = new DOMDocument;
147
		$element = $this->lecteur->expand();
148
		$noeud = simplexml_import_dom($doc->importNode($element, true));
149
		return $noeud;
150
	}
151
 
152
	private function traiterTermes($type, $termes) {
153
		foreach ($termes as $terme) {
154
			$id = (int) $terme->attributes()->GLOBALID;
226 jpm 155
			if (isset($this->lotsTermes[$id]) === false) {
225 jpm 156
				$valeur = array();
157
				$valeur[] = (int) $id;
158
				$valeur[] = (int) $type;
159
				$valeur[] = (string) $terme->attributes()->term;
160
				$valeur[] = (string) $this->obtenirDefinition($terme);
161
				$valeur[] = (int) $this->obtenirPreference($terme);
162
				$valeur[] = (int) $this->obtenirAuteur($terme);
226 jpm 163
				$valeur[] = (int) $this->obtenirCitation($terme);
225 jpm 164
				$valeur[] = (int) $this->obtenirImage($terme);
165
				$this->lotsTermes[$id] = $valeur;
166
			}
167
			if (isset($terme->attributes()->parentID)) {
168
				$relation = array();
169
				$relation[] = (int) $terme->attributes()->GLOBALID;
170
				$relation[] = (int) $terme->attributes()->parentID;
171
				$relation[] = 'A POUR PARENT';
226 jpm 172
				$this->ajouterRelation($relation);
225 jpm 173
			}
226 jpm 174
			if (isset($terme->attributes()->PARENT_STRUCTURE_ID)) {
175
				$relation = array();
176
				$relation[] = (int) $terme->attributes()->GLOBALID;
177
				$relation[] = (int) $terme->attributes()->PARENT_STRUCTURE_ID;
178
				$relation[] = 'A POUR STRUCTURE PARENTE';
179
				$this->ajouterRelation($relation);
180
			}
225 jpm 181
			if (isset($terme->attributes()->stateOfNEWPROPERTYID)) {
182
				$relation = array();
183
				$relation[] = (int) $terme->attributes()->GLOBALID;
184
				$relation[] = (int) $terme->attributes()->stateOfNEWPROPERTYID;
185
				$relation[] = 'A POUR NOUVELLE QUALITE';
226 jpm 186
				$this->ajouterRelation($relation);
225 jpm 187
			}
188
		}
189
	}
190
 
191
	private function obtenirDefinition($terme) {
192
		$definition = null;
193
		if (isset($terme->DEFINITION)) {
194
			$definition = $terme->DEFINITION;
195
		}
196
		return $definition;
197
	}
198
 
199
	private function obtenirPreference($terme) {
200
		$preference = '1';
201
		if (isset($terme->attributes()->PREFERRED_TERM)) {
202
			$valeur = (string) $terme->attributes()->PREFERRED_TERM;
203
			$preference = (trim($valeur) == 'Disallowed Term') ? '0' : '1';
204
		}
205
		return $preference;
206
	}
207
 
208
	private function obtenirAuteur($terme) {
209
		$auteur = 0;
210
		if (isset($terme->attributes()->authorID)) {
211
			$auteur = $terme->attributes()->authorID;
212
		} elseif (isset($terme->attributes()->authorREF)) {
213
			$auteur = $terme->attributes()->authorREF;
214
		}
215
		return $auteur;
216
	}
217
 
226 jpm 218
	private function obtenirCitation($terme) {
219
		$citation = 0;
220
		if (isset($terme->attributes()->citationID)) {
221
			$citation = $terme->attributes()->citationID;
222
		} elseif (isset($terme->attributes()->citationREF)) {
223
			$citation = $terme->attributes()->citationREF;
224
		}
225
		return $citation;
226
	}
227
 
225 jpm 228
	private function obtenirImage($terme) {
229
		$image = 0;
230
		if (isset($terme->attributes()->pictureREF)) {
231
			$image = $terme->attributes()->pictureREF;
232
		}
233
		return $image;
234
	}
235
 
236
	private function traiterGroupes($groupes) {
237
		foreach ($groupes as $groupe) {
238
			$id = $this->baseIdGroupe + (int) $groupe->attributes()->GROUP_ID;
226 jpm 239
			if (isset($this->lotsTermes[$id]) === false) {
225 jpm 240
				$valeur = array();
241
				$valeur[] = (int) $id;
242
				$valeur[] = 18;
243
				$valeur[] = (string) $groupe->attributes()->groupName;
244
				$valeur[] = '';
245
				$valeur[] = 1;
246
				$valeur[] = 0;
247
				$valeur[] = 0;
248
				$valeur[] = 0;
249
				$this->lotsTermes[$id] = $valeur;
250
			}
251
			if (isset($groupe->STRUCTURES_LINKED_TO_GROUP)) {
252
				foreach ($groupe->STRUCTURES_LINKED_TO_GROUP->children() as $structure) {
253
					$relation = array();
254
					$relation[] = (int) $structure->attributes()->GLOBALID;
255
					$relation[] = (int) $id;
256
					$relation[] = 'A POUR GROUPE';
226 jpm 257
					$this->ajouterRelation($relation);
225 jpm 258
				}
259
			}
260
			if (isset($groupe->STATES_IN_GROUP)) {
261
				foreach ($groupe->STATES_IN_GROUP->children() as $etat) {
262
					$relation = array();
263
					$relation[] = (int) $id;
264
					$relation[] = (int) $etat->attributes()->GLOBALID;
265
					$relation[] = 'A POUR ETAT';
226 jpm 266
					$this->ajouterRelation($relation);
225 jpm 267
				}
268
			}
269
			if (isset($groupe->STATESUBGROUPS)) {
270
				$this->traiterSousGroupes($id, $groupe->STATESUBGROUPS->children());
271
			}
272
		}
273
	}
274
 
275
	private function traiterSousGroupes($idGroupe, $sousGroupes) {
276
		foreach ($sousGroupes as $sg) {
277
			$id = $this->baseIdSousGroupe + (int) $sg->attributes()->STATESUBGROUP_GLOBALID;
226 jpm 278
			if (isset($this->lotsTermes[$id]) === false) {
225 jpm 279
				$valeur = array();
280
				$valeur[] = (int) $id;
281
				$valeur[] = 19;
282
				$valeur[] = (string) $sg->attributes()->subgGroupName;
283
				$valeur[] = '';
284
				$valeur[] = 1;
285
				$valeur[] = 0;
286
				$valeur[] = 0;
287
				$valeur[] = 0;
288
				$this->lotsTermes[$id] = $valeur;
289
 
290
				$relation = array();
291
				$relation[] = (int) $idGroupe;
292
				$relation[] = (int) $id;
293
				$relation[] = 'A POUR SOUS-GROUPE';
226 jpm 294
				$this->ajouterRelation($relation);
225 jpm 295
			}
296
			if (isset($sg->STATES_IN_SUBGROUP)) {
297
				foreach ($sg->STATES_IN_SUBGROUP->children() as $etat) {
298
					$relation = array();
299
					$relation[] = (int) $id;
300
					$relation[] = (int) $etat->attributes()->GLOBALID;
301
					$relation[] = 'A POUR ETAT';
226 jpm 302
					$this->ajouterRelation($relation);
225 jpm 303
				}
304
			}
305
		}
306
	}
307
 
226 jpm 308
	private function traiterNouvellesQualites($qualites) {
309
		foreach ($qualites as $qualite) {
310
			$id = (int) $qualite->attributes()->IDSEQ;
311
			if (isset($this->lotsTermes[$id]) === false) {
312
				$valeur = array();
313
				$valeur[] = (int) $id;
314
				$valeur[] = 11;
315
				$valeur[] = (string) $qualite->attributes()->term;
316
				$valeur[] = (string) $this->obtenirDefinition($terme);
317
				$valeur[] = (int) $this->obtenirPreference($terme);
318
				$valeur[] = (int) $this->obtenirAuteur($terme);
319
				$valeur[] = (int) $this->obtenirCitation($terme);
320
				$valeur[] = (int) $this->obtenirImage($terme);
321
				$this->lotsTermes[$id] = $valeur;
322
			}
323
			if (isset($qualite->attributes()->ParentPropertyID)) {
324
				$relation = array();
325
				$relation[] = (int) $qualite->attributes()->IDSEQ;
326
				$relation[] = (int) $qualite->attributes()->ParentPropertyID;
327
				$relation[] = 'A POUR PARENT';
328
				$this->ajouterRelation($relation);
329
			}
330
			if (isset($qualite->MemberStates)) {
331
				$etats = $qualite->MemberStates->children();
332
				$idParent = $qualite->attributes()->IDSEQ;
333
				$this->traiterEtatsMembre($etats, $idParent);
334
			}
335
			if (isset($qualite->Structures_linked_to_Property)) {
336
				$structures = $qualite->Structures_linked_to_Property->children();
337
				$idParent = $qualite->attributes()->IDSEQ;
338
				$this->traiterStructuresLiees($structures, $idParent);
339
			}
340
			if (isset($qualite->ContextGroups)) {
341
				$contextes = $qualite->ContextGroups->children();
342
				if (count($contextes) > 0) {
343
					foreach ($contextes as $contexte) {
344
						$idParent = $contexte->attributes()->ID;
345
						$structures = $contexte->Structures_linked_to_Context->children();
346
						$this->traiterStructuresLiees($structures, $idParent);
347
						$etats = $contexte->MemberStates->children();
348
						$this->traiterEtatsMembre($etats, $idParent);
349
					}
350
				}
351
			}
352
		}
353
	}
354
 
355
	private function ajouterRelation($relation) {
356
		$id = implode('-', $relation);
357
		if (isset($this->lotsRelations[$id]) === false) {
358
			$this->lotsRelations[$id] = $relation;
359
		}
360
	}
361
 
362
	private function traiterEtatsMembre($etats, $idParent) {
363
		if (count($etats) > 0) {
364
			foreach ($etats as $etat) {
365
				$relation = array();
366
				$relation[] = (int) $idParent;
367
				$relation[] = (int) $etat->attributes()->RefID;
368
				$relation[] = 'A POUR ETAT';
369
				$this->ajouterRelation($relation);
370
			}
371
		}
372
	}
373
 
374
	private function traiterStructuresLiees($structures, $idParent) {
375
		if (count($structures) > 0) {
376
			foreach ($structures as $structure) {
377
				$relation = array();
378
				$relation[] = (int) $structure->attributes()->RefID;
379
				$relation[] = (int) $idParent;
380
				$relation[] = 'A POUR PROPRIETE';
381
				$this->ajouterRelation($relation);
382
			}
383
		}
384
	}
385
 
386
	private function traiterRelations($relations) {
387
		foreach ($relations as $rel) {
388
			$relation = array();
389
			$relation[] = (int) $rel->attributes()->term1REF;
390
			$relation[] = (int) $rel->attributes()->term2REF;
391
			$relation[] = (string) $this->obtenirTypeRelation($rel->attributes()->relationship);
392
			$this->ajouterRelation($relation);
393
		}
394
	}
395
 
396
	private function obtenirTypeRelation($type) {
397
		switch ($type) {
398
			case 'ASSOCIATED WITH' :
399
				$relation = 'ASSOCIE AVEC';
400
				break;
401
			case 'IS A PART OF' :
402
				$relation = 'EST UNE PARTIE DE';
403
				break;
404
			case 'IS A TYPE OF' :
405
				$relation = 'EST UN TYPE DE';
406
				break;
407
			default :
408
				$relation = '';
409
		}
410
		return $relation;
411
	}
412
 
413
	private function traiterImages($images) {
414
		foreach ($images as $img) {
415
			$valeur = array();
416
			$valeur[] = (int) $img->attributes()->ID;
417
			$valeur[] = (string) $img->attributes()->NAME;
418
			$valeur[] = (int) $img->attributes()->CITATION_REFID;
419
			$this->lotsImages[] = $valeur;
420
		}
421
	}
422
 
423
	private function traiterCitations($citations) {
424
		foreach ($citations as $publi) {
425
			$valeur = array();
426
			$valeur[] = (int) $publi->attributes()->ID;
427
			$valeur[] = (int) $publi->attributes()->primaryAuthorREF;
428
			$valeur[] = (string) $publi->PUBLICATION;
429
			$valeur[] = (string) $publi->DATE;
430
			$valeur[] = (string) $publi->PAGE;
431
			$this->lotsPublications[] = $valeur;
432
		}
433
	}
434
 
435
	private function traiterAuteurs($auteurs) {
436
		foreach ($auteurs as $auteur) {
437
			$valeur = array();
438
			$valeur[] = (int) $auteur->attributes()->ID;
439
			$valeur[] = (string) $auteur->attributes()->givenNames;
440
			$valeur[] = (string) $auteur->attributes()->surname;
441
			$valeur[] = $this->obtenirDateNaissance((string) $auteur->attributes()->born);
442
			$valeur[] = (string) $auteur->attributes()->died;
443
			$this->lotsAuteurs[] = $valeur;
444
		}
445
	}
446
 
447
	private function obtenirDateNaissance($annee) {
448
		$date = $annee.'-00-00';
449
		return $date;
450
	}
451
 
452
	private function traiterHierarchie($noeud) {
453
		$valeur = array();
454
		$valeur[] = (int) $noeud->attributes()->ID;
455
		$valeur[] = (int) $noeud->attributes()->ParentNodeID;
456
		$valeur[] = (string) $noeud->attributes()->pathAsNames;
457
		$valeur[] = (string) $noeud->attributes()->pathAsID;
458
		$valeur[] = (int) $noeud->attributes()->TermID;
459
		$this->lotsHierarchie[] = $valeur;
460
	}
461
 
225 jpm 462
	private function insererLotDeTermes() {
232 jpm 463
		$champs = implode(',', array('id_terme', 'ce_type', 'nom_en', 'description_en', 'preference', 'ce_auteur', 'ce_publication', 'ce_image'));
225 jpm 464
		$values = $this->creerValues($this->lotsTermes);
232 jpm 465
		$requete = "INSERT INTO prometheus_ontologies_terme_v1_00 ($champs) VALUES $values";
225 jpm 466
		$this->executerSql($requete);
467
	}
468
 
469
	private function insererLotDeRelations() {
470
		$champs = implode(',', array('id_terme_01', 'id_terme_02', 'relation'));
471
		$values = $this->creerValues($this->lotsRelations);
232 jpm 472
		$requete = "INSERT INTO prometheus_ontologies_relation_v1_00 ($champs) VALUES $values";
225 jpm 473
		$this->executerSql($requete);
474
	}
475
 
226 jpm 476
	private function insererLotImages() {
477
		$champs = implode(',', array('id_image', 'uri', 'ce_publication'));
478
		$values = $this->creerValues($this->lotsImages);
232 jpm 479
		$requete = "INSERT INTO prometheus_ontologies_image_v1_00 ($champs) VALUES $values";
226 jpm 480
		$this->executerSql($requete);
481
	}
482
 
483
	private function insererLotDePublications() {
484
		$champs = implode(',', array('id_publication', 'ce_auteur_principal', 'titre', 'date', 'uri'));
485
		$values = $this->creerValues($this->lotsPublications);
232 jpm 486
		$requete = "INSERT INTO prometheus_ontologies_publication_v1_00 ($champs) VALUES $values";
226 jpm 487
		$this->executerSql($requete);
488
	}
489
 
490
	private function insererLotAuteurs() {
491
		$champs = implode(',', array('id_auteur', 'prenom', 'nom', 'naissance_date', 'deces_date'));
492
		$values = $this->creerValues($this->lotsAuteurs);
232 jpm 493
		$requete = "INSERT INTO prometheus_ontologies_auteur_v1_00 ($champs) VALUES $values";
226 jpm 494
		$this->executerSql($requete);
495
	}
496
 
497
	private function insererLotHierarchie() {
498
		$champs = implode(',', array('id_noeud', 'id_noeud_parent', 'chemin_noms', 'chemin_ids', 'ce_terme'));
499
		$values = $this->creerValues($this->lotsHierarchie);
232 jpm 500
		$requete = "INSERT INTO prometheus_ontologies_hierarchie_v1_00 ($champs) VALUES $values";
226 jpm 501
		$this->executerSql($requete);
502
	}
503
 
225 jpm 504
	private function creerValues($valeurs) {
505
		$values = array();
506
		foreach ($valeurs as $valeur) {
507
			foreach ($valeur as $id => $val) {
508
				$valeur[$id] = $this->etreVide($val) ? 'NULL' : $this->proteger(trim($val));
509
			}
510
			$values[]  = '('.implode(',', $valeur).')';
511
		}
512
		$values = implode(',', $values);
513
		return $values;
514
	}
515
 
516
	private function etreVide($val) {
517
		$vide = ($val === null || trim($val) === '') ? true : false;
518
		return $vide;
519
	}
520
 
521
	private function executerSql($requete) {
232 jpm 522
		$this->getBdd()->requeter($requete);
225 jpm 523
	}
524
 
525
	private function proteger($chaine) {
232 jpm 526
		return $this->getBdd()->proteger($chaine);
225 jpm 527
	}
528
 
233 jpm 529
	private function viderTraductions() {
530
		$requete = 'UPDATE prometheus_ontologies_terme_v1_00 '.
531
			'SET nom = NULL, description = NULL, notes = NULL';
532
		$this->executerSql($requete);
533
	}
534
 
535
	private function chargerTraductions() {
536
		$dossier = $this->projetDossier.'traductions'.DS;
537
		$pointeur = opendir($dossier);
538
		while ($fichierNom = readdir($pointeur)) {
539
			if (preg_match('/^[.]{1,2}/', $fichierNom) == false) {
540
				$fichierChemin = $dossier.$fichierNom;
541
				$lecteur = new LecteurExcel($fichierChemin);
542
				//$this->verifierStructureFichierExcel($lecteur);
543
				for ($ligne = 2; $ligne < $lecteur->getNbreLignes(); $ligne++) {
544
					$traduction = new Traduction();
545
					$traduction->type = $lecteur->getValeur($ligne, 1);
546
					$traduction->en = $lecteur->getValeur($ligne, 2);
547
					$traduction->fr = $lecteur->getValeur($ligne, 3);
548
					$traduction->sourcesTraduction = $lecteur->getValeur($ligne, 4);
549
					$traduction->remarques = $lecteur->getValeur($ligne, 5);
550
					$traduction->sources = $lecteur->getValeur($ligne, 6);
551
					$traduction->relectureRemarques = $lecteur->getValeur($ligne, 7);
552
					$this->genererNotes($traduction);
553
 
554
					$this->insererTraduction($traduction);
555
				}
556
			}
557
		}
558
		closedir($pointeur);
559
	}
560
 
561
	private function verifierStructureFichierExcel($lecteur) {
562
		$messages = array();
563
		$colonnes = array("Type d'élément", "Élément en anglais", "Traduction en français", "Sources de la traduction", "Remarques", "Sources", "Relecture/ Remarques");
564
		foreach ($colonnes as $numero => $intitule) {
565
			$valeurBrute = $lecteur->getValeur(1, ($numero + 1));
566
			if ($valeurBrute != $intitule) {
567
				$messages[] = "Le fichier {$lecteur->getFichier()} ne contient pas la bonne colonne #$numero : $intitule != $valeurBrute";
568
			}
569
		}
570
		if (count($messages) > 0) {
571
			throw new Exception(implode("\n", $messages));
572
		}
573
	}
574
 
575
	private function genererNotes(Traduction $traduction) {
576
		$notes = array();
577
		if ($this->etreVide($traduction->sourcesTraduction) === false) {
578
			$notes[] = "Sources de la traduction : ".$traduction->sourcesTraduction;
579
		}
580
		if ($this->etreVide($traduction->remarques) === false) {
581
			$notes[] = "Remarques : ".$traduction->remarques;
582
		}
583
		if ($this->etreVide($traduction->sources) === false) {
584
			$notes[] = "Sources : ".$traduction->sources;
585
		}
586
		if ($this->etreVide($traduction->relectureRemarques) === false) {
587
			$notes[] = "Remarques sur la relecture : ".$traduction->relectureRemarques;
588
		}
589
		if (count($notes) > 0) {
590
			$traduction->notes = implode("\n", $notes);
591
		}
592
	}
593
 
594
	private function insererTraduction($traduction) {
595
		$requete = null;
596
		$notes = $traduction->notes;
597
		if ($traduction->type == 'term') {
598
			$notes = $this->proteger("Nom :\n".$notes);
599
			$nom = $this->proteger($traduction->fr);
600
			$nomEn = $this->proteger($traduction->en);
601
			$requete = "UPDATE prometheus_ontologies_terme_v1_00 ".
602
				"SET nom = $nom, notes = $notes ".
603
				"WHERE nom_en = $nomEn ";
604
		} else if ($traduction->type == 'DEFINITION') {
605
			$notes = $this->proteger("Description :\n".$notes);
606
			$description = $this->proteger($traduction->fr);
607
			$descriptionEn = $this->proteger($traduction->en);
608
			$requete = "UPDATE prometheus_ontologies_terme_v1_00 ".
609
				"SET description = $description, notes = CONCAT(notes, '\n', $notes) ".
610
				"WHERE description_en = $descriptionEn ";
611
		}
612
		if ($requete != null) {
613
			$this->executerSql($requete);
614
		}
615
	}
616
 
225 jpm 617
	private function vider() {
349 jpm 618
		$requete = 'TRUNCATE TABLE IF EXISTS prometheus_ontologies_auteur_v1_00';
225 jpm 619
		$this->executerSql($requete);
349 jpm 620
		$requete = 'TRUNCATE TABLE IF EXISTS prometheus_ontologies_hierarchie_v1_00';
226 jpm 621
		$this->executerSql($requete);
349 jpm 622
		$requete = 'TRUNCATE TABLE IF EXISTS prometheus_ontologies_image_v1_00';
226 jpm 623
		$this->executerSql($requete);
349 jpm 624
		$requete = 'TRUNCATE TABLE IF EXISTS prometheus_ontologies_publication_v1_00';
226 jpm 625
		$this->executerSql($requete);
349 jpm 626
		$requete = 'TRUNCATE TABLE IF EXISTS prometheus_ontologies_relation_v1_00';
225 jpm 627
		$this->executerSql($requete);
349 jpm 628
		$requete = 'TRUNCATE TABLE IF EXISTS prometheus_ontologies_terme_v1_00';
226 jpm 629
		$this->executerSql($requete);
225 jpm 630
	}
232 jpm 631
 
632
	private function supprimerTous() {
349 jpm 633
		$requete = "DROP TABLE IF EXISTS prometheus_meta, prometheus_ontologies_auteur_v1_00, prometheus_ontologies_hierarchie_v1_00,
232 jpm 634
			prometheus_ontologies_image_v1_00, prometheus_ontologies_publication_v1_00, prometheus_ontologies_relation_v1_00,
635
			prometheus_ontologies_terme_v1_00, prometheus_ontologies_type_v1_00";
636
		$this->getBdd()->requeter($requete);
637
	}
225 jpm 638
}
639
?>