| 631 | delphine | 1 | <?php
 | 
        
           |  |  | 2 | // declare(encoding='UTF-8');
 | 
        
           |  |  | 3 | /**
 | 
        
           |  |  | 4 | * Classe permettant de fournir des informations sur les noms scientifiques.
 | 
        
           |  |  | 5 | * Si l'url finit par /noms on retourne une liste de noms latin et leurs identifiants (seulement les 100 premeiers noms par défaut).
 | 
        
           |  |  | 6 | * L'url peut contenir des paramètres optionnels passés après le ? : /noms?param1=val1¶m2=val2&...
 | 
        
           | 657 | jpm | 7 | *
 | 
        
           | 631 | delphine | 8 | * Les paramètres de requête disponibles sont : masque, masque.gen (nom de genre), masque.sp (épithète d'espèce), masque.ssp (épithète infra-spécifique),
 | 
        
           | 657 | jpm | 9 | * masque.au (auteur du nom), masque.an (année de publication du nom), masque.bib (réf biblio de la publi d'origine du nom), masque.ad (nomen addendum),
 | 
        
           | 631 | delphine | 10 | * masque.nn (identifiant du nom), recherche, rang, distinct, retour.format, nl.format, nl.structure, navigation.depart et navigation.limite.
 | 
        
           | 657 | jpm | 11 | * Les différentes requetes :
 | 
        
           | 631 | delphine | 12 | *   - noms | noms/relations/#projet/#id_projet | noms/#id | noms/#id/#champ+#champ
 | 
        
           |  |  | 13 | *   - noms/#id/relations | noms/#id/relations/synonymie | noms/#id/relations/homonymie | noms/#id/relations/flores
 | 
        
           |  |  | 14 | *   - noms/stats/rangs | noms/stats/annees | noms/stats/initiales
 | 
        
           | 657 | jpm | 15 | *
 | 
        
           | 631 | delphine | 16 | * @package bdtfx
 | 
        
           |  |  | 17 | * @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
 | 
        
           |  |  | 18 | * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
 | 
        
           |  |  | 19 | * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
 | 
        
           |  |  | 20 | * @version $Id$
 | 
        
           |  |  | 21 | * @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
 | 
        
           |  |  | 22 | * @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Noms
 | 
        
           |  |  | 23 | */
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | class Noms extends CommunNomsTaxons {
 | 
        
           | 657 | jpm | 26 |   | 
        
           | 631 | delphine | 27 | 	protected $format_reponse	 = 'noms'; // Permet de stocker la requete formulée
 | 
        
           |  |  | 28 | 	protected $service 			 = 'noms';
 | 
        
           | 657 | jpm | 29 | 	protected $serviceNom		 = 'noms';
 | 
        
           | 631 | delphine | 30 | 	protected $requete_champ 	 = 'num_nom, nom_sci, num_nom_retenu';
 | 
        
           | 657 | jpm | 31 | 	protected $requete_condition = null;
 | 
        
           | 631 | delphine | 32 | 	protected $requete_group_by  = '';
 | 
        
           |  |  | 33 | 	/** Permet de stocker les limite de la requete SQL (par défaut seul les 100 premiers résultats seront retournés).*/
 | 
        
           | 657 | jpm | 34 | 	protected $limite_requete 	 = array('depart' => 0, 'limite' => 100);
 | 
        
           | 631 | delphine | 35 | 	protected $distinct		 	 = null; // Valeur du paramètre de requete distinct (=0|1)
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | 	public function consulter($ressources, $parametres) {
 | 
        
           |  |  | 38 | 		return parent::consulter($ressources, $parametres);
 | 
        
           |  |  | 39 | 	}
 | 
        
           | 657 | jpm | 40 |   | 
        
           | 631 | delphine | 41 | //+----------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+
 | 
        
           | 657 | jpm | 42 |   | 
        
           | 631 | delphine | 43 | 	public function traiterParametresSpecifiques() {
 | 
        
           |  |  | 44 | 		foreach ($this->parametres as $param => $val) {
 | 
        
           |  |  | 45 | 			switch ($param) {
 | 
        
           |  |  | 46 | 				case 'masque' :
 | 
        
           | 657 | jpm | 47 | 					$this->ajouterFiltreMasque('nom_sci', $val);
 | 
        
           | 631 | delphine | 48 | 					break;
 | 
        
           |  |  | 49 | 				case 'masque.sg' :
 | 
        
           | 657 | jpm | 50 | 					$this->ajouterFiltreMasque('nom_supra_generique', $val);
 | 
        
           | 631 | delphine | 51 | 					break;
 | 
        
           | 667 | jpm | 52 | 				case 'masque.gen' :
 | 
        
           |  |  | 53 | 					$this->ajouterFiltreMasque('genre', $val);
 | 
        
           | 631 | delphine | 54 | 					break;
 | 
        
           | 667 | jpm | 55 | 				case 'masque.sp' :
 | 
        
           |  |  | 56 | 					$this->ajouterFiltreMasque('epithete_sp', $val);
 | 
        
           |  |  | 57 | 					break;
 | 
        
           |  |  | 58 | 				case 'masque.ssp' :
 | 
        
           |  |  | 59 | 					$this->ajouterFiltreMasque('epithete_infra_sp',$val);
 | 
        
           |  |  | 60 | 					break;
 | 
        
           |  |  | 61 | 				case 'masque.au' :
 | 
        
           |  |  | 62 | 					$this->ajouterFiltreMasque('auteur', $val);
 | 
        
           |  |  | 63 | 					break;
 | 
        
           |  |  | 64 | 				case 'masque.an' :
 | 
        
           |  |  | 65 | 					$this->ajouterFiltreMasque('annee', $val);
 | 
        
           |  |  | 66 | 					break;
 | 
        
           |  |  | 67 | 				case 'masque.bib' :
 | 
        
           |  |  | 68 | 					$this->ajouterFiltreMasque('biblio_origine',$val);
 | 
        
           |  |  | 69 | 					break;
 | 
        
           |  |  | 70 | 				case 'masque.ad' :
 | 
        
           |  |  | 71 | 					$this->ajouterFiltreMasque('nom_addendum', $val);
 | 
        
           |  |  | 72 | 					break;
 | 
        
           |  |  | 73 | 				case 'masque.nn' :
 | 
        
           |  |  | 74 | 					$this->requete_condition []= 'num_nom IN ('.$val.')';
 | 
        
           |  |  | 75 | 					$this->masque['num_nom'] = "num_nom=$val";
 | 
        
           |  |  | 76 | 					break;
 | 
        
           |  |  | 77 | 				case 'masque.nt' :
 | 
        
           |  |  | 78 | 					$this->requete_condition []= 'num_tax IN ('.$val.')';
 | 
        
           |  |  | 79 | 					$this->masque['num_tax'] = "num_tax=$val";
 | 
        
           |  |  | 80 | 					break;
 | 
        
           |  |  | 81 | 				case 'masque.rg' :
 | 
        
           |  |  | 82 | 					$this->ajouterFiltreMasque('rang', $val);
 | 
        
           |  |  | 83 | 					break;
 | 
        
           |  |  | 84 | 				case 'retour.champs' :
 | 
        
           |  |  | 85 | 					$this->verifierParamChamps($param, $val);
 | 
        
           |  |  | 86 | 					break;
 | 
        
           |  |  | 87 | 				case 'distinct' :
 | 
        
           |  |  | 88 | 					$this->ajouterNomDistinct($val);
 | 
        
           |  |  | 89 | 					break;
 | 
        
           |  |  | 90 | 				case 'masque.fam' :
 | 
        
           |  |  | 91 | 					$this->ajouterFiltreMasque('famille', $val);
 | 
        
           |  |  | 92 | 					break;
 | 
        
           |  |  | 93 | 				case 'masque.sto' :
 | 
        
           |  |  | 94 | 					$this->ajouterFiltreMasque('statut_origine', $val);
 | 
        
           |  |  | 95 | 					break;
 | 
        
           |  |  | 96 | 				case 'masque.sti' :
 | 
        
           |  |  | 97 | 					$this->ajouterFiltreMasque('statut_introduction', $val);
 | 
        
           |  |  | 98 | 					break;
 | 
        
           |  |  | 99 | 				case 'masque.stc' :
 | 
        
           |  |  | 100 | 					$this->ajouterFiltreMasque('statut_culture', $val);
 | 
        
           |  |  | 101 | 					break;
 | 
        
           |  |  | 102 | 				case 'masque.and' :
 | 
        
           |  |  | 103 | 					$this->requete_condition []= " annee >= ".$this->getBdd()->proteger($val);
 | 
        
           |  |  | 104 | 					break;
 | 
        
           |  |  | 105 | 				case 'masque.anf' :
 | 
        
           |  |  | 106 | 					$this->requete_condition []= " annee <= ".$this->getBdd()->proteger($val);
 | 
        
           |  |  | 107 | 					break;
 | 
        
           | 713 | aurelien | 108 | 				case 'masque.prgua' :
 | 
        
           |  |  | 109 | 					$this->ajouterFiltreMasque('presence_Guadeloupe', $val);
 | 
        
           |  |  | 110 | 					break;
 | 
        
           |  |  | 111 | 				case 'masque.prmar' :
 | 
        
           |  |  | 112 | 					$this->ajouterFiltreMasque('presence_Martinique', $val);
 | 
        
           |  |  | 113 | 					break;
 | 
        
           |  |  | 114 | 				case 'masque.prstm' :
 | 
        
           |  |  | 115 | 					$this->ajouterFiltreMasque('presence_Saint_Martin', $val);
 | 
        
           |  |  | 116 | 					break;
 | 
        
           |  |  | 117 | 				case 'masque.prdes' :
 | 
        
           |  |  | 118 | 					$this->ajouterFiltreMasque('presence_La_Desirade', $val);
 | 
        
           |  |  | 119 | 					break;
 | 
        
           |  |  | 120 |   | 
        
           |  |  | 121 | 				case 'masque.prstb' :
 | 
        
           |  |  | 122 | 					$this->ajouterFiltreMasque('presence_Saint_Barthelemy', $val);
 | 
        
           |  |  | 123 | 					break;
 | 
        
           |  |  | 124 |   | 
        
           |  |  | 125 | 				case 'masque.prmga' :
 | 
        
           |  |  | 126 | 					$this->ajouterFiltreMasque('presence_Marie_Galante', $val);
 | 
        
           |  |  | 127 | 					break;
 | 
        
           |  |  | 128 |   | 
        
           |  |  | 129 | 				case 'masque.prsai' :
 | 
        
           | 767 | raphael | 130 | 					$this->ajouterFiltreMasque('presence_Les-Saintes', $val);
 | 
        
           | 713 | aurelien | 131 | 					break;
 | 
        
           | 631 | delphine | 132 | 			}
 | 
        
           |  |  | 133 | 		}
 | 
        
           |  |  | 134 | 	}
 | 
        
           | 657 | jpm | 135 |   | 
        
           | 631 | delphine | 136 | 	public function verifierParamChamps($param, $val) {
 | 
        
           |  |  | 137 | 		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
 | 
        
           |  |  | 138 | 		$champs_demandes = explode(',', $val);
 | 
        
           |  |  | 139 | 		$champs_verifies = array();
 | 
        
           | 657 | jpm | 140 | 		$champs_api = array_flip($this->champs_api);
 | 
        
           | 631 | delphine | 141 | 		$champs_supp = array('nom_retenu_complet'=>'num_nom_retenu', 'basionyme_complet'=>'basionyme');
 | 
        
           |  |  | 142 | 		$champs_api = array_merge($champs_api, $champs_supp);
 | 
        
           |  |  | 143 | 		foreach ($champs_demandes as $champ) {
 | 
        
           |  |  | 144 | 			if (array_key_exists($champ, $champs_api)) {
 | 
        
           |  |  | 145 | 				$champs_verifies[] = $champs_api[$champ];
 | 
        
           |  |  | 146 | 			}
 | 
        
           |  |  | 147 | 		}
 | 
        
           |  |  | 148 | 		if (count($champs_verifies) > 0) {
 | 
        
           |  |  | 149 | 			$this->requete_champ .= ', '.implode(',', $champs_verifies);
 | 
        
           |  |  | 150 | 		}
 | 
        
           | 657 | jpm | 151 | 	}
 | 
        
           |  |  | 152 |   | 
        
           | 631 | delphine | 153 | 	/** Permet de rajouter à la requete sql le parametre distinct. N'est utilisé qu'avec le format oss */
 | 
        
           |  |  | 154 | 	public function ajouterNomDistinct($distinct) {
 | 
        
           |  |  | 155 | 		if (isset($distinct)) {
 | 
        
           |  |  | 156 | 			if ($distinct == 1 && $this->parametres['retour.format'] == 'oss') {
 | 
        
           |  |  | 157 | 				$this->distinct = ' distinct ';
 | 
        
           |  |  | 158 | 			} elseif ($distinct == 1 && $this->parametres['retour.format'] != 'oss') {
 | 
        
           | 657 | jpm | 159 | 				$e = 'Erreur dans votre requête </br> L\'utilisation du paramètre distinct ne se fait que sous
 | 
        
           | 631 | delphine | 160 | 					le format oss';
 | 
        
           |  |  | 161 | 				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
 | 
        
           |  |  | 162 | 			}
 | 
        
           |  |  | 163 | 		}
 | 
        
           |  |  | 164 | 	}
 | 
        
           | 657 | jpm | 165 |   | 
        
           | 631 | delphine | 166 | //-----------------FONCTION D'ANALYSE DES RESSOURCES--------------------------------------------------------------------
 | 
        
           |  |  | 167 |   | 
        
           |  |  | 168 | 	public function traiterRessourcesIdentifiant() {
 | 
        
           |  |  | 169 | 		//on initialise la condition de la requete sql et le format de réponse
 | 
        
           |  |  | 170 | 		$this->requete_condition = array(); //on vide la table dans le cas de plusieurs version
 | 
        
           |  |  | 171 | 		$this->requete_condition[] = 'num_nom = '.$this->getBdd()->proteger($this->ressources[0]);
 | 
        
           |  |  | 172 | 		$this->format_reponse = $this->service.'/id';
 | 
        
           | 657 | jpm | 173 | 		if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
 | 
        
           |  |  | 174 | 			if ($this->ressources[1] == 'relations') {
 | 
        
           | 631 | delphine | 175 | 				$this->traiterRessourceIdRelations();
 | 
        
           |  |  | 176 | 			} else {
 | 
        
           |  |  | 177 | 				$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
 | 
        
           |  |  | 178 | 					 <li> noms/#id/relations </li> <li> noms/#id/#champ+#champ </li>
 | 
        
           |  |  | 179 | 					 <li> noms/#id/relations/synonymie </li> <li> noms/#id/relations/flores </li>
 | 
        
           |  |  | 180 | 					 <li> noms/#id/relations/homonymie </li>';
 | 
        
           |  |  | 181 | 				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
 | 
        
           |  |  | 182 | 			}
 | 
        
           |  |  | 183 | 		} else { // requete de type noms/#id : rajout du nom_sci pour récupérer le format html par la fct mettreAuFormat()
 | 
        
           |  |  | 184 | 			$this->requete_champ = ' *, nom_sci ';
 | 
        
           |  |  | 185 | 		}
 | 
        
           |  |  | 186 | 	}
 | 
        
           | 657 | jpm | 187 |   | 
        
           | 631 | delphine | 188 | 	public function traiterRessourceRelations() {
 | 
        
           |  |  | 189 | 		$this->format_reponse .= '/relations';
 | 
        
           |  |  | 190 | 		$projet = $this->ressources[1];
 | 
        
           |  |  | 191 | 		$num_nom = $this->ressources[2];
 | 
        
           |  |  | 192 | 		if (strrpos($num_nom, 'nn.coste') !== false) {
 | 
        
           |  |  | 193 | 			list($p, $nn) = explode('=', $num_nom);
 | 
        
           |  |  | 194 | 			$num_nom = $nn;
 | 
        
           | 657 | jpm | 195 | 		}
 | 
        
           | 631 | delphine | 196 | 		$champ = "flore_$projet"."_num";
 | 
        
           |  |  | 197 | 		if (isset($this->ressources[3])) {
 | 
        
           |  |  | 198 | 			$type = $this->ressources[3];
 | 
        
           |  |  | 199 | 			if (!in_array($type, array('homonymie', 'synonymie', 'flores'))) {
 | 
        
           |  |  | 200 | 				$e = "Les types disponibles pour les noms sont homonymie, synonymie et flores";
 | 
        
           |  |  | 201 | 				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
 | 
        
           |  |  | 202 | 			}
 | 
        
           | 657 | jpm | 203 | 		}
 | 
        
           | 631 | delphine | 204 | 		$this->requete_champ = ' num_nom ';
 | 
        
           |  |  | 205 | 		$this->requete_condition = array();
 | 
        
           |  |  | 206 | 		$this->requete_condition[] = "$champ = ".$this->getBdd()->proteger($num_nom);
 | 
        
           |  |  | 207 | 	}
 | 
        
           | 657 | jpm | 208 |   | 
        
           | 631 | delphine | 209 | 	public function traiterRessourceIdRelations() {
 | 
        
           |  |  | 210 | 		$this->format_reponse .= '/relations';
 | 
        
           |  |  | 211 | 		if (isset($this->ressources[2]) && !empty($this->ressources[2])) {
 | 
        
           |  |  | 212 | 			// requete de type noms/#id/relations/#relation
 | 
        
           |  |  | 213 | 			switch ($this->ressources[2]) {
 | 
        
           | 657 | jpm | 214 | 				case 'synonymie' :
 | 
        
           | 631 | delphine | 215 | 					$this->traiterRessourceIdSynonymie();
 | 
        
           |  |  | 216 | 					break;
 | 
        
           |  |  | 217 | 				case 'flores' :
 | 
        
           |  |  | 218 | 					$this->traiterRessourceIdFlores();
 | 
        
           | 657 | jpm | 219 | 					break;
 | 
        
           | 631 | delphine | 220 | 				case 'homonymie' :
 | 
        
           |  |  | 221 | 					$this->traiterRessourceIdHomonymie();
 | 
        
           |  |  | 222 | 					break;
 | 
        
           | 657 | jpm | 223 | 				default :
 | 
        
           | 631 | delphine | 224 | 					$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
 | 
        
           | 657 | jpm | 225 | 					 <li> noms/#id/relations </li>  <li> noms/#id/relations/synonymie </li>
 | 
        
           | 631 | delphine | 226 | 					 <li> noms/#id/relations/flores </li> <li> noms/#id/relations/homonymie </li>';
 | 
        
           | 657 | jpm | 227 | 					$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
 | 
        
           | 631 | delphine | 228 | 					break;
 | 
        
           |  |  | 229 | 			}
 | 
        
           | 657 | jpm | 230 | 		}
 | 
        
           | 631 | delphine | 231 | 	}
 | 
        
           | 657 | jpm | 232 |   | 
        
           | 631 | delphine | 233 | 	public function traiterRessourceIdSynonymie() {
 | 
        
           |  |  | 234 | 		// SELECT num_nom, nom_sci, num_nom_retenu, basionyme FROM bdtfx_v2_00 WHERE num_nom = X LIMIT 0,100;
 | 
        
           |  |  | 235 | 		$this->format_reponse .= '/synonymie';
 | 
        
           |  |  | 236 | 		if (strrpos($this->requete_champ, ', basionyme') === false) {
 | 
        
           |  |  | 237 | 			$this->requete_champ .= ', basionyme ';
 | 
        
           |  |  | 238 | 		}
 | 
        
           | 1040 | aurelien | 239 | 		if (strrpos($this->requete_champ, ', num_type') === false) {
 | 
        
           |  |  | 240 | 			$this->requete_champ .= ', num_type ';
 | 
        
           |  |  | 241 | 		}
 | 
        
           | 631 | delphine | 242 | 		$this->requete_condition[0] = 'num_nom_retenu = '.
 | 
        
           |  |  | 243 | 			'(SELECT num_nom_retenu FROM '.$this->table.' WHERE '.$this->requete_condition[0].')';
 | 
        
           |  |  | 244 | 	}
 | 
        
           | 657 | jpm | 245 |   | 
        
           | 631 | delphine | 246 | 	public function traiterRessourceIdHomonymie() {
 | 
        
           |  |  | 247 | 		// SELECT num_nom, nom_sci, num_nom_retenu FROM bdtfx_v2_00 WHERE nom_sci = (SELECT nom_sci FROM bdtfx_v2_00 WHERE num_nom = X);
 | 
        
           |  |  | 248 | 		$this->format_reponse 	 .=  '/homonymie';
 | 
        
           |  |  | 249 | 		$this->requete_condition[0] =  'nom_sci = (SELECT nom_sci FROM '.$this->table
 | 
        
           |  |  | 250 | 									.' WHERE '.$this->requete_condition[0].')';
 | 
        
           |  |  | 251 | 	}
 | 
        
           | 657 | jpm | 252 |   | 
        
           | 631 | delphine | 253 | 	public function traiterRessourceIdFlores() {
 | 
        
           |  |  | 254 | 		$champ_flores = '';
 | 
        
           |  |  | 255 | 		foreach ($this->champs_table as $champ) {
 | 
        
           |  |  | 256 | 			if (preg_match('/^flore_.*$/', $champ)) {
 | 
        
           |  |  | 257 | 				$champ_flores .= ', '.$champ;
 | 
        
           |  |  | 258 | 			}
 | 
        
           |  |  | 259 | 		}
 | 
        
           |  |  | 260 | 		$this->format_reponse .=  '/flores';
 | 
        
           |  |  | 261 | 		$this->requete_champ   = 'num_nom'.$champ_flores;
 | 
        
           |  |  | 262 | 	}
 | 
        
           | 657 | jpm | 263 |   | 
        
           | 631 | delphine | 264 | 	public function traiterRessourceStatsRangs() {
 | 
        
           |  |  | 265 | 		// SELECT count(*) as nombre, rang FROM bdtfx_v2_00 [WHERE rang = 290] GROUP BY rang ORDER BY rang;
 | 
        
           |  |  | 266 | 		$this->format_reponse   .= '/rangs';
 | 
        
           | 657 | jpm | 267 | 		$this->requete_champ 	 = 'count(*) as nombre, rang ';
 | 
        
           | 631 | delphine | 268 | 		$this->requete_group_by  = ' GROUP BY rang ORDER BY rang ';
 | 
        
           |  |  | 269 | 	}
 | 
        
           | 657 | jpm | 270 |   | 
        
           | 631 | delphine | 271 | 	public function traiterRessourceStatsAnnees() {
 | 
        
           |  |  | 272 | 		// SELECT count(*) as nombre, annee FROM bdtfx_v2_00 GROUP BY annee ORDER BY annee;
 | 
        
           |  |  | 273 | 		$this->format_reponse   .= '/annees';
 | 
        
           |  |  | 274 | 		$this->requete_champ   	 = 'count(*) as nombre, annee ';
 | 
        
           |  |  | 275 | 		$this->requete_condition = null;
 | 
        
           | 657 | jpm | 276 | 		$this->requete_group_by  = ' GROUP BY annee ORDER BY annee ';
 | 
        
           | 631 | delphine | 277 | 	}
 | 
        
           | 657 | jpm | 278 |   | 
        
           | 631 | delphine | 279 | 	public function traiterRessourceStatsInitiales() {
 | 
        
           |  |  | 280 | 		// SELECT count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre GROUP BY rang, left(nom_sci, 2);
 | 
        
           |  |  | 281 | 		$this->format_reponse .= '/initiales';
 | 
        
           | 657 | jpm | 282 | 		$this->requete_champ   = 'count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre ';
 | 
        
           | 631 | delphine | 283 | 		$this->requete_group_by  = ' GROUP BY rang, left(nom_sci, 2)';
 | 
        
           |  |  | 284 | 	}
 | 
        
           | 657 | jpm | 285 |   | 
        
           | 631 | delphine | 286 | //-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
 | 
        
           | 657 | jpm | 287 |   | 
        
           | 631 | delphine | 288 | 	public function assemblerLaRequete() {
 | 
        
           |  |  | 289 | 		if ( strrpos($this->format_reponse, 'noms/stats/') === false ) {
 | 
        
           |  |  | 290 | 			$this->mettreAuFormat(); //Ds CommunNomsTaxons.php
 | 
        
           |  |  | 291 | 		}
 | 
        
           | 667 | jpm | 292 | 		$requete = 'SELECT '.$this->retournerChamps().' '.
 | 
        
           |  |  | 293 | 			"FROM {$this->table} ".
 | 
        
           |  |  | 294 | 			$this->retournerRequeteCondition().' '.
 | 
        
           |  |  | 295 | 			$this->requete_group_by.' '.
 | 
        
           |  |  | 296 | 			$this->retournerOrderBy().' '.
 | 
        
           |  |  | 297 | 			$this->formerRequeteLimite();
 | 
        
           |  |  | 298 | 		return $requete;
 | 
        
           |  |  | 299 | 	}
 | 
        
           | 657 | jpm | 300 |   | 
        
           | 667 | jpm | 301 | 	public function retournerChamps() {
 | 
        
           |  |  | 302 | 		$sql = '';
 | 
        
           |  |  | 303 | 		if ($this->distinct) {
 | 
        
           |  |  | 304 | 			$sql .= $this->distinct.' ';
 | 
        
           |  |  | 305 | 		}
 | 
        
           |  |  | 306 | 		if ($this->requete_champ) {
 | 
        
           |  |  | 307 | 			$sql .= $this->requete_champ.' ';
 | 
        
           |  |  | 308 | 		}
 | 
        
           |  |  | 309 |   | 
        
           |  |  | 310 | 		// Champs "virtuels" pour tier sur l'ensemble des résultats
 | 
        
           |  |  | 311 | 		if (isset($this->parametres['retour.tri'])) {
 | 
        
           |  |  | 312 | 			list($champ, $ordre) = $this->decouperParametreRetourTri();
 | 
        
           |  |  | 313 | 			if ($champ == 'retenu') {
 | 
        
           |  |  | 314 | 				$sql .= ", IF(num_nom = num_nom_retenu, '0', '1') AS nom_retenu_tri ";
 | 
        
           |  |  | 315 | 			}
 | 
        
           |  |  | 316 | 		}
 | 
        
           |  |  | 317 |   | 
        
           |  |  | 318 | 		return $sql;
 | 
        
           | 631 | delphine | 319 | 	}
 | 
        
           |  |  | 320 |   | 
        
           | 667 | jpm | 321 | 	public function decouperParametreRetourTri() {
 | 
        
           |  |  | 322 | 		$tri = array('', '');
 | 
        
           |  |  | 323 | 		if (isset($this->parametres['retour.tri'])) {
 | 
        
           |  |  | 324 | 			if (preg_match('/^(retenu)(?:,(ASC|DESC)|)$/', $this->parametres['retour.tri'], $match))
 | 
        
           |  |  | 325 | 				$tri[0] = $match[1];
 | 
        
           |  |  | 326 | 			$tri[1] = isset($match[2]) ? $match[2] : '';
 | 
        
           |  |  | 327 | 		}
 | 
        
           |  |  | 328 | 		return $tri;
 | 
        
           |  |  | 329 | 	}
 | 
        
           |  |  | 330 |   | 
        
           |  |  | 331 | 	public function retournerRequeteCondition() {
 | 
        
           |  |  | 332 | 		$condition = '';
 | 
        
           |  |  | 333 | 		if ($this->requete_condition) {
 | 
        
           |  |  | 334 | 			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
 | 
        
           |  |  | 335 | 		}
 | 
        
           |  |  | 336 | 		return $condition;
 | 
        
           |  |  | 337 | 	}
 | 
        
           |  |  | 338 |   | 
        
           |  |  | 339 | 	public function retournerOrderBy() {
 | 
        
           |  |  | 340 | 		$orderBy = array();
 | 
        
           |  |  | 341 |   | 
        
           |  |  | 342 | 		// Tri sur l'ensemble des résultats
 | 
        
           |  |  | 343 | 		if (isset($this->parametres['retour.tri'])) {
 | 
        
           |  |  | 344 | 			list($champ, $ordre) = $this->decouperParametreRetourTri();
 | 
        
           |  |  | 345 | 			if ($champ == 'retenu') {
 | 
        
           |  |  | 346 | 				$orderBy[] = "nom_retenu_tri $ordre";
 | 
        
           |  |  | 347 | 			}
 | 
        
           |  |  | 348 | 		}
 | 
        
           |  |  | 349 | 		// Tri par défaut
 | 
        
           |  |  | 350 | 		if ($this->format_reponse == 'noms') {
 | 
        
           |  |  | 351 | 			$orderBy[] = 'nom_sci ASC';
 | 
        
           |  |  | 352 | 		}
 | 
        
           |  |  | 353 |   | 
        
           |  |  | 354 | 		$sql = '';
 | 
        
           | 673 | delphine | 355 | 		if (count($orderBy) > 0) {
 | 
        
           | 667 | jpm | 356 | 			$sql = 'ORDER BY '.implode(', ', $orderBy).' ';
 | 
        
           |  |  | 357 | 		}
 | 
        
           |  |  | 358 | 		return $sql;
 | 
        
           |  |  | 359 | 	}
 | 
        
           |  |  | 360 |   | 
        
           | 631 | delphine | 361 | 	public function formerRequeteLimite() {
 | 
        
           | 657 | jpm | 362 | 		if ($this->format_reponse != 'noms' && $this->format_reponse != 'noms/id/relations/synonymie'
 | 
        
           | 631 | delphine | 363 | 			&& $this->format_reponse != 'noms/id/relations/homonymie') {
 | 
        
           | 657 | jpm | 364 | 			$this->requete_limite = '';
 | 
        
           | 631 | delphine | 365 | 		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
 | 
        
           | 657 | jpm | 366 | 			$this->limite_requete['depart'] =
 | 
        
           | 631 | delphine | 367 | 				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
 | 
        
           | 657 | jpm | 368 | 			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
 | 
        
           | 631 | delphine | 369 | 		} else {
 | 
        
           | 657 | jpm | 370 | 			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
 | 
        
           | 631 | delphine | 371 | 		}
 | 
        
           |  |  | 372 | 		return $this->requete_limite;
 | 
        
           |  |  | 373 | 	}
 | 
        
           | 657 | jpm | 374 |   | 
        
           | 631 | delphine | 375 | 	/** Recupere le nombre total de résultat d'une requete lancée. */
 | 
        
           |  |  | 376 | 	public function recupererTotalResultat() {
 | 
        
           |  |  | 377 | 		$total = null;
 | 
        
           |  |  | 378 | 		$requete = 'SELECT count(*) as nombre FROM '.$this->table.$this->retournerRequeteCondition().$this->requete_group_by;
 | 
        
           |  |  | 379 | 		$res = $this->getBdd()->recuperer($requete);
 | 
        
           |  |  | 380 | 		if ($res) {
 | 
        
           |  |  | 381 | 			$total = $res['nombre'];
 | 
        
           |  |  | 382 | 		} else {
 | 
        
           |  |  | 383 | 			$e = 'Fct recupererTotalResultat() : <br/>Données introuvables dans la base';
 | 
        
           |  |  | 384 | 			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
 | 
        
           |  |  | 385 | 		}
 | 
        
           |  |  | 386 | 		return $total;
 | 
        
           |  |  | 387 | 	}
 | 
        
           | 657 | jpm | 388 |   | 
        
           |  |  | 389 |   | 
        
           | 631 | delphine | 390 | //-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
 | 
        
           | 657 | jpm | 391 |   | 
        
           | 631 | delphine | 392 | 	public function retournerResultatFormate($resultat) {
 | 
        
           |  |  | 393 | 		switch ($this->format_reponse) {
 | 
        
           |  |  | 394 | 			case 'noms/relations' :
 | 
        
           |  |  | 395 | 				$reponse = $this->formaterRelations($resultat[0]);
 | 
        
           |  |  | 396 | 				break;
 | 
        
           |  |  | 397 | 			case 'noms/id' : //ds CommunNomsTaxons
 | 
        
           |  |  | 398 | 				$reponse = $this->formaterId($resultat[0]);
 | 
        
           |  |  | 399 | 				break;
 | 
        
           |  |  | 400 | 			case 'noms/id/relations' :
 | 
        
           |  |  | 401 | 				$reponse = $this->formaterIdRelations($resultat[0]);
 | 
        
           | 657 | jpm | 402 | 				break;
 | 
        
           | 631 | delphine | 403 | 			case 'noms/id/relations/synonymie' :
 | 
        
           |  |  | 404 | 				$reponse = $this->formaterIdSynonymie($resultat);
 | 
        
           |  |  | 405 | 				break;
 | 
        
           |  |  | 406 | 			case 'noms/id/relations/homonymie' :
 | 
        
           |  |  | 407 | 				$reponse = $this->formaterIdHomonymie($resultat);
 | 
        
           |  |  | 408 | 				break;
 | 
        
           |  |  | 409 | 			case 'noms/id/relations/flores' : //ds CommunsNomsTaxons
 | 
        
           |  |  | 410 | 				$reponse = $this->formaterIdFlores($resultat[0]);
 | 
        
           |  |  | 411 | 				break;
 | 
        
           |  |  | 412 | 			case 'noms/stats/annees' : //ds CommunNomsTaxons
 | 
        
           |  |  | 413 | 				$reponse = $this->formaterStatsAnnee($resultat);
 | 
        
           |  |  | 414 | 				break;
 | 
        
           |  |  | 415 | 			case 'noms/stats/rangs' : //ds CommunNomsTaxons
 | 
        
           |  |  | 416 | 				$reponse = $this->formaterStatsRang($resultat);
 | 
        
           |  |  | 417 | 				break;
 | 
        
           |  |  | 418 | 			case 'noms/stats/initiales' : //ds CommunNomsTaxons
 | 
        
           |  |  | 419 | 				$reponse = $this->formaterStatsInitiales($resultat);
 | 
        
           |  |  | 420 | 				break;
 | 
        
           |  |  | 421 | 			case 'noms' :
 | 
        
           |  |  | 422 | 				$reponse = $this->formaterNoms($resultat);
 | 
        
           |  |  | 423 | 				break;
 | 
        
           |  |  | 424 | 		}
 | 
        
           |  |  | 425 | 		return $reponse;
 | 
        
           |  |  | 426 | 	}
 | 
        
           | 657 | jpm | 427 |   | 
        
           | 631 | delphine | 428 | //+---------------------concerne les resultats pour des requetes de type noms/id-----------------------------+
 | 
        
           | 657 | jpm | 429 |   | 
        
           | 631 | delphine | 430 | 	public function formaterRelations($resultat) {
 | 
        
           |  |  | 431 | 		$num_nom = $resultat['num_nom'];
 | 
        
           |  |  | 432 | 		if (isset($this->ressources[3])) {
 | 
        
           |  |  | 433 | 			$url = Config::get('url_service').$this->service."/$num_nom/relations";
 | 
        
           |  |  | 434 | 		} else {
 | 
        
           |  |  | 435 | 			$type = $this->ressources[3];
 | 
        
           |  |  | 436 | 			$url = Config::get('url_service')."/$this->service/$num_nom/relations/$type";
 | 
        
           |  |  | 437 | 		}
 | 
        
           |  |  | 438 | 		$res = $this->consulterHref($url);
 | 
        
           |  |  | 439 | 		return $res;
 | 
        
           | 657 | jpm | 440 | 	}
 | 
        
           |  |  | 441 |   | 
        
           | 631 | delphine | 442 | 	public function formaterIdRelations($resultat) {
 | 
        
           |  |  | 443 | 		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
 | 
        
           | 657 | jpm | 444 | 		$this->resultat_req = $resultat;
 | 
        
           | 631 | delphine | 445 | 		$retour_id_rel = array ('entete' => array()); //on initialise pr que l'entete apparaisse en premier lors de l'affichage
 | 
        
           | 657 | jpm | 446 |   | 
        
           | 631 | delphine | 447 | 		//on recupère le resultat de chaque relation (appel du WS correspondant)
 | 
        
           |  |  | 448 | 		$flores = $this->ajouterRelations('flores');
 | 
        
           |  |  | 449 | 		if (isset($flores)) $retour_id_rel['resultat']['flores'] = $flores;
 | 
        
           |  |  | 450 | 		$homonymes = $this->ajouterRelations('homonymie');
 | 
        
           |  |  | 451 | 		if (isset($homonymes)) $retour_id_rel['resultat']['homonymes'] = $homonymes;
 | 
        
           |  |  | 452 | 		$synonymes = $this->ajouterRelations('synonymie');
 | 
        
           |  |  | 453 | 		if (isset($synonymes)) $retour_id_rel['resultat']['synonymes'] = $synonymes;
 | 
        
           | 657 | jpm | 454 |   | 
        
           | 631 | delphine | 455 | 		//on renvoit null si il n'existe aucune relations (on efface l'entete en premier lieu)
 | 
        
           |  |  | 456 | 		if (!isset($retour_id_rel['resultat']))	{
 | 
        
           | 657 | jpm | 457 | 			$retour_id_rel = null;
 | 
        
           | 631 | delphine | 458 | 		} else { //on rajoute l'entete si des relations existent
 | 
        
           | 657 | jpm | 459 | 			$this->afficherDonnees('num_nom', $this->ressources[0]);
 | 
        
           | 631 | delphine | 460 | 			$retour_id_rel['entete'] = $this->table_retour;
 | 
        
           |  |  | 461 | 			$this->table_retour = array();
 | 
        
           |  |  | 462 | 		}
 | 
        
           |  |  | 463 | 		return $retour_id_rel;
 | 
        
           |  |  | 464 | 	}
 | 
        
           | 657 | jpm | 465 |   | 
        
           | 631 | delphine | 466 | 	/**
 | 
        
           | 657 | jpm | 467 | 	 * Recupere les relations (type de la relation passée en paramètres :[type_relation] = synonymie, homonymie ou
 | 
        
           | 631 | delphine | 468 | 	 * flores) par l'appel du web service [version]/noms/#id/relations/[type_relation]
 | 
        
           |  |  | 469 | 	 */
 | 
        
           |  |  | 470 | 	public function ajouterRelations($relation) {
 | 
        
           |  |  | 471 | 		$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
 | 
        
           |  |  | 472 | 		$res = null;
 | 
        
           |  |  | 473 | 		$parametres_url = '';
 | 
        
           |  |  | 474 | 		if ($this->parametres != array()) $parametres_url = '?'.http_build_query($this->parametres, '', '&');
 | 
        
           | 667 | jpm | 475 | 		$url = Config::get('url_service').'/'.$this->service.'/'.
 | 
        
           |  |  | 476 | 			$this->ressources[0].'/relations/'.
 | 
        
           |  |  | 477 | 			$relation.$parametres_url;
 | 
        
           | 657 | jpm | 478 |   | 
        
           | 631 | delphine | 479 | 		$relation = $this->consulterHref($url);
 | 
        
           | 657 | jpm | 480 |   | 
        
           | 631 | delphine | 481 | 		$res = $relation->resultat;
 | 
        
           |  |  | 482 | 		return $res;
 | 
        
           |  |  | 483 | 	}
 | 
        
           | 657 | jpm | 484 |   | 
        
           |  |  | 485 |   | 
        
           | 631 | delphine | 486 | 	public function formaterIdSynonymie($resultat) {
 | 
        
           |  |  | 487 | 		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
 | 
        
           |  |  | 488 | 		$retour_id_syn = array();
 | 
        
           |  |  | 489 | 		if ($resultat[0]['num_nom_retenu'] == '') {
 | 
        
           |  |  | 490 | 			$retour_id_syn[] = 'nom_retenu N.D.';
 | 
        
           | 657 | jpm | 491 | 		} elseif (count($resultat) != 1) {
 | 
        
           |  |  | 492 | 			//on remplit d'abord l'entete du resultat
 | 
        
           | 631 | delphine | 493 | 			$this->table_retour['id'] = $this->ressources[0];
 | 
        
           |  |  | 494 | 			$this->afficherEnteteResultat('/'.$this->service.'/'.$this->ressources[0].'/relations/synonymie');
 | 
        
           |  |  | 495 | 			$retour_id_syn['entete'] = $this->table_retour;
 | 
        
           |  |  | 496 | 			$this->table_retour = array();
 | 
        
           |  |  | 497 | 			foreach ($resultat as $tab) {
 | 
        
           |  |  | 498 | 				//pour chaque basionyme, on recupère le résultat : num_nom, nom_sci, basionyme et num_nom_retenu :
 | 
        
           | 657 | jpm | 499 | 				$this->resultat_req = $tab;
 | 
        
           | 631 | delphine | 500 | 				$num = $tab['num_nom'];
 | 
        
           |  |  | 501 | 				$this->afficherNomHrefRetenu($tab, $num);
 | 
        
           | 657 | jpm | 502 | 				$this->afficherDonnees('basionyme', $tab['basionyme']);
 | 
        
           | 631 | delphine | 503 | 				$retour_id_syn['resultat'][$num] = $this->table_retour;
 | 
        
           |  |  | 504 | 				$this->table_retour = array();
 | 
        
           |  |  | 505 | 			}
 | 
        
           |  |  | 506 | 			if (!isset($retour_id_syn['resultat']) && !in_array('nom_retenu N.D.', $retour_id_syn)) {
 | 
        
           |  |  | 507 | 				$retour_id_syn = null; //on initialise le resultat à null
 | 
        
           | 657 | jpm | 508 | 			}
 | 
        
           | 631 | delphine | 509 | 		}
 | 
        
           |  |  | 510 | 		return $retour_id_syn;
 | 
        
           |  |  | 511 | 	}
 | 
        
           | 657 | jpm | 512 |   | 
        
           | 631 | delphine | 513 | 	public function formaterIdHomonymie($resultat) {
 | 
        
           |  |  | 514 | 		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
 | 
        
           |  |  | 515 | 		if (count($resultat) != 1) {
 | 
        
           |  |  | 516 | 			$this->table_retour['id'] = $this->ressources[0];
 | 
        
           |  |  | 517 | 			$this->afficherEnteteResultat($resultat, '/'.$this->service.'/'.$this->ressources[0].'/relations/homonymie');
 | 
        
           |  |  | 518 | 			$retour_id_hom['entete'] = $this->table_retour;
 | 
        
           |  |  | 519 | 			$this->table_retour = array();
 | 
        
           |  |  | 520 | 			foreach ($resultat as $homonyme) {
 | 
        
           |  |  | 521 | 				$this->resultat_req = $homonyme;
 | 
        
           |  |  | 522 | 				$id = $homonyme['num_nom'];
 | 
        
           |  |  | 523 | 				$this->afficherDonnees('num_nom', $id);
 | 
        
           |  |  | 524 | 				if ($homonyme['num_nom_retenu'] != '') {
 | 
        
           |  |  | 525 | 					$retenu = ($id == $homonyme['num_nom_retenu']) ? 'true' : 'false';
 | 
        
           |  |  | 526 | 				} else {
 | 
        
           |  |  | 527 | 					$retenu = 'absent';
 | 
        
           |  |  | 528 | 				}
 | 
        
           | 657 | jpm | 529 | 				$this->table_retour['retenu'] = $retenu;
 | 
        
           | 631 | delphine | 530 | 				$retour_id_hom['resultat'][$id] = $this->table_retour;
 | 
        
           |  |  | 531 | 				unset($retour_id_hom['resultat'][$id]['id']);
 | 
        
           |  |  | 532 | 				$this->table_retour = array();
 | 
        
           |  |  | 533 | 			}
 | 
        
           |  |  | 534 | 		} else {
 | 
        
           | 657 | jpm | 535 | 			$retour_id_hom = null;
 | 
        
           | 631 | delphine | 536 | 		}
 | 
        
           |  |  | 537 | 		return $retour_id_hom;
 | 
        
           |  |  | 538 | 	}
 | 
        
           | 657 | jpm | 539 |   | 
        
           | 631 | delphine | 540 | 	public function obtenirSynonymesParNumNomAvecInfosFlore($num_nom, $version='1_02') {
 | 
        
           | 657 | jpm | 541 |   | 
        
           |  |  | 542 | 		$champs_flore = 'flore_bonnier_num, flore_bonnier_rem,'.
 | 
        
           | 631 | delphine | 543 | 						'flore_cnrs_num, flore_cnrs_rem '.
 | 
        
           |  |  | 544 | 						'flore_fe_num, flore_fe_rem '.
 | 
        
           | 657 | jpm | 545 | 						'flore_coste_num, flore_coste_rem '.
 | 
        
           |  |  | 546 | 						'flore_fh_num, flore_fh_rem '.
 | 
        
           | 631 | delphine | 547 | 						'flore_fournier_num, flore_fournier_rem';
 | 
        
           | 657 | jpm | 548 |   | 
        
           | 631 | delphine | 549 | 		$requete = 'SELECT num_nom, nom_sci, '.$champs_flore.' '.
 | 
        
           |  |  | 550 | 						'FROM '.$this->table.' '.
 | 
        
           |  |  | 551 | 						'WHERE num_nom_retenu = '.
 | 
        
           |  |  | 552 | 						'('.
 | 
        
           |  |  | 553 | 						'SELECT num_nom_retenu FROM '.$this->table.' WHERE num_nom = "'.$num_nom.'"'.
 | 
        
           |  |  | 554 | 						')';
 | 
        
           | 657 | jpm | 555 |   | 
        
           |  |  | 556 | 		return $this->getBdd()->recupererTous($requete);
 | 
        
           | 631 | delphine | 557 | 	}
 | 
        
           | 657 | jpm | 558 |   | 
        
           | 631 | delphine | 559 | 	public function formaterIdFlores($resultat) {
 | 
        
           |  |  | 560 | 		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp,noms_projets');
 | 
        
           | 657 | jpm | 561 | 		$this->resultat_req = $resultat;
 | 
        
           | 631 | delphine | 562 | 		$id = array_shift($resultat);
 | 
        
           |  |  | 563 | 		$reponse['entete']['id'] = $id;
 | 
        
           |  |  | 564 | 		$synonymes_flores = $this->obtenirSynonymesParNumNomAvecInfosFlore($this->ressources[0]);
 | 
        
           |  |  | 565 | 		if(is_array($synonymes_flores)) {
 | 
        
           |  |  | 566 | 			foreach ($synonymes_flores as $synonyme) {
 | 
        
           |  |  | 567 | 				$nom_sci = $synonyme['nom_sci'];
 | 
        
           |  |  | 568 | 				$num_nom = $synonyme['num_nom'];
 | 
        
           |  |  | 569 | 				unset($synonyme['nom_sci']);
 | 
        
           |  |  | 570 | 				unset($synonyme['num_nom']);
 | 
        
           |  |  | 571 | 				foreach ($synonyme as $flores => $valeur) {
 | 
        
           |  |  | 572 | 					if ($valeur != '' && $valeur != '0') {
 | 
        
           |  |  | 573 | 						$this->afficherInfosFlore($synonyme, $flores, $valeur, $nom_sci, $num_nom);
 | 
        
           |  |  | 574 | 					}
 | 
        
           |  |  | 575 | 				}
 | 
        
           |  |  | 576 | 			}
 | 
        
           |  |  | 577 | 		}
 | 
        
           |  |  | 578 |   | 
        
           |  |  | 579 | 		if ($this->table_retour != array()) {
 | 
        
           |  |  | 580 | 			$reponse['resultat'] = $this->table_retour;
 | 
        
           |  |  | 581 | 			$this->table_retour = array();
 | 
        
           | 657 | jpm | 582 | 		} else {
 | 
        
           |  |  | 583 | 			$reponse = null;
 | 
        
           | 631 | delphine | 584 | 		}
 | 
        
           |  |  | 585 | 		return $reponse;
 | 
        
           |  |  | 586 | 	}
 | 
        
           | 657 | jpm | 587 |   | 
        
           | 631 | delphine | 588 | 	public function getNomCompletFlore($flore) {
 | 
        
           |  |  | 589 | 		return Config::get($flore.'_texte');
 | 
        
           |  |  | 590 | 	}
 | 
        
           | 657 | jpm | 591 |   | 
        
           | 631 | delphine | 592 | 	public function afficherInfosFlore(&$resultat, $flores, $valeur, $nom_sci, $num_nom) {
 | 
        
           | 657 | jpm | 593 | 		$flore = substr($flores,0,strrpos($flores, '_'));
 | 
        
           | 631 | delphine | 594 | 		$projet = $this->noms_projets[$flore];
 | 
        
           | 657 | jpm | 595 |   | 
        
           | 631 | delphine | 596 | 		//TODO voir si l'on peut factoriser les affectations à la table retour
 | 
        
           |  |  | 597 | 		// et simplifier ce gros pavé
 | 
        
           | 657 | jpm | 598 | 		if (strrpos($flores, 'num') !== false) {
 | 
        
           |  |  | 599 | 			if (preg_match('/^([0-9]+)(?:[.]syn[^a-z]*|(.*))?$/', $valeur, $match)) {
 | 
        
           | 631 | delphine | 600 | 				$this->table_retour[$num_nom][$flore]['id'] = $match[1];
 | 
        
           |  |  | 601 | 				if ($projet == 'coste') {
 | 
        
           |  |  | 602 | 					$this->table_retour[$num_nom][$flore]['href'] = $this->ajouterHrefAutreProjet('noms', 'nn_coste:', $match[1], $projet);
 | 
        
           |  |  | 603 | 				}
 | 
        
           |  |  | 604 | 				if (isset($match[2]) && $match[2] != '') $this->table_retour[$num_nom][$flore]['cle'] = $match[2];
 | 
        
           |  |  | 605 | 				$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
 | 
        
           |  |  | 606 | 				$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
 | 
        
           | 657 | jpm | 607 | 			}
 | 
        
           | 631 | delphine | 608 | 			if (isset($resultat[$flore.'_rem']) && !empty($resultat[$flore.'_rem'])) {
 | 
        
           |  |  | 609 | 				$this->table_retour[$num_nom][$flore]['remarque'] = $resultat[$flore.'_rem'];
 | 
        
           |  |  | 610 | 				$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
 | 
        
           |  |  | 611 | 				$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
 | 
        
           |  |  | 612 | 				unset($resultat[$flore.'_rem']);
 | 
        
           |  |  | 613 | 			}
 | 
        
           |  |  | 614 | 		} elseif (strrpos($flores,'belge') !== false) {
 | 
        
           |  |  | 615 | 			if (preg_match('/^([0-9]+) (R|S)?$/', $valeur, $match)) {
 | 
        
           |  |  | 616 | 				if (isset($match[2])) $type = ($match[2] == 'R') ? 'taxons' : 'synonyme';
 | 
        
           |  |  | 617 | 				$this->table_retour[$num_nom][$flore]['page'] = $match[1];
 | 
        
           |  |  | 618 | 				$this->table_retour[$num_nom][$flore]['type'] = $type;
 | 
        
           |  |  | 619 | 				$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
 | 
        
           |  |  | 620 | 				$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
 | 
        
           |  |  | 621 | 			}
 | 
        
           |  |  | 622 | 		}
 | 
        
           | 657 | jpm | 623 | 	}
 | 
        
           |  |  | 624 |   | 
        
           | 631 | delphine | 625 | //+---------------------concerne les resultats pour des requetes de type /noms avec ou sans paramètres-------+
 | 
        
           |  |  | 626 |   | 
        
           |  |  | 627 | 	public function formaterNoms($resultat) {
 | 
        
           |  |  | 628 | 		if ($this->parametres['retour.format'] == 'oss') {
 | 
        
           |  |  | 629 | 			$reponse = $this->formaterEnOss($resultat);	 //Ds CommunNomsTaxons.php
 | 
        
           |  |  | 630 | 		} else {
 | 
        
           |  |  | 631 | 			$reponse = $this->formaterEnJsonMax($resultat);
 | 
        
           |  |  | 632 | 		}
 | 
        
           |  |  | 633 | 		return $reponse;
 | 
        
           |  |  | 634 | 	}
 | 
        
           |  |  | 635 |   | 
        
           |  |  | 636 | 	public function formaterEnJsonMax($resultat) {
 | 
        
           |  |  | 637 | 		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
 | 
        
           | 667 | jpm | 638 |   | 
        
           | 713 | aurelien | 639 | 		// TODO : améliorer le tri des résultats
 | 
        
           | 667 | jpm | 640 | 		// ATTENTION : ce comportement est étrange
 | 
        
           | 631 | delphine | 641 | 		$masque = $this->recupererMasquePrincipal();
 | 
        
           | 671 | jpm | 642 | 		if (isset($masque) && !isset($this->parametres['retour.tri'])) {
 | 
        
           | 713 | aurelien | 643 | 			// fonction du pauvre pour palier aux "." remplacés accidentellement par des "_"
 | 
        
           |  |  | 644 | 			$index = str_replace('masque_','masque.',$masque[0]);
 | 
        
           |  |  | 645 | 			//$resultat = $this->trierRechercheFloue($this->parametres[$index], $resultat, $masque[1]);
 | 
        
           | 631 | delphine | 646 | 		}
 | 
        
           | 667 | jpm | 647 |   | 
        
           | 1067 | mathias | 648 | 		// Tri à la mode du CeL : lexicographique puis noms retenus (retour.tri = "alpharet")
 | 
        
           |  |  | 649 | 		if (isset($this->parametres['retour.tri']) && ($this->parametres['retour.tri'] == "alpharet")) {
 | 
        
           |  |  | 650 | 			usort($resultat, array($this, 'genrePuisNomsRetenusEnTete'));
 | 
        
           |  |  | 651 | 		}
 | 
        
           |  |  | 652 |   | 
        
           | 631 | delphine | 653 | 		$table_retour_json['entete'] = $this->remplirJsonEntete();
 | 
        
           | 657 | jpm | 654 | 		$table_retour_json['resultat'] = $this->remplirJsonResultat($resultat);
 | 
        
           | 631 | delphine | 655 | 		return $table_retour_json;
 | 
        
           |  |  | 656 | 	}
 | 
        
           |  |  | 657 |   | 
        
           | 1067 | mathias | 658 | 	// Trie les éléments du tableau de résultats : le genre en tête, puis les noms retenus, puis le reste
 | 
        
           |  |  | 659 | 	// mais à partir du jeu de données retourné par SQL (indépendents du statut "retenu")
 | 
        
           |  |  | 660 | 	private function genrePuisNomsRetenusEnTete($a, $b) {
 | 
        
           |  |  | 661 | 		// On pourrait utiliser l'indice ['retenu'] mais il contient parfois "absent", qui est dur à traiter
 | 
        
           |  |  | 662 | 		$aEstRetenu = ($a['num_nom'] == $a['num_nom_retenu']);
 | 
        
           |  |  | 663 | 		$bEstRetenu = ($b['num_nom'] == $b['num_nom_retenu']);
 | 
        
           |  |  | 664 | 		$retour = 0;
 | 
        
           |  |  | 665 |   | 
        
           |  |  | 666 | 		// les noms retenus en premier ("inférieurs")
 | 
        
           |  |  | 667 | 		if ($aEstRetenu) {
 | 
        
           |  |  | 668 | 			if (! $bEstRetenu) {
 | 
        
           |  |  | 669 | 				$retour = -1;
 | 
        
           |  |  | 670 | 			}
 | 
        
           |  |  | 671 | 		}  else {
 | 
        
           |  |  | 672 | 			if ($bEstRetenu) {
 | 
        
           |  |  | 673 | 				$retour = 1;
 | 
        
           |  |  | 674 | 			}
 | 
        
           |  |  | 675 | 		}
 | 
        
           |  |  | 676 |   | 
        
           |  |  | 677 | 		// en cas d'égalité on conserve le tri lexicographique - devrait faire sortir le genre en première position
 | 
        
           |  |  | 678 | 		// car il ne contient pas le nom d'auteur
 | 
        
           |  |  | 679 | 		if ($retour == 0) {
 | 
        
           |  |  | 680 | 			$retour = strcasecmp($a['nom_sci'], $b['nom_sci']);
 | 
        
           |  |  | 681 | 		}
 | 
        
           |  |  | 682 |   | 
        
           |  |  | 683 | 		return $retour;
 | 
        
           |  |  | 684 | 	}
 | 
        
           |  |  | 685 |   | 
        
           | 631 | delphine | 686 | 	public function remplirJsonResultat($resultat) {
 | 
        
           |  |  | 687 | 		$champs = null;
 | 
        
           |  |  | 688 | 		if (array_key_exists('retour.champs', $this->parametres)) {
 | 
        
           |  |  | 689 | 			$champs = explode(',', $this->parametres['retour.champs']);
 | 
        
           |  |  | 690 | 		}
 | 
        
           | 667 | jpm | 691 |   | 
        
           | 1115 | mathias | 692 | 		// Structure des données: objet ou liste ?
 | 
        
           |  |  | 693 | 		$modeListe = false;
 | 
        
           |  |  | 694 | 		if (array_key_exists('retour.structure', $this->parametres)) {
 | 
        
           |  |  | 695 | 			$modeListe = ($this->parametres['retour.structure'] === "liste");
 | 
        
           |  |  | 696 | 		}
 | 
        
           |  |  | 697 |   | 
        
           | 657 | jpm | 698 | 		$noms = array();
 | 
        
           | 631 | delphine | 699 | 		foreach ($resultat as $tab) {
 | 
        
           |  |  | 700 | 			$this->table_retour = array();
 | 
        
           |  |  | 701 | 			$num = $tab['num_nom'];
 | 
        
           |  |  | 702 | 			$this->afficherNomHrefRetenu($tab, $num); // ajoute le nom_sci, href et si le nom est retenu dans $this->table_retour
 | 
        
           |  |  | 703 | 			$retour = $this->table_retour;
 | 
        
           |  |  | 704 | 			$this->table_retour = array();
 | 
        
           |  |  | 705 | 			if ($champs != null) {
 | 
        
           |  |  | 706 | 				$reponse_id = $this->formaterId($tab);
 | 
        
           |  |  | 707 | 				$this->table_retour = array();
 | 
        
           |  |  | 708 | 				$this->ajouterChampsPersonnalises($champs, $reponse_id);
 | 
        
           |  |  | 709 | 				$retour = array_merge($retour, $this->table_retour);
 | 
        
           |  |  | 710 | 			}
 | 
        
           | 1115 | mathias | 711 | 			if ($modeListe) {
 | 
        
           |  |  | 712 | 				$retour['num_nom'] = intval($num);
 | 
        
           |  |  | 713 | 				$noms[] = $retour;
 | 
        
           |  |  | 714 | 			} else {
 | 
        
           |  |  | 715 | 				$noms[$num] = $retour;
 | 
        
           |  |  | 716 | 			}
 | 
        
           | 631 | delphine | 717 | 		}
 | 
        
           | 657 | jpm | 718 |   | 
        
           | 667 | jpm | 719 | 		return $noms;
 | 
        
           | 631 | delphine | 720 | 	}
 | 
        
           | 657 | jpm | 721 |   | 
        
           | 631 | delphine | 722 | 	public function remplirJsonEntete() {
 | 
        
           |  |  | 723 | 		$entete = array();
 | 
        
           |  |  | 724 | 		if (isset($this->masque)) {
 | 
        
           |  |  | 725 | 			$this->table_retour['masque'] = implode('&', $this->masque);
 | 
        
           |  |  | 726 | 		}
 | 
        
           | 657 | jpm | 727 | 		parent::afficherEnteteResultat('/'.$this->service);
 | 
        
           | 631 | delphine | 728 | 		return  $this->table_retour;
 | 
        
           |  |  | 729 | 	}
 | 
        
           |  |  | 730 | }
 | 
        
           |  |  | 731 | ?>
 |