Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 282 | Rev 284 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 282 Rev 283
Line 42... Line 42...
42
	protected $requete_condition = '';
42
	protected $requete_condition = '';
43
	protected $limite_requete = array(
43
	protected $limite_requete = array(
44
		'depart' => 0,
44
		'depart' => 0,
45
		'limite' => 100
45
		'limite' => 100
46
	);
46
	);
47
	
-
 
48
	protected $champ_tri = 'code_langue';
-
 
49
	protected $direction_tri = 'asc';
-
 
Line 50... Line 47...
50
 
47
 
51
	/**
48
	/**
52
	 * Precise la contenance plus ou moins précise du tableau à retourner :
49
	 * Precise la contenance plus ou moins précise du tableau à retourner :
53
	 *  - min = les données présentes dans la table
50
	 *  - min = les données présentes dans la table
Line 57... Line 54...
57
	/** Valeur du paramètre de requete recherche :
54
	/** Valeur du paramètre de requete recherche :
58
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
55
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
59
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
56
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
60
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
57
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
61
	protected $recherche;
58
	protected $recherche;
62
	
59
 
63
	/** Permet de stocker le tableau de résultat (non encodé en json) */
60
	/** Permet de stocker le tableau de résultat (non encodé en json) */
64
	protected $table_retour = array();
61
	protected $table_retour = array();
65
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
62
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
66
	protected $total_resultat;
63
	protected $total_resultat;
Line 74... Line 71...
74
				$this->recherche = $this->parametres['recherche'];
71
				$this->recherche = $this->parametres['recherche'];
75
			}
72
			}
76
			foreach ($this->parametres as $param => $valeur) {
73
			foreach ($this->parametres as $param => $valeur) {
77
				switch ($param) {
74
				switch ($param) {
78
					case 'masque' :
75
					case 'masque' :
79
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
76
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
80
						break;
77
						break;
81
					case 'masque.nt' :
78
					case 'masque.nt' :
82
						$this->ajouterFiltreMasque('num_taxon', $valeur);
79
						$this->ajouterLeFiltreMasque('num_taxon', $valeur);
83
						break;
80
						break;
84
					case 'masque.nv' :
81
					case 'masque.nv' :
85
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
82
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
86
						break;
83
						break;
87
					case 'masque.lg' :
84
					case 'masque.lg' :
88
						$this->ajouterFiltreMasque('code_langue', $valeur);
85
						$this->ajouterLeFiltreMasque('code_langue', $valeur);
89
						break;
86
						break;
90
					case 'masque.cce' :
87
					case 'masque.cce' :
91
						$this->ajouterFiltreMasque('num_statut', $valeur);
88
						$this->ajouterLeFiltreMasque('num_statut', $valeur);
92
						break;
89
						break;
93
					case 'retour.format' :
90
					case 'retour.format' :
94
						$this->retour_format = $valeur;
91
						$this->retour_format = $valeur;
95
						break;
92
						break;
96
					case 'navigation.depart' :
93
					case 'navigation.depart' :
Line 110... Line 107...
110
				}
107
				}
111
			}
108
			}
112
		}
109
		}
113
	}
110
	}
Line 114... Line 111...
114
 
111
 
115
	public function ajouterFiltreMasque($nom_champ, $valeur) {
112
	public function ajouterLeFiltreMasque($nom_champ, $valeur) {
116
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
113
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
117
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
114
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
118
		} else {
115
		} else {
119
			if ($this->recherche == 'floue') {
116
			if ($this->recherche == 'floue') {
Line 332... Line 329...
332
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
329
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
333
		}
330
		}
334
		if (isset($url['suivant']) && $url['suivant']   != '') {
331
		if (isset($url['suivant']) && $url['suivant']   != '') {
335
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
332
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
336
		}
333
		}
337
		
334
 
338
		foreach ($resultat as &$tab) {			
335
		foreach ($resultat as $tab) {
339
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
336
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
340
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
337
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
341
			$resultat_json[$tab['num_nom_vernaculaire']]['code_langue'] = $tab['code_langue'];
338
			$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
342
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
339
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
343
			if ($this->retour_format == 'max') {
340
			if ($this->retour_format == 'max') {
344
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
341
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
345
				$resultat_json[$tab['num_nom_vernaculaire']]['nom_retenu.code'] = $tab['num_taxon'];
342
				$resultat_json[$tab['num_nom_vernaculaire']]['nom_retenu.code'] = $tab['num_taxon'];
346
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
343
				$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
347
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
344
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
348
				$resultat_json[$tab['num_nom_vernaculaire']] = $this->ajouterChampsOntologieLigneResultat($tab);
-
 
349
			}
345
			}
350
		}
346
		}
Line 351... Line 347...
351
		
347
		
352
		if ($this->retour_format == 'max') {
-
 
353
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une 
-
 
354
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
-
 
355
			$noms_sci = $this->recupererNomTaxons();
-
 
356
			foreach ($resultat_json as &$tab) {
348
		if ($this->retour_format == 'max') {
357
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($resultat_json[$tab['num_nom_vernaculaire']], $noms_sci);
-
 
358
			}
349
			$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
Line 359... Line -...
359
		}
-
 
360
		
350
		}
361
		uasort($resultat_json, array($this,'trierLigneTableau'));
351
		
362
		$table_retour_json['resultat'] = $resultat_json;
352
		$table_retour_json['resultat'] = $resultat_json;
Line 363... Line 353...
363
		return $table_retour_json;
353
		return $table_retour_json;
364
	}
-
 
365
	
-
 
366
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
-
 
367
		
354
	}
368
		$intitule = '';
-
 
369
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
-
 
370
			extract($champs_supplementaires);
-
 
371
			$valeur_recherche = '';
-
 
372
			switch($cle) {
-
 
373
				case 'taxon':
-
 
374
					$valeur_recherche = $ligne_resultat['num_taxon'];
-
 
375
					$intitule = 'taxon.code';
-
 
376
					break;
-
 
377
				case 'genre':
-
 
378
					$valeur_recherche = $ligne_resultat['num_genre'];
-
 
379
					$intitule = 'genre';
-
 
380
					break;
-
 
381
				case 'conseil_emploi':
-
 
382
					$valeur_recherche = $ligne_resultat['num_statut'];
-
 
383
					$intitule = 'conseil_emploi'; 
-
 
384
					break;
355
	
385
			}
-
 
386
			$code_valeur = '';
-
 
387
			if(trim($valeur_recherche) != '') {
-
 
388
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
-
 
389
				$code_valeur = $this->chercherSignificationCode($url, $nom);
-
 
390
			}
-
 
391
			$ligne_resultat[$intitule] = $code_valeur;
-
 
392
		}
-
 
393
		return $ligne_resultat;
-
 
394
	}
-
 
395
	
-
 
396
	/**
-
 
397
	 * Fonction qui ajoute les attributions à une ligne de résultats
-
 
398
	 *
-
 
399
	 * @param array $ligne_tableau_resultat
-
 
400
	 * @param array $nom_sci
356
	public function afficherTaxonsAttributions($resultat) {
401
	 */
357
		$nom_sci = $this->recupererNomTaxons();
402
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
358
		foreach ($resultat as $num=>$tab) {
403
		if (isset($nom_sci[$ligne_tableau_resultat['taxon.code']])) {
-
 
404
			$ligne_tableau_resultat['nom_retenu.code'] = $nom_sci[$ligne_tableau_resultat['taxon']]['id'];
-
 
405
			$ligne_tableau_resultat['taxon'] = $nom_sci[$ligne_tableau_resultat['taxon']]['nom_sci'];
-
 
406
		}
-
 
407
		return $ligne_tableau_resultat;
-
 
408
	}
-
 
409
	
-
 
410
	private function trierLigneTableau($a, $b) {
-
 
411
		$retour = 0;
-
 
412
		
-
 
413
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
-
 
414
			$retour = 0;
-
 
415
		}
-
 
416
				
-
 
417
		if($this->champ_tri == 'code_langue') {
-
 
418
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
-
 
419
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
-
 
420
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
-
 
421
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
359
			if (isset($nom_sci[$tab['taxon']])) {
422
			} else {
-
 
423
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
-
 
424
			}
-
 
425
		} else {
-
 
426
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
-
 
427
		}
-
 
428
		return $retour;
-
 
429
	}
-
 
430
	
-
 
431
	private function comparerChaineSelonDirectionTri($a, $b) {
-
 
432
		if($this->direction_tri == 'asc') {
-
 
433
			return ($a < $b) ? -1 : 1;
360
				$resultat[$num]['nom_retenu.code'] = $nom_sci[$tab['taxon']]['id'];
-
 
361
				$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']]['nom_sci'];
434
		} else {
362
			}
Line 435... Line 363...
435
			return ($a > $b) ? -1 : 1;
363
		}
436
		}
364
		return $resultat;
437
	}
365
	}
Line 610... Line 538...
610
 
538
 
611
	public function chargerBiblio($num_nom, $langue) {
539
	public function chargerBiblio($num_nom, $langue) {
612
		list($table, $version) = explode('_v',$this->table);
540
		list($table, $version) = explode('_v',$this->table);
613
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
541
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
614
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
542
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
Line 615... Line 543...
615
		$resultat = $this->getBdd()->recupererTous($requete);
543
		$resultat = $this->getBdd()->recupererTous($requete); //Debug::printr($resultat);
616
 
544
 
617
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
545
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
618
		 	$r = 'La requête SQL formée comporte une erreur !!';
546
		 	$r = 'La requête SQL formée comporte une erreur !!';