Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1115 | Rev 1123 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1115 Rev 1116
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Classe gérant les images.
4
 * Classe gérant les images.
5
 *
5
 *
6
 * @category	PHP 5.2
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
7
 * @package		eflore-consultation
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @copyright	2011 Tela-Botanica
10
 * @copyright	2011 Tela-Botanica
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class Images extends Eflore {
15
class Images extends Eflore {
16
	
16
	
17
	private $nntaxon;
17
	private $nntaxon;
18
	private $limite;
18
	private $limite;
19
	private $depart;
19
	private $depart;
20
 
20
 
21
	public function setNnTaxon($nntax) {
21
	public function setNnTaxon($nntax) {
22
		$this->nntaxon = $nntax;
22
		$this->nntaxon = $nntax;
23
	}
23
	}
24
	
24
	
25
	public function setLimite($limite) {
25
	public function setLimite($limite) {
26
		$this->limite = $limite;
26
		$this->limite = $limite;
27
	}
27
	}
28
	
28
	
29
	public function setDepart($depart) {
29
	public function setDepart($depart) {
30
		$this->depart = $depart;
30
		$this->depart = $depart;
31
	}
31
	}
32
	
32
	
33
	//TODO: créer des fonctions spécifiques cel et photoflora pour plus de clarté ?
33
	//TODO: créer des fonctions spécifiques cel et photoflora pour plus de clarté ?
34
	public function getUrlsImagesParIdsNoms(Array $idsNoms) {
34
	public function getUrlsImagesParIdsNoms(Array $idsNoms) {
35
		$infosImages = $this->getInfosImagesParIdsNoms($idsNoms);
35
		$infosImages = $this->getInfosImagesParIdsNoms($idsNoms);
36
		$urls = array();
36
		$urls = array();
37
		if (count($infosImages) > 0) {
37
		if (count($infosImages) > 0) {
38
			foreach ($infosImages as $img) {
38
			foreach ($infosImages as $img) {
39
				$id = $img['determination.nom_sci.code'];
39
				$id = $img['determination.nom_sci.code'];
40
				$urls[$id][] = $img['binaire.href'];
40
				$urls[$id][] = $img['binaire.href'];
41
			}
41
			}
42
		}
42
		}
43
		return $urls;
43
		return $urls;
44
	}
44
	}
45
 
45
 
46
	public function getInfosImagesParIdsNoms(Array $idsNoms) {
46
	public function getInfosImagesParIdsNoms(Array $idsNoms) {
47
		$pas = 800;
47
		$pas = 800;
48
		if(count($idsNoms) >= $pas) {
48
		if(count($idsNoms) >= $pas) {
49
			$images = array();
49
			$images = array();
50
			$idsPartages = array_chunk($idsNoms, $pas);
50
			$idsPartages = array_chunk($idsNoms, $pas);
51
			foreach ($idsPartages as $sousEnsembleIdsNoms) {
51
			foreach ($idsPartages as $sousEnsembleIdsNoms) {
52
				$url = $this->getUrlImagesParIdsNoms($sousEnsembleIdsNoms);
52
				$url = $this->getUrlImagesParIdsNoms($sousEnsembleIdsNoms);
53
				$donnees = $this->chargerDonnees($url);
53
				$donnees = $this->chargerDonnees($url);
54
				$resultats = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
54
				$resultats = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
55
				$images += $resultats;
55
				$images += $resultats;
56
			}
56
			}
57
		} else {
57
		} else {
58
			$url = $this->getUrlImagesParIdsNoms($idsNoms);
58
			$url = $this->getUrlImagesParIdsNoms($idsNoms);
59
			$donnees = $this->chargerDonnees($url);
59
			$donnees = $this->chargerDonnees($url);
60
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
60
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
61
		}
61
		}
62
		return $this->formaterResultatImages($images);
62
		return $this->formaterResultatImages($images);
63
	}
63
	}
64
 
64
 
65
	public function getInfosImageParIdImage($id_image) {
65
	public function getInfosImageParIdImage($id_image) {
66
		$tpl = $this->obtenirSqueletteSelonApi('imagesPopup');
66
		$tpl = $this->obtenirSqueletteSelonApi('imagesPopup');
67
		$url = $this->formaterUrl($tpl, array('id' => $id_image, 'referentiel' => Registre::get('parametres.referentiel')));
67
		$url = $this->formaterUrl($tpl, array('id' => $id_image, 'referentiel' => Registre::get('parametres.referentiel')));
68
		$image = $this->chargerDonnees($url);
68
		$image = $this->chargerDonnees($url);
69
		return $this->formaterResultatImages($image, true);
69
		return $this->formaterResultatImages($image, true);
70
	}
70
	}
71
	
71
	
72
	public function getInfosImages() {
72
	public function getInfosImages() {
73
		$url = $this->getUrlImages();
73
		$url = $this->getUrlImages();
74
		$donnees = $this->chargerDonnees($url);
74
		$donnees = $this->chargerDonnees($url);
75
		$images = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
75
		$images = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
76
		return $this->formaterResultatImages($images);
76
		return $this->formaterResultatImages($images);
77
	}
77
	}
78
 
78
 
79
	public function getInfosImagesTaxons() {
79
	public function getInfosImagesTaxons() {
80
		$pas = 800;
80
		$pas = 800;
81
		$idsTaxons = explode(',', $this->nntaxon);
81
		$idsTaxons = explode(',', $this->nntaxon);
82
		if(count($idsTaxons) >= $pas) {
82
		if(count($idsTaxons) >= $pas) {
83
			$images = array();
83
			$images = array();
84
			$idsPartages = array_chunk($idsTaxons, $pas);
84
			$idsPartages = array_chunk($idsTaxons, $pas);
85
			foreach ($idsPartages as $sousEnsembleIdsTaxons) {
85
			foreach ($idsPartages as $sousEnsembleIdsTaxons) {
86
				$url = $this->getUrlImagesTaxons(implode(',',$sousEnsembleIdsTaxons));
86
				$url = $this->getUrlImagesTaxons(implode(',',$sousEnsembleIdsTaxons));
87
				$donnees = $this->chargerDonnees($url);
87
				$donnees = $this->chargerDonnees($url);
88
				$resultats = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
88
				$resultats = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
89
				$images += $resultats;
89
				$images += $resultats;
90
			}
90
			}
91
		} else {
91
		} else {
92
			$url = $this->getUrlImagesTaxons($idsTaxons);
92
			$url = $this->getUrlImagesTaxons($idsTaxons);
93
			$donnees = $this->chargerDonnees($url);
93
			$donnees = $this->chargerDonnees($url);
94
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
94
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
95
		}
95
		}
96
		return $this->formaterResultatImages($images);
96
		return $this->formaterResultatImages($images);
97
	}
97
	}
98
 
98
 
99
	public function getInfosPremiereImageParIdsNoms($idsNoms) {
99
	public function getInfosPremiereImageParIdsNoms($idsNoms) {
100
		$url = $this->getUrlPremiereImageParIdsNoms($idsNoms);
100
		$url = $this->getUrlPremiereImageParIdsNoms($idsNoms);
101
		$donnees = $this->chargerDonnees($url);
101
		$donnees = $this->chargerDonnees($url);
102
		$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
102
		$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
103
		return $this->formaterResultatImages($images);
103
		return $this->formaterResultatImages($images);
104
	}
104
	}
105
 
105
 
106
	public function getInfosImagesGalerieMobile($nn) {
106
	public function getInfosImagesGalerieMobile($nn) {
107
		$url = $this->getUrlImagesGalerieMobile($nn);
107
		$url = $this->getUrlImagesGalerieMobile($nn);
108
		$donnees = $this->chargerDonnees($url);
108
		$donnees = $this->chargerDonnees($url);
109
		$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
109
		$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
110
		$this->formaterResultatImagesDel($images);
-
 
111
		return $images;
110
		return $images;
112
	}
111
	}
-
 
112
 
-
 
113
	/**
-
 
114
	 * Retourne les $limite images ayant le plus de votes pour le protocole $protocole et le(s) tag(s) $tags
-
 
115
	 * 
-
 
116
	 * @param number $nn
-
 
117
	 * @param mixed $tags
-
 
118
	 * @param number $protocole
-
 
119
	 * @param number $limite
-
 
120
	 * @return array
-
 
121
	 */
-
 
122
	public function getInfosMeilleuresImagesParTag($nn, $tags, $protocole = Eflore::PROTOCOLE_CAPITALISATION, $limite = 10) {
-
 
123
		if (! is_array($tags)) {
-
 
124
			$tags = array($tags);
-
 
125
		}
-
 
126
		$images_tag = array();
-
 
127
		foreach ($tags as $tag) {
-
 
128
			$url = $this->getUrlMeilleuresImagesParTag($nn, $tag, $protocole, $limite);
-
 
129
			$donnees = $this->chargerDonnees($url);
-
 
130
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
-
 
131
			$images_tag[$tag] = $images;
-
 
132
		}
-
 
133
		return $images_tag;
-
 
134
	}
113
 
135
 
114
	private function getUrlImagesParIdsNoms($idsNoms) {
136
	private function getUrlImagesParIdsNoms($idsNoms) {
115
		$tpl = $this->obtenirSqueletteSelonApi('imagesResultatsDetermination');
137
		$tpl = $this->obtenirSqueletteSelonApi('imagesResultatsDetermination');
116
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
138
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
117
		$url = $this->formaterUrl($tpl, $params);
139
		$url = $this->formaterUrl($tpl, $params);
118
		return $url;
140
		return $url;
119
	}
141
	}
120
 
142
 
121
	private function getUrlPremiereImageParIdsNoms($idsNoms) {
143
	private function getUrlPremiereImageParIdsNoms($idsNoms) {
122
		$tpl = $this->obtenirSqueletteSelonApi('imagesPremiere');
144
		$tpl = $this->obtenirSqueletteSelonApi('imagesPremiere');
123
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
145
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
124
		return $this->formaterUrl($tpl, $params);
146
		return $this->formaterUrl($tpl, $params);
125
	}
147
	}
126
 
148
 
127
	private function getUrlImages($nn = false) {
149
	private function getUrlImages($nn = false) {
128
		$tpl = $this->obtenirSqueletteSelonApi('images');
150
		$tpl = $this->obtenirSqueletteSelonApi('images');
129
		if ($this->getApi() == Eflore::API_EFLORE) {
151
		if ($this->getApi() == Eflore::API_EFLORE) {
130
			$params = array('projet' => $this->getProjet(), 'limite' => $this->limite, 'depart' => $this->depart, 'referentiel' => Registre::get('parametres.referentiel'));
152
			$params = array('projet' => $this->getProjet(), 'limite' => $this->limite, 'depart' => $this->depart, 'referentiel' => Registre::get('parametres.referentiel'));
131
		}
153
		}
132
		$url = $this->formaterUrl($tpl, $params);
154
		$url = $this->formaterUrl($tpl, $params);
133
		return $url;
155
		return $url;
134
	}
156
	}
135
 
157
 
136
	private function getUrlImagesTaxons($idsTaxons) {
158
	private function getUrlImagesTaxons($idsTaxons) {
137
		$tpl = $this->obtenirSqueletteSelonApi('imagesTaxons');
159
		$tpl = $this->obtenirSqueletteSelonApi('imagesTaxons');
138
		$params = array('projet' => $this->getProjet(),'nntaxon'=> $idsTaxons, 'referentiel' => Registre::get('parametres.referentiel'));
160
		$params = array('projet' => $this->getProjet(),'nntaxon'=> $idsTaxons, 'referentiel' => Registre::get('parametres.referentiel'));
139
		$url = $this->formaterUrl($tpl, $params);
161
		$url = $this->formaterUrl($tpl, $params);
140
		return $url;
162
		return $url;
141
	}
163
	}
142
 
164
 
143
	private function getUrlImagesGalerieMobile($nn) {
165
	private function getUrlImagesGalerieMobile($nn) {
144
		$tpl = Config::get('delGalerieMobileTpl');
166
		$tpl = Config::get('delGalerieMobileTpl');
145
		$params = array('nn' => $nn);
167
		$params = array('nn' => $nn);
146
		$url = $this->formaterUrl($tpl, $params);
168
		$url = $this->formaterUrl($tpl, $params);
147
		return $url;
169
		return $url;
148
	}
170
	}
-
 
171
 
-
 
172
	private function getUrlMeilleuresImagesParTag($nn, $tag, $protocole = Eflore::PROTOCOLE_CAPITALISATION, $limite = 10) {
-
 
173
		$tpl = Config::get('delMeilleuresImagesParTagTpl');
-
 
174
		$params = array('nn'=> $nn,
-
 
175
						'tag'=> $tag,
-
 
176
						'protocole' => $protocole,
-
 
177
						'referentiel' => Registre::get('parametres.referentiel'),
-
 
178
						'limite' => $limite);
-
 
179
		$url = $this->formaterUrl($tpl, $params);
-
 
180
		return $url;
-
 
181
	}
149
 
182
 
150
	/**
183
	/**
151
	 * Transforme les résultats issus des Webservices autres que eflore/cel afin de conserver un format homogène
184
	 * Transforme les résultats issus des Webservices autres que eflore/cel afin de conserver un format homogène
152
	 * @param mixed $images
185
	 * @param mixed $images
153
	 */
186
	 */
154
	private function formaterResultatImages($images, $seulementUne = false) {
187
	private function formaterResultatImages($images, $seulementUne = false) {
155
		switch ($this->getApi()) {
188
		switch ($this->getApi()) {
156
			case Eflore::API_DEL:
189
			case Eflore::API_DEL:
157
				return $this->formaterResultatImagesDel($images, $seulementUne);
190
				return $this->formaterResultatImagesDel($images, $seulementUne);
158
			break;
191
			break;
159
			default:
192
			default:
160
				return $images;
193
				return $images;
161
		}
194
		}
162
	}
195
	}
163
 
196
 
164
	private function formaterResultatImagesDel($images, $seulementUne = false) {
197
	private function formaterResultatImagesDel($images, $seulementUne = false) {
165
		if ($seulementUne) {
198
		if ($seulementUne) {
166
			return $this->formaterUnResultatImagesDel($images);
199
			return $this->formaterUnResultatImagesDel($images);
167
		} else {
200
		} else {
168
			$retour = array();
201
			$retour = array();
169
			foreach ($images as $idObsImage => $image) {
202
			foreach ($images as $idObsImage => $image) {
170
				$retour[$image['id_image']] = array_merge($images[$idObsImage], $this->formaterUnResultatImagesDel($image));
203
				$retour[$image['id_image']] = array_merge($images[$idObsImage], $this->formaterUnResultatImagesDel($image));
171
			}
204
			}
172
			return $retour;
205
			return $retour;
173
		}
206
		}
174
	}
207
	}
175
 
208
 
176
	/**
209
	/**
177
	 * Convertit un array venant d'un Webservice del vers le format retourné par eflore/cel
210
	 * Convertit un array venant d'un Webservice del vers le format retourné par eflore/cel
178
	 * @param array $image
211
	 * @param array $image
179
	 * @return array
212
	 * @return array
180
	 */
213
	 */
181
	private function formaterUnResultatImagesDel(array $image) {
214
	private function formaterUnResultatImagesDel(array $image) {
182
		//echo "FORMAT DEL: <pre>"; print_r($image); echo "</pre>";
-
 
183
		$libelleAuteur = $image['observation']['auteur.prenom'].' '.$image['observation']['auteur.nom'];
215
		$libelleAuteur = $image['observation']['auteur.prenom'].' '.$image['observation']['auteur.nom'];
184
		$codeReferentiel = substr($image['observation']['determination.referentiel'], 0, strpos($image['observation']['determination.referentiel'], ':'));
216
		$codeReferentiel = substr($image['observation']['determination.referentiel'], 0, strpos($image['observation']['determination.referentiel'], ':'));
185
		$localiteLibelle = array($image['observation']['zone_geo'],
217
		$localiteLibelle = array($image['observation']['zone_geo'],
186
				$image['observation']['lieudit'],
218
				$image['observation']['lieudit'],
187
				$image['observation']['station'],
219
				$image['observation']['station'],
188
				$image['observation']['milieu']);
220
				$image['observation']['milieu']);
189
		$retourImage = array(
221
		$retourImage = array(
190
				'date' => $image['observation']['date_observation'],
222
				'date' => $image['observation']['date_observation'],
191
				'mime' => 'image/jpeg',
223
				'mime' => 'image/jpeg',
192
				'auteur.libelle' => $libelleAuteur,
224
				'auteur.libelle' => $libelleAuteur,
193
				'auteur.id' => $image['observation']['auteur.id'],
225
				'auteur.id' => $image['observation']['auteur.id'],
194
				'binaire.href' => $image['binaire.href'],
226
				'binaire.href' => $image['binaire.href'],
195
				'observation.id' => $image['observation']['id_observation'],
227
				'observation.id' => $image['observation']['id_observation'],
196
				'determination.libelle' => $image['observation']['determination.ns'].'[Dét. : '.$libelleAuteur.']',
228
				'determination.libelle' => $image['observation']['determination.ns'].'[Dét. : '.$libelleAuteur.']',
197
				'determination.nom_sci' => $image['observation']['determination.ns'],
229
				'determination.nom_sci' => $image['observation']['determination.ns'],
198
				'determination.nom_sci.code' => $codeReferentiel.'.'.$image['observation']['determination.nn'],
230
				'determination.nom_sci.code' => $codeReferentiel.'.'.$image['observation']['determination.nn'],
199
				'station.commune' => $image['observation']['zone_geo'],
231
				'station.commune' => $image['observation']['zone_geo'],
200
				'station.lieudit' => $image['observation']['lieudit'],
232
				'station.lieudit' => $image['observation']['lieudit'],
201
				'station.station' => $image['observation']['station'],
233
				'station.station' => $image['observation']['station'],
202
				'station.milieu' => $image['observation']['milieu'],
234
				'station.milieu' => $image['observation']['milieu'],
203
				'station.libelle' => $this->formaterLocalite($localiteLibelle)
235
				'station.libelle' => $this->formaterLocalite($localiteLibelle)
204
		);
236
		);
205
		//echo "FORMAT CEL: <pre>"; print_r($retourImage); echo "</pre>";
-
 
206
		return $retourImage;
237
		return $retourImage;
207
	}
238
	}
208
	
239
	
209
	private function formaterLocalite($infosLocalite) {
240
	private function formaterLocalite($infosLocalite) {
210
		$localiteFmt = array();
241
		$localiteFmt = array();
211
		foreach ($infosLocalite as $localite) {
242
		foreach ($infosLocalite as $localite) {
212
			if($localite != '') {
243
			if($localite != '') {
213
				$localiteFmt[] = $localite;
244
				$localiteFmt[] = $localite;
214
			}
245
			}
215
		}
246
		}
216
		if (empty($localiteFmt)) {
247
		if (empty($localiteFmt)) {
217
			$localiteFmt[0] = 'localité inconnue';
248
			$localiteFmt[0] = 'localité inconnue';
218
		}
249
		}
219
		return implode(" > ", $localiteFmt);
250
		return implode(" > ", $localiteFmt);
220
	}
251
	}
221
}
252
}
222
?>
253
?>