Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 950 Rev 960
Line 13... Line 13...
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
* @version 1.0
14
* @version 1.0
15
* @copyright 1999-2012 Tela Botanica (accueil@tela-botanica.org)
15
* @copyright 1999-2012 Tela Botanica (accueil@tela-botanica.org)
16
*/
16
*/
Line -... Line 17...
-
 
17
 
-
 
18
require_once(dirname(__FILE__) . '/../../baseflor/Informations.php');
17
 
19
 
Line 18... Line 20...
18
class SyntaxonsCommun  extends Commun {
20
class SyntaxonsCommun  extends Commun {
19
	
21
	
20
	
22
	
21
	protected $table = "";
23
	protected $table = "";
22
	protected $format_reponse = 'syntaxons';
24
	protected $format_reponse = 'syntaxons';
23
	protected $serviceNom = 'syntaxons';
25
	protected $serviceNom = 'syntaxons';
24
	protected $Bdd;
26
	protected $Bdd;
25
	protected $syn;
27
	protected $syn;
26
	protected $niv;
28
	protected $niv;
27
	protected $limite_requete = array('depart' => 0, 'limite' => 100);
29
	protected $limite_requete = array('depart' => 0, 'limite' => 100);
28
	protected $requete_condition = '';
30
	protected $requete_condition = array();
29
	protected $total_resultat;
31
	protected $total_resultat;
30
	protected $champs_recherches = ' * ';
32
	protected $champs_recherches = ' * ';
Line 31... Line 33...
31
	protected $table_version;
33
	protected $table_version;
32
	protected $version_projet = '+' ;
34
	protected $version_projet = '+' ;
33
	protected $cache = array();	
35
	static $cache = array();	
34
	
36
	
35
	
37
	
Line 103... Line 105...
103
	
105
	
104
	protected function recupererOntologiesNiveau($valeur, $code){
106
	protected function recupererOntologiesNiveau($valeur, $code){
105
		$ontologie = array();
107
		$ontologie = array();
106
		$url = Config::get('url_service_base').Config::get('nom_projet').
108
		$url = Config::get('url_service_base').Config::get('nom_projet').
107
							'/ontologies/'.$code.':'.urlencode(urlencode($valeur));
109
							'/ontologies/'.$code.':'.urlencode(urlencode($valeur));
108
		if(array_key_exists($url, $this->cache)) {
110
		if(array_key_exists($url, self::$cache)) {
109
			$val = $this->cache[$url];
111
			$val = self::$cache[$url];
110
		} else {
112
		} else {
111
			$val = $this->consulterHref($url);
113
			$val = $this->consulterHref($url);
112
			$this->cache[$url] = $val;
114
			self::$cache[$url] = $val;
113
		}
115
		}
114
		$ontologie['niveau.code'] = $valeur;
116
		$ontologie['niveau.code'] = $valeur;
115
		$ontologie['niveau.libelle'] = $val->nom;
117
		$ontologie['niveau.libelle'] = $val->nom;
116
		$ontologie['niveau.href'] = $url;
118
		$ontologie['niveau.href'] = $url;
Line 143... Line 145...
143
		return $ontologie;
145
		return $ontologie;
144
	}
146
	}
Line 145... Line 147...
145
	
147
	
146
	protected function traiterOntologieNiveau($niveau) {
148
	protected function traiterOntologieNiveau($niveau) {
147
		$ontologie = array();
-
 
148
	
149
		$ontologie = array();
Line 149... Line 150...
149
		if ( preg_match('/syn {0,1}(['.implode('',$this->syn).']*)( *\[.+\])*/',$niveau,$retour)) {
150
		if ( preg_match('/syn {0,1}(['.implode($this->syn).']*)( *\[.+\])*/',$niveau,$retour)) {
Line 150... Line 151...
150
	
151
	
151
			$ontologie = $this->recupererOntologiesNiveauSyn($retour);
152
			$ontologie = $this->recupererOntologiesNiveauSyn($retour);
Line 158... Line 159...
158
	
159
	
Line 159... Line 160...
159
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
160
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
160
	
161
	
161
	protected function assemblerLaRequete() {
162
	protected function assemblerLaRequete() {
Line 162... Line 163...
162
		$requete = 	' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
163
		$requete = 	' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
163
		.$this->retournerRequeteCondition().' '.$this->delimiterResultatsRequete();
164
            .Informations::retournerRequeteCondition($this->requete_condition).' '.$this->delimiterResultatsRequete();
Line 164... Line -...
164
	
-
 
165
		return $requete;
-
 
166
	}
-
 
167
	
-
 
168
	protected function calculerTotalResultat() {
-
 
169
		$requete = 'SELECT count(*) as nombre FROM '.$this->table.' '.$this->retournerRequeteCondition();
-
 
170
	
-
 
171
		$res = $this->getBdd()->recuperer($requete);
-
 
172
		if ($res) {
-
 
173
			$this->total_resultat = $res['nombre'];
-
 
174
		} else {
-
 
175
			$this->total_resultat = 0;
-
 
176
			$e = 'Données introuvables dans la base';
-
 
177
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
165
	
178
		}
166
		return $requete;
-
 
167
	}
-
 
168
	
-
 
169
	protected function delimiterResultatsRequete() {
-
 
170
		$this->total_resultat = Informations::calculerTotalResultat(
-
 
171
            $this->getBdd(),
179
	}
172
            $this->table,
180
	
173
            Array(),
181
	protected function delimiterResultatsRequete() {
174
            $this->requete_condition);
182
		$this->calculerTotalResultat();
175
 
183
		$requete_limite = '';
176
		$requete_limite = '';
Line 195... Line 188...
195
		return $requete_limite;
188
		return $requete_limite;
196
	}
189
	}
Line 197... Line -...
197
	
-
 
198
	
-
 
199
	
-
 
200
	protected  function retournerRequeteCondition() {
-
 
201
		$condition = '';
-
 
202
		if (empty($this->requete_condition) == false) {
-
 
203
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
-
 
204
		}
-
 
Line 205... Line 190...
205
	
190
	
206
		return $condition;
191
	
207
	}
192