Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 721 Rev 932
Line 134... Line 134...
134
			} else {
134
			} else {
135
				if ($this->recherche == 'etendue') {
135
				if ($this->recherche == 'etendue') {
136
					$valeur = '%'.str_replace(' ','% ', $valeur);
136
					$valeur = '%'.str_replace(' ','% ', $valeur);
137
					$valeur .= '%';
137
					$valeur .= '%';
138
				}
138
				}
139
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
139
				$this->requete_condition[] = 'nva.'.$nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
140
			}
140
			}
141
		}
141
		}
142
	}
142
	}
Line 143... Line 143...
143
 
143
 
Line 150... Line 150...
150
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
150
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
151
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
151
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
152
				}
152
				}
153
			}
153
			}
154
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
154
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
155
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
155
			$this->requete_champ = array('distinct(nva.num_nom_vernaculaire)', 'nva.nom_vernaculaire ');
156
		}
156
		}
157
	}
157
	}
Line 158... Line 158...
158
 
158
 
159
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
159
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
160
	public function traiterRessourceId() {
160
	public function traiterRessourceId() {
161
		if (is_numeric($this->ressources[0])) {
161
		if (is_numeric($this->ressources[0])) {
162
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
162
			$this->requete_condition[] = ' nva.num_nom_vernaculaire = '.$this->getBdd()->proteger($this->ressources[0]);
163
			$this->format_reponse .= '/id';
163
			$this->format_reponse .= '/id';
164
		} elseif ($this->ressources[0] == 'attributions') {
164
		} elseif ($this->ressources[0] == 'attributions') {
165
			$this->format_reponse .= '/attributions';
165
			$this->format_reponse .= '/attributions';
166
		} else {
166
		} else {
Line 196... Line 196...
196
	}
196
	}
Line 197... Line 197...
197
 
197
 
198
	//+------------------------------------------------------------------------------------------------------+
198
	//+------------------------------------------------------------------------------------------------------+
199
	public function assemblerLaRequete() {
199
	public function assemblerLaRequete() {
200
		$requete = ' SELECT '.$this->formerRequeteChamp().
200
		$requete = ' SELECT '.$this->formerRequeteChamp().
201
					', CASE code_langue WHEN "fra" THEN 1 ELSE 0 END AS tri '.
201
		', CASE nva.code_langue WHEN "fra" THEN 1 ELSE 0 END AS tri '.
-
 
202
			' FROM '.str_replace('nva', 'nva_index', $this->table).' inva'.
202
					' FROM '.$this->table
203
			' LEFT JOIN '.$this->table.' nva ON nva.num_nom_vernaculaire = inva.num_nom_vernaculaire '
203
					.$this->formerRequeteCondition().
204
			.$this->formerRequeteCondition().
204
					' ORDER BY tri DESC, nom_vernaculaire ASC '
205
			' ORDER BY tri DESC, nva.nom_vernaculaire ASC '
205
					.$this->formerRequeteLimite();
206
			.$this->formerRequeteLimite();
206
		return $requete;
207
		return $requete;
Line 207... Line 208...
207
	}
208
	}
208
 
209
 
Line 238... Line 239...
238
		return $this->requete_limite;
239
		return $this->requete_limite;
239
	}
240
	}
Line 240... Line 241...
240
 
241
 
241
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
242
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
242
	public function recupererTotalResultat() {
243
	public function recupererTotalResultat() {
243
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct id ';
244
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? '*' : 'distinct nva.num_nom_vernaculaire';
-
 
245
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
-
 
246
			.str_replace('nva', 'nva_index', $this->table).' inva '
244
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
247
			.'INNER JOIN '.$this->table.' nva ON nva.num_nom_vernaculaire = '
245
			.$this->table
248
			.'inva.num_nom_vernaculaire '
-
 
249
			.$this->formerRequeteCondition();
246
			.$this->formerRequeteCondition();
250
 
Line 247... Line 251...
247
		$res = $this->getBdd()->recuperer($requete);
251
		$res = $this->getBdd()->recuperer($requete);
248
 
252
 
249
		if ($res) {
253
		if ($res) {
Line 289... Line 293...
289
	public function ajouterJsonResultatNV($resultat) {
293
	public function ajouterJsonResultatNV($resultat) {
290
		foreach ($resultat as $tab) {
294
		foreach ($resultat as $tab) {
291
			foreach ($tab as $key => $valeur) {
295
			foreach ($tab as $key => $valeur) {
292
				if ($valeur != '') {
296
				if ($valeur != '') {
293
					switch ($key) {
297
					switch ($key) {
294
						case 'id'				: $num = $valeur;								break;
298
						case 'num_nom_vernaculaire'				: $num = $valeur;								break;
295
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
299
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
296
						default					:												break;
300
						default					:												break;
297
					}
301
					}
298
				}
302
				}
299
			}
303
			}
Line 343... Line 347...
343
					$table_nom[] = $tab['nom_vernaculaire'];
347
					$table_nom[] = $tab['nom_vernaculaire'];
344
					$oss [] = $tab['nom_vernaculaire'];
348
					$oss [] = $tab['nom_vernaculaire'];
345
				}
349
				}
346
			}
350
			}
347
		}
351
		}
348
		if (isset($this->masque)) $masque = implode('&', $this->masque);
352
		$masque = $this->recupererMasque();
-
 
353
		if($masque == "") {
349
		else $masque = 'Pas de masque';
354
			$masque = "Pas de masque";
-
 
355
		}
350
		$table_retour_oss = array($masque, $oss);
356
		$table_retour_oss = array($masque, $oss);
351
		return $table_retour_oss;
357
		return $table_retour_oss;
352
	}
358
	}
Line 353... Line 359...
353
	
359
	
Line 363... Line 369...
363
		if (isset($url['suivant']) && $url['suivant']   != '') {
369
		if (isset($url['suivant']) && $url['suivant']   != '') {
364
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
370
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
365
		}
371
		}
366
		foreach ($resultat as &$tab) {	
372
		foreach ($resultat as &$tab) {	
367
			unset($tab['tri']);		
373
			unset($tab['tri']);		
-
 
374
			$id_nom = $tab['num_nom_vernaculaire'];
368
			$resultat_json[$tab['id']]['id'] = $tab['id'];
375
			$resultat_json[$id_nom]['id'] = $id_nom;
369
			$resultat_json[$tab['id']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
376
			$resultat_json[$id_nom]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
370
			$resultat_json[$tab['id']]['code_langue'] = $tab['code_langue'];
377
			$resultat_json[$id_nom]['code_langue'] = $tab['code_langue'];
371
			$resultat_json[$tab['id']]['taxon.code'] = 'bdtxa.nt:'.$tab['num_taxon'];
378
			$resultat_json[$id_nom]['taxon.code'] = 'bdtxa.nt:'.$tab['num_taxon'];
372
			if ($this->retour_format == 'max') {
379
			if ($this->retour_format == 'max') {
373
				$resultat_json[$tab['id']]['num_taxon'] = $tab['num_taxon'];
380
				$resultat_json[$id_nom]['num_taxon'] = $tab['num_taxon'];
374
				$resultat_json[$tab['id']]['nom_retenu.code'] = $tab['num_taxon'];
381
				$resultat_json[$id_nom]['nom_retenu.code'] = $tab['num_taxon'];
375
				$resultat_json[$tab['id']]['taxon'] = $tab['num_taxon'];
382
				$resultat_json[$id_nom]['taxon'] = $tab['num_taxon'];
376
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
383
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
377
				$resultat_json[$tab['id']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
384
				$resultat_json[$id_nom]['href'] = $this->ajouterHref('noms-vernaculaires', $id_nom);
Line 378... Line 385...
378
				
385
				
379
				if($this->champs_supp != array()) {
386
				if($this->champs_supp != array()) {
380
					$resultat_json[$tab['id']] = $this->ajouterChampsOntologieLigneResultat($tab);
387
					$resultat_json[$id_nom] = $this->ajouterChampsOntologieLigneResultat($tab);
381
				}
388
				}
382
			}
389
			}
Line 383... Line 390...
383
		}
390
		}
Line 479... Line 486...
479
	// langue
486
	// langue
480
	// num_nom (correspond à un taxon bdtxa)
487
	// num_nom (correspond à un taxon bdtxa)
481
	public function formaterNomsVernaculairesId($resultat) {
488
	public function formaterNomsVernaculairesId($resultat) {
482
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtxa
489
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtxa
483
			// on crée les variables qui serviront de clés et on les enléves du tableau
490
			// on crée les variables qui serviront de clés et on les enléves du tableau
484
			$num_nom = $taxon['id']; // unique pour un trinôme id, langue, taxon
491
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
485
			unset($taxon['id']);
492
			unset($taxon['num_nom_vernaculaire']);
486
			$langue = $taxon['code_langue'];
493
			$langue = $taxon['code_langue'];
487
			unset($taxon['code_langue']);
494
			unset($taxon['code_langue']);
Line 488... Line 495...
488
 
495
 
489
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
496
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
Line 501... Line 508...
501
		unset($this->table_retour['href']);
508
		unset($this->table_retour['href']);
502
		return $this->table_retour;
509
		return $this->table_retour;
503
	}
510
	}
Line 504... Line 511...
504
 
511
 
505
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
512
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
506
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
513
		if ($champ == 'num_nom_vernaculaire' || $champ == 'nom_vernaculaire') {
507
			$this->table_retour[$champ] = $valeur;
514
			$this->table_retour[$champ] = $valeur;
508
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
515
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
509
				switch ($match[1]) {
516
				switch ($match[1]) {
510
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
517
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}