Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 279 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 279 Rev 280
Line 187... Line 187...
187
	public function assemblerLaRequete() {
187
	public function assemblerLaRequete() {
188
		$requete = ' SELECT '.$this->formerRequeteChamp().
188
		$requete = ' SELECT '.$this->formerRequeteChamp().
189
					' FROM '.$this->table
189
					' FROM '.$this->table
190
					.$this->formerRequeteCondition()
190
					.$this->formerRequeteCondition()
191
					.$this->formerRequeteLimite();
191
					.$this->formerRequeteLimite();
192
		
-
 
193
		return $requete;
192
		return $requete;
194
	}
193
	}
Line 195... Line 194...
195
 
194
 
196
	public  function formerRequeteChamp() {
195
	public  function formerRequeteChamp() {
Line 334... Line 333...
334
		}
333
		}
335
		if (isset($url['suivant']) && $url['suivant']   != '') {
334
		if (isset($url['suivant']) && $url['suivant']   != '') {
336
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
335
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
337
		}
336
		}
Line 338... Line 337...
338
 
337
		
339
		foreach ($resultat as $tab) {			
338
		foreach ($resultat as &$tab) {			
340
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
339
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
341
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
340
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
342
			$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
341
			$resultat_json[$tab['num_nom_vernaculaire']]['code_langue'] = $tab['code_langue'];
343
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
342
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
344
			if ($this->retour_format == 'max') {
343
			if ($this->retour_format == 'max') {
345
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
344
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
346
				$resultat_json[$tab['num_nom_vernaculaire']]['nom_retenu.code'] = $tab['num_taxon'];
345
				$resultat_json[$tab['num_nom_vernaculaire']]['nom_retenu.code'] = $tab['num_taxon'];
347
				$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
346
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins
-
 
347
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
-
 
348
				$resultat_json[$tab['num_nom_vernaculaire']] = $this->ajouterChampsOntologieLigneResultat($tab);
348
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
349
			}
Line 349... Line 350...
349
			}
350
		}
350
			
351
		
351
			if($this->retour_format == 'max') {
352
		if ($this->retour_format == 'max') {
352
				//TODO: la fonction afficherTaxonsAttributions itere sur tout le tableau de résultats alors qu'elle ne devrait
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
353
				// traiter qu'une ligne à la fois (i.e.: la ligne en cours dans $tab), ce qui serait bien plus rapide
355
			$noms_sci = $this->recupererNomTaxons();
354
				$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
356
			foreach ($resultat_json as &$tab) {
355
				$resultat_json[$tab['num_nom_vernaculaire']] = $this->afficherChampsSupplementairesOntologie($tab);
357
				$tab = $this->ajouterTaxonsAttributionsLigneResultat(&$resultat_json[$tab['num_nom_vernaculaire']], &$noms_sci);
-
 
358
			}
356
			}
359
		}
357
		}
360
		
358
		uasort($resultat_json, array($this,'trierLigneTableau'));
361
		uasort($resultat_json, array($this,'trierLigneTableau'));
359
		$table_retour_json['resultat'] = $resultat_json;
362
		$table_retour_json['resultat'] = $resultat_json;
Line 360... Line 363...
360
		return $table_retour_json;
363
		return $table_retour_json;
-
 
364
	}
-
 
365
	
361
	}
366
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
362
	
367
		
363
	public function afficherChampsSupplementairesOntologie($ligne_resultat) {
368
		$intitule = '';
364
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
369
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
365
			extract($champs_supplementaires);
370
			extract($champs_supplementaires);
366
			$valeur_recherche = '';
371
			$valeur_recherche = '';
-
 
372
			switch($cle) {
367
			switch($cle) {
373
				case 'taxon':
368
				case 'taxon':
374
					$valeur_recherche = $ligne_resultat['num_taxon'];
369
					$valeur_recherche = $ligne_resultat['num_taxon'];
375
					$intitule = 'taxon.code';
-
 
376
					break;
370
					break;
377
				case 'genre':
371
				case 'genre':
378
					$valeur_recherche = $ligne_resultat['num_genre'];
372
					$valeur_recherche = $ligne_resultat['num_genre'];
379
					$intitule = 'genre';
-
 
380
					break;
373
					break;
381
				case 'conseil_emploi':
374
				case 'conseil_emploi':
382
					$valeur_recherche = $ligne_resultat['num_statut'];
375
					$valeur_recherche = $ligne_resultat['num_statut'];
383
					$intitule = 'conseil_emploi'; 
376
					break;
384
					break;
377
			}
385
			}
378
			$code_valeur = '';
386
			$code_valeur = '';
379
			if(trim($valeur_recherche) != '') {
387
			if(trim($valeur_recherche) != '') {
380
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
388
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
381
				$code_valeur = $this->chercherSignificationCode($url, $nom);
389
				$code_valeur = $this->chercherSignificationCode($url, $nom);
382
			}
390
			}
383
			$ligne_resultat[$cle] = $code_valeur;
391
			$ligne_resultat[$intitule] = $code_valeur;
Line -... Line 392...
-
 
392
		}
384
		}
393
		return $ligne_resultat;
-
 
394
	}
385
		return $ligne_resultat;
395
	
386
	}
396
	/**
-
 
397
	 * Fonction qui ajoute les attributions à une ligne de résultats
-
 
398
	 *
-
 
399
	 * @param array $ligne_tableau_resultat
387
	
400
	 * @param array $ligne_originale
388
	public function afficherTaxonsAttributions($resultat) {
401
	 * @param array $nom_sci
389
		$nom_sci = $this->recupererNomTaxons();
402
	 */
390
		foreach ($resultat as $num=>$tab) {
-
 
391
			if (isset($nom_sci[$tab['taxon']])) {
403
	public function ajouterTaxonsAttributionsLigneResultat($ligne_tableau_resultat, $noms_sci) {
392
				$resultat[$num]['nom_retenu.code'] = $nom_sci[$tab['taxon']]['id'];
404
		if (isset($nom_sci[$ligne_tableau_resultat['taxon.code']])) {
393
				$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']]['nom_sci'];
405
			$ligne_tableau_resultat['nom_retenu.code'] = $nom_sci[$ligne_tableau_resultat['taxon']]['id'];
Line 394... Line 406...
394
			}
406
			$ligne_tableau_resultat['taxon'] = $nom_sci[$ligne_tableau_resultat['taxon']]['nom_sci'];
-
 
407
		}
-
 
408
		return $ligne_tableau_resultat;
395
		}
409
	}
-
 
410
	
-
 
411
	private function trierLigneTableau($a, $b) {
-
 
412
		$retour = 0;
-
 
413
		
-
 
414
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
-
 
415
			$retour = 0;
-
 
416
		}
-
 
417
				
-
 
418
		if($this->champ_tri == 'code_langue') {
-
 
419
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
-
 
420
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
-
 
421
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
-
 
422
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
-
 
423
			} else {
-
 
424
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
-
 
425
			}
-
 
426
		} else {
-
 
427
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
396
		return $resultat;
428
		}
397
	}
429
		return $retour;
398
	
430
	}
399
	private function trierLigneTableau($a, $b) {
431
	
400
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) return 0;
432
	private function comparerChaineSelonDirectionTri($a, $b) {
401
		if($this->direction_tri == 'asc') {
433
		if($this->direction_tri == 'asc') {
Line 402... Line 434...
402
			return ($a[$this->champ_tri] < $b[$this->champ_tri]) ? -1 : 1;
434
			return ($a < $b) ? -1 : 1;
403
		} else {
435
		} else {