Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 867 Rev 891
Line 1... Line 1...
1
<?php
1
<?php
2
/**
2
/**
3
* PHP Version 5
3
* PHP Version 5
4
*  
-
 
5
* Classe de recherche d'informations sur un taxon donné
-
 
6
*
4
*
7
* @category  PHP
5
* @category  PHP
8
* @package   jrest
6
* @package   jrest
9
* @author    david <david@tela-botania.org>
7
* @author    david <david@tela-botania.org>
10
* @copyright 2010 Tela-Botanica
8
* @copyright 2010 Tela-Botanica
11
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
* @version   SVN: <svn_id>
10
* @version   SVN: <svn_id>
13
* @link      /doc/jrest/
11
* @link      /doc/jrest/
14
*/
12
*/
-
 
13
 
-
 
14
/**
-
 
15
 * 
-
 
16
 * Classe de recherche d'informations sur un taxon donné
-
 
17
 * lors de l'évolution d'eflore, devrait être remplacée par 
-
 
18
 * un appel aux nouveaux web services
-
 
19
 */
15
class RechercheInfosTaxon extends Cel {
20
class RechercheInfosTaxon extends Cel {
-
 
21
	
-
 
22
	public function RechercheInfosTaxon($config) {
-
 
23
		
-
 
24
		parent::__construct($config);
-
 
25
		
-
 
26
		// Connection à la base de données spécifique eflore
-
 
27
		$this->bdd = $this->connecterPDO($this->config, 'database');	
-
 
28
	}
-
 
29
	
-
 
30
	public function rechercherGenreEspeceSurPrefixe($genre = null, $espece = null) {
-
 
31
		
-
 
32
		$liste_genre_espece = array();	
-
 
33
		
-
 
34
		$requete_recherche = '';
-
 
35
		// Genre et Espece 
-
 
36
		if ($espece != null && $genre != null) {	
-
 
37
            if (strlen($espece) > 0 ) {
-
 
38
				$espece=ereg_replace('\*+','%',$espece);
-
 
39
    	       	$requete_recherche = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,". 
-
 
40
    	       			"   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
-
 
41
    	       			" , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
-
 
42
    	       			" , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
-
 
43
    	       			" , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
-
 
44
    	       			" , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom, esn_ce_statut" .
-
 
45
    	       			" FROM eflore_nom, eflore_nom_rang, " .
-
 
46
    	       			"  	  eflore_naturaliste_intitule_abreviation AS auteur_bex ".
-
 
47
    	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
-
 
48
    	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
-
 
49
    	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
-
 
50
    	       	     	"   , eflore_selection_nom".
-
 
51
    	       			" WHERE en_id_version_projet_nom = '25' AND en_nom_genre LIKE ".$this->proteger($genre.'%').
-
 
52
    	       			" AND en_ce_rang > 160 " .
-
 
53
    	       			" AND en_epithete_espece like ".$this->proteger($espece.'%')." AND en_ce_rang = enrg_id_rang " .
-
 
54
    	       			" AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
-
 
55
    	       			" AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
-
 
56
    	       			" AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ". 
-
 
57
    	       			" AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
-
 
58
    	       			" AND esn_id_version_projet_taxon=en_id_version_projet_nom " . 
-
 
59
    	       			" AND esn_id_nom= en_id_nom ".
-
 
60
    	       			" ORDER BY esn_ce_statut, en_ce_rang, en_epithete_espece, en_nom_genre LIMIT 50";
-
 
61
            }
-
 
62
		}
-
 
63
		else {
-
 
64
			if ($genre != null) {
-
 
65
				$genre=ereg_replace('\*+','%',$genre);
-
 
66
				//TODO: comprendre pourquoi à l'origine il y avait : (strlen($genre) >= 1) /*&& ($genre != '%')
-
 
67
	            if ((strlen($genre) >= 1)) {
-
 
68
				    $requete_recherche = "SELECT DISTINCT en_nom_genre, en_id_nom, 0 as esn_ce_statut FROM  eflore_nom WHERE en_id_version_projet_nom = '25'" .
-
 
69
				    "AND en_ce_rang = 160 " .
-
 
70
				    "AND en_nom_genre LIKE ".$this->proteger($genre.'%')." ORDER BY esn_ce_statut, en_nom_genre LIMIT 50";
-
 
71
	            }
-
 
72
			}
-
 
73
		}
-
 
74
		
-
 
75
        if($requete_recherche != '') {
-
 
76
        	$resultat_recherche = $this->requeter($requete_recherche);	
-
 
77
        	
-
 
78
        	if (is_array($resultat_recherche)) {
-
 
79
        		foreach($resultat_recherche as $ligne) {
-
 
80
        			$liste_genre_espece[] = array($this->formaterNom($ligne),
-
 
81
        										$ligne['en_id_nom'], 
-
 
82
        										$ligne['esn_ce_statut']
-
 
83
        									);
-
 
84
        		}
-
 
85
	    
-
 
86
        	}	
-
 
87
        }
-
 
88
		    
-
 
89
		return $liste_genre_espece;
-
 
90
	}
-
 
91
 
-
 
92
	function rechercherInformationsComplementairesSurNumNom($numNom) {
-
 
93
 
-
 
94
		$resultat_infos_complementaires = $this->effectuerRequeteInfosComplementairesSurNumNom($numNom);
-
 
95
 
-
 
96
		// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
-
 
97
		$value=array('Nom_Retenu'=>"",'Num_Nom_Retenu'=>"0",'Num_Taxon'=>"0",'Famille'=>"");
-
 
98
 
-
 
99
        if (is_array($resultat_infos_complementaires)) {
-
 
100
		    foreach($resultat_infos_complementaires as $row) {
-
 
101
		        	$fam=$this->rechercherFamille($row['esn_id_taxon']);
-
 
102
	        	while (($fam['en_ce_rang']!='fin') && ($fam['en_ce_rang'] !=120)) {
-
 
103
		        	$fam=$this->rechercherFamille($fam['etr_id_taxon_2']);
-
 
104
	        	}
-
 
105
	        	if ($fam['en_ce_rang']==120) {
-
 
106
	        		$famille=$fam['en_nom_supra_generique'];
-
 
107
	        	}
-
 
108
	        	else {
-
 
109
	        		$famille="Famille inconnue";
-
 
110
	        	}
-
 
111
	        	$value=array('Nom_Retenu'=>$this->formaterNom($row),'Num_Nom_Retenu'=>$row['esn_id_nom'],'Num_Taxon'=>$row['esn_id_taxon'],'Famille'=>$famille);
-
 
112
		    }
-
 
113
        }
Line 16... Line 114...
16
 
114
 
Line -... Line 115...
-
 
115
	    return $value;
-
 
116
 
-
 
117
	}
-
 
118
	
-
 
119
	public function effectuerRequeteInfosComplementairesEtFormaterNom($numNom) {
-
 
120
		
-
 
121
		$resultat_infos_complementaires = $this->effectuerRequeteInfosComplementairesSurNumNom($numNom);
-
 
122
		
-
 
123
		$retour_infos_complementaires = array();
-
 
124
		foreach ($resultat_infos_complementaires as $info) {
-
 
125
           $retour_infos_complementaires=array(($this->formaterNom($info)));
-
 
126
	    }
-
 
127
		
-
 
128
		return $retour_infos_complementaires;
-
 
129
	}
-
 
130
	
17
	function rechercherInformationsComplementaires($numNom) {
131
	public function effectuerRequeteInfosComplementairesSurNumNom($numNom) {
18
 
132
				
19
		$requete_infos_complementaires = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
133
		$requete_infos_complementaires = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
20
			     	       			"   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
134
			     	       			"   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
21
        	       			" , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
135
        	       			" , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
Line 26... Line 140...
26
			       			"  	  eflore_naturaliste_intitule_abreviation AS auteur_bex ".
140
			       			"  	  eflore_naturaliste_intitule_abreviation AS auteur_bex ".
27
        	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
141
        	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
28
        	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
142
        	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
29
        	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
143
        	       			"   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
30
			     " ,eflore_selection_nom a, eflore_selection_nom b".
144
			     " ,eflore_selection_nom a, eflore_selection_nom b".
31
			     " WHERE a.esn_id_nom= ".$numNom.
145
			     " WHERE a.esn_id_nom= ".$this->proteger($numNom).
32
			     " AND a.esn_id_version_projet_taxon = 25 ".
146
			     " AND a.esn_id_version_projet_taxon = 25 ".
33
			     " AND a.esn_id_taxon=b.esn_id_taxon ".
147
			     " AND a.esn_id_taxon=b.esn_id_taxon ".
34
			     " AND b.esn_ce_statut=3 ".
148
			     " AND b.esn_ce_statut=3 ".
35
			     " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
149
			     " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
36
			     " AND en_ce_rang = enrg_id_rang" .
150
			     " AND en_ce_rang = enrg_id_rang" .
Line 39... Line 153...
39
       			 " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
153
       			 " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
40
       			 " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
154
       			 " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
41
        	     " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
155
        	     " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
42
			     " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
156
			     " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
Line -... Line 157...
-
 
157
 
43
 
158
		
44
		$resultat_infos_complementaires = $this->requeter($requete_infos_complementaires);
159
		$resultat_infos_complementaires = $this->requeter($requete_infos_complementaires);
45
 
-
 
46
		// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
-
 
47
		$value=array('Nom_Retenu'=>"",'Num_Nom_Retenu'=>"0",'Num_Taxon'=>"0",'Famille'=>"");
-
 
48
 
-
 
49
        if (is_array($resultat_infos_complementaires)) {
160
		
50
		    foreach($resultat_infos_complementaires as $row) {
-
 
51
		        	$fam=$this->rechercherFamille($row['esn_id_taxon']);
-
 
52
	        	while (($fam['en_ce_rang']!='fin') && ($fam['en_ce_rang'] !=120)) {
-
 
53
		        	$fam=$this->rechercherFamille($fam['etr_id_taxon_2']);
-
 
54
	        	}
-
 
55
	        	if ($fam['en_ce_rang']==120) {
-
 
56
	        		$famille=$fam['en_nom_supra_generique'];
-
 
57
	        	}
-
 
58
	        	else {
-
 
59
	        		$famille="Famille inconnue";
-
 
60
	        	}
-
 
61
	        	$value=array('Nom_Retenu'=>$this->formaterNom($row),'Num_Nom_Retenu'=>$row['esn_id_nom'],'Num_Taxon'=>$row['esn_id_taxon'],'Famille'=>$famille);
-
 
62
		    }
-
 
63
        }
-
 
64
 
-
 
65
	    return $value;
-
 
66
 
161
		return $resultat_infos_complementaires;
Line 67... Line 162...
67
	}
162
	}
Line 68... Line 163...
68
	
163
	
Line 69... Line 164...
69
	function rechercherInformationsComplementairesSurNom($nom_saisi) {
164
	public function rechercherInformationsComplementairesSurNom($nom_saisi) {
Line 70... Line 165...
70
				
165
				
71
		$value = array();
166
		$value = array();
72
		
167
		
73
		if($nom_saisi != null && $nom_saisi != "") { 
168
		if($nom_saisi != null && $nom_saisi != "") { 
74
		
169
		
75
			$requete_infos_comp_sur_nom = 'SELECT * FROM eflore_nom_intitule '.
170
			$requete_infos_comp_sur_nom = 'SELECT * FROM '.$this->config['cel_db']['bdd_eflore'].'.eflore_nom_intitule '.
Line 89... Line 184...
89
		}
184
		}
Line 90... Line 185...
90
	                
185
	                
91
		return $value;
186
		return $value;
Line 92... Line -...
92
	}
-
 
93
 
-
 
94
	function formaterNom($rawnom) {
-
 
95
 
-
 
96
        // Constitution du nom:
-
 
97
        $nom = '';
-
 
98
 
-
 
99
        if ($rawnom['en_nom_supra_generique'] != '') {
-
 
100
            $nom .= $rawnom['en_nom_supra_generique'];
-
 
101
        } else if ($rawnom['en_epithete_infra_generique'] != '') {
-
 
102
            $nom .= $rawnom['en_epithete_infra_generique'];
-
 
103
        } else {
-
 
104
                if ($rawnom['en_nom_genre'] != '') {
-
 
105
                    $nom .=  $rawnom['en_nom_genre'];
-
 
106
                }
-
 
107
                if ($rawnom['en_epithete_espece']!= '') {
-
 
108
                    $nom .= ' '.$rawnom['en_epithete_espece'];
-
 
109
                }
-
 
110
                if ($rawnom['en_epithete_infra_specifique'] != '') {
-
 
111
                        if (!empty($rawnom['enrg_abreviation_rang'])) {
-
 
112
                                $nom .= ' '.$rawnom['enrg_abreviation_rang'].'';
-
 
113
                        }
-
 
114
                        $nom .= ' '.$rawnom['en_epithete_infra_specifique'];
-
 
115
                }
-
 
116
 
-
 
117
        }
-
 
118
 
-
 
119
        return $nom .$this->retournerAuteur($rawnom) ;
-
 
120
 	}
187
	}
Line 121... Line 188...
121
 
188
 
Line 122... Line 189...
122
	function rechercherFamille($taxon) {
189
	public function rechercherFamille($taxon) {
123
	
190
	
-
 
191
		$row=array();
-
 
192
	
124
		$row=array();
193
		$requete_famille = "SELECT DISTINCT en_ce_rang, etr_id_taxon_2, en_id_nom, en_nom_supra_generique ".
125
	
194
		" FROM eflore_taxon_relation, ".
126
		$requete_famille = "SELECT DISTINCT en_ce_rang, etr_id_taxon_2, en_id_nom, en_nom_supra_generique ".
195
		" eflore_selection_nom, ".
127
		" FROM eflore_taxon_relation, eflore_selection_nom, eflore_nom ".
196
		" eflore_nom ".
128
		" WHERE etr_id_taxon_1 = ".$taxon.
197
		" WHERE etr_id_taxon_1 = ".$taxon.
Line 141... Line 210...
141
	    	$row['en_ce_rang']='fin';
210
	    	$row['en_ce_rang']='fin';
142
	    }
211
	    }
Line 143... Line 212...
143
	
212
	
144
		return $row;
213
		return $row;
-
 
214
	}
-
 
215
	
-
 
216
	public function rechercherNumTaxSurNumNom($num_nom) {
-
 
217
		
-
 
218
		$requete_num_tax = "SELECT DISTINCT b.esn_id_taxon FROM eflore_nom, eflore_nom_rang," .
-
 
219
		" eflore_selection_nom a, eflore_selection_nom b".
-
 
220
		" WHERE a.esn_id_nom= ".$this->proteger($num_nom). 
-
 
221
		" AND a.esn_id_version_projet_taxon = 25 ".
-
 
222
		" AND a.esn_id_taxon=b.esn_id_taxon ".
-
 
223
		" AND b.esn_ce_statut=3 ".
-
 
224
		" AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
-
 
225
		" AND en_ce_rang = enrg_id_rang" .
-
 
226
		" AND en_id_nom = b.esn_id_nom" .
-
 
227
		" AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
-
 
228
	     
-
 
229
	    $res_num_nom = $this->requeter($requete_num_tax);
-
 
230
		
-
 
231
		$nt = null;	    
-
 
232
		if(is_array($res_num_nom) && count($res_num_nom) > 0) {
-
 
233
			$nt=$res_num_nom[0]['esn_id_taxon'];
-
 
234
		}
-
 
235
		
-
 
236
		return $nt;
-
 
237
	}
-
 
238
	
Line -... Line 239...
-
 
239
	private function formaterNom($rawnom) {
-
 
240
 
Line -... Line 241...
-
 
241
        // Constitution du nom:
-
 
242
        $nom = '';
-
 
243
 
-
 
244
        if ($rawnom['en_nom_supra_generique'] != '') {
-
 
245
            $nom .= $rawnom['en_nom_supra_generique'];
-
 
246
        } else if ($rawnom['en_epithete_infra_generique'] != '') {
-
 
247
            $nom .= $rawnom['en_epithete_infra_generique'];
-
 
248
        } else {
-
 
249
            if ($rawnom['en_nom_genre'] != '') {
-
 
250
                $nom .=  $rawnom['en_nom_genre'];
-
 
251
            }
-
 
252
            if ($rawnom['en_epithete_espece']!= '') {
-
 
253
                $nom .= ' '.$rawnom['en_epithete_espece'];
-
 
254
            }
-
 
255
            if ($rawnom['en_epithete_infra_specifique'] != '') {
-
 
256
                if (!empty($rawnom['enrg_abreviation_rang'])) {
-
 
257
                        $nom .= ' '.$rawnom['enrg_abreviation_rang'].'';
-
 
258
                }
-
 
259
                $nom .= ' '.$rawnom['en_epithete_infra_specifique'];
-
 
260
            }
-
 
261
        }
Line 145... Line 262...
145
	}
262
 
146
 
263
        return $nom.$this->retournerAuteur($rawnom) ;
147
 
264
 	}
148
 
265
 
149
	function retournerAuteur($rawnom) {
266
	private function retournerAuteur($rawnom) {
150
		$auteurs = '';
267
		$auteurs = '';