Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 1123 Rev 1127
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
		return $images;
110
		return $images;
111
	}
111
	}
112
 
112
 
113
	/**
113
	/**
114
	 * Retourne les $limite images ayant le plus de votes pour le protocole $protocole et le(s) tag(s) $tags
114
	 * Retourne les $limite images ayant le plus de votes pour le protocole $protocole et le(s) tag(s) $tags
115
	 */
115
	 */
116
	public function getInfosMeilleuresImagesParTag($nn, $tags, $protocole = Eflore::PROTOCOLE_CAPITALISATION, $limite = 10, $format = 'CRS') {
116
	public function getInfosMeilleuresImagesParTag($nn, $tags, $protocole = Eflore::PROTOCOLE_CAPITALISATION, $limite = 10, $format = 'CRS') {
117
		if (! is_array($tags)) {
117
		if (! is_array($tags)) {
118
			$tags = array($tags);
118
			$tags = array($tags);
119
		}
119
		}
120
		$images_tag = array();
120
		$images_tag = array();
121
		foreach ($tags as $tag) {
121
		foreach ($tags as $tag) {
122
			$url = $this->getUrlMeilleuresImagesParTag($nn, $tag, $protocole, $limite, $format);
122
			$url = $this->getUrlMeilleuresImagesParTag($nn, $tag, $protocole, $limite, $format);
123
			$donnees = $this->chargerDonnees($url);
123
			$donnees = $this->chargerDonnees($url);
124
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
124
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
125
			$images_tag[$tag] = $this->formaterResultatImagesDel($images);
125
			$images_tag[$tag] = $this->formaterResultatImagesDel($images);
126
		}
126
		}
127
		return $images_tag;
127
		return $images_tag;
128
	}
128
	}
129
 
129
 
130
	private function getUrlImagesParIdsNoms($idsNoms) {
130
	private function getUrlImagesParIdsNoms($idsNoms) {
131
		$tpl = $this->obtenirSqueletteSelonApi('imagesResultatsDetermination');
131
		$tpl = $this->obtenirSqueletteSelonApi('imagesResultatsDetermination');
132
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
132
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
133
		$url = $this->formaterUrl($tpl, $params);
133
		$url = $this->formaterUrl($tpl, $params);
134
		return $url;
134
		return $url;
135
	}
135
	}
136
 
136
 
137
	private function getUrlPremiereImageParIdsNoms($idsNoms) {
137
	public function getUrlPremiereImageParIdsNoms($idsNoms) {
138
		$tpl = $this->obtenirSqueletteSelonApi('imagesPremiere');
138
		$tpl = $this->obtenirSqueletteSelonApi('imagesPremiere');
139
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
139
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
140
		return $this->formaterUrl($tpl, $params);
140
		return $this->formaterUrl($tpl, $params);
141
	}
141
	}
142
 
142
 
143
	private function getUrlImages($nn = false) {
143
	private function getUrlImages($nn = false) {
144
		$tpl = $this->obtenirSqueletteSelonApi('images');
144
		$tpl = $this->obtenirSqueletteSelonApi('images');
145
		if ($this->getApi() == Eflore::API_EFLORE) {
145
		if ($this->getApi() == Eflore::API_EFLORE) {
146
			$params = array('projet' => $this->getProjet(), 'limite' => $this->limite, 'depart' => $this->depart, 'referentiel' => Registre::get('parametres.referentiel'));
146
			$params = array('projet' => $this->getProjet(), 'limite' => $this->limite, 'depart' => $this->depart, 'referentiel' => Registre::get('parametres.referentiel'));
147
		}
147
		}
148
		$url = $this->formaterUrl($tpl, $params);
148
		$url = $this->formaterUrl($tpl, $params);
149
		return $url;
149
		return $url;
150
	}
150
	}
151
 
151
 
152
	private function getUrlImagesTaxons($idsTaxons) {
152
	private function getUrlImagesTaxons($idsTaxons) {
153
		$tpl = $this->obtenirSqueletteSelonApi('imagesTaxons');
153
		$tpl = $this->obtenirSqueletteSelonApi('imagesTaxons');
154
		$params = array('projet' => $this->getProjet(),'nntaxon'=> $idsTaxons, 'referentiel' => Registre::get('parametres.referentiel'));
154
		$params = array('projet' => $this->getProjet(),'nntaxon'=> $idsTaxons, 'referentiel' => Registre::get('parametres.referentiel'));
155
		$url = $this->formaterUrl($tpl, $params);
155
		$url = $this->formaterUrl($tpl, $params);
156
		return $url;
156
		return $url;
157
	}
157
	}
158
 
158
 
159
	private function getUrlImagesGalerieMobile($nn) {
159
	private function getUrlImagesGalerieMobile($nn) {
160
		$tpl = Config::get('delGalerieMobileTpl');
160
		$tpl = Config::get('delGalerieMobileTpl');
161
		$params = array('nn' => $nn);
161
		$params = array('nn' => $nn);
162
		$url = $this->formaterUrl($tpl, $params);
162
		$url = $this->formaterUrl($tpl, $params);
163
		return $url;
163
		return $url;
164
	}
164
	}
165
 
165
 
166
	private function getUrlMeilleuresImagesParTag($nn, $tag, $protocole = Eflore::PROTOCOLE_CAPITALISATION, $limite = 10, $format = 'CRS') {
166
	private function getUrlMeilleuresImagesParTag($nn, $tag, $protocole = Eflore::PROTOCOLE_CAPITALISATION, $limite = 10, $format = 'CRS') {
167
		$tpl = Config::get('delMeilleuresImagesParTagTpl');
167
		$tpl = Config::get('delMeilleuresImagesParTagTpl');
168
		$params = array('nn'=> $nn,
168
		$params = array('nn'=> $nn,
169
						'tag'=> $tag,
169
						'tag'=> $tag,
170
						'protocole' => $protocole,
170
						'protocole' => $protocole,
171
						'referentiel' => Registre::get('parametres.referentiel'),
171
						'referentiel' => Registre::get('parametres.referentiel'),
172
						'limite' => $limite,
172
						'limite' => $limite,
173
						'format' => $format);
173
						'format' => $format);
174
		$url = $this->formaterUrl($tpl, $params);
174
		$url = $this->formaterUrl($tpl, $params);
175
		return $url;
175
		return $url;
176
	}
176
	}
177
 
177
 
178
	/**
178
	/**
179
	 * Transforme les résultats issus des Webservices autres que eflore/cel afin de conserver un format homogène
179
	 * Transforme les résultats issus des Webservices autres que eflore/cel afin de conserver un format homogène
180
	 * @param mixed $images
180
	 * @param mixed $images
181
	 */
181
	 */
182
	private function formaterResultatImages($images, $seulementUne = false) {
182
	private function formaterResultatImages($images, $seulementUne = false) {
183
		switch ($this->getApi()) {
183
		switch ($this->getApi()) {
184
			case Eflore::API_DEL:
184
			case Eflore::API_DEL:
185
				return $this->formaterResultatImagesDel($images, $seulementUne);
185
				return $this->formaterResultatImagesDel($images, $seulementUne);
186
			break;
186
			break;
187
			default:
187
			default:
188
				return $images;
188
				return $images;
189
		}
189
		}
190
	}
190
	}
191
 
191
 
192
	private function formaterResultatImagesDel($images, $seulementUne = false) {
192
	private function formaterResultatImagesDel($images, $seulementUne = false) {
193
		if ($seulementUne) {
193
		if ($seulementUne) {
194
			return $this->formaterUnResultatImagesDel($images);
194
			return $this->formaterUnResultatImagesDel($images);
195
		} else {
195
		} else {
196
			$retour = array();
196
			$retour = array();
197
			foreach ($images as $idObsImage => $image) {
197
			foreach ($images as $idObsImage => $image) {
198
				$retour[$image['id_image']] = array_merge($images[$idObsImage], $this->formaterUnResultatImagesDel($image));
198
				$retour[$image['id_image']] = array_merge($images[$idObsImage], $this->formaterUnResultatImagesDel($image));
199
			}
199
			}
200
			return $retour;
200
			return $retour;
201
		}
201
		}
202
	}
202
	}
203
 
203
 
204
	/**
204
	/**
205
	 * Convertit un array venant d'un Webservice del vers le format retourné par eflore/cel
205
	 * Convertit un array venant d'un Webservice del vers le format retourné par eflore/cel
206
	 * @param array $image
206
	 * @param array $image
207
	 * @return array
207
	 * @return array
208
	 */
208
	 */
209
	private function formaterUnResultatImagesDel(array $image) {
209
	private function formaterUnResultatImagesDel(array $image) {
210
		$libelleAuteur = $image['observation']['auteur.prenom'].' '.$image['observation']['auteur.nom'];
210
		$libelleAuteur = $image['observation']['auteur.prenom'].' '.$image['observation']['auteur.nom'];
211
		$codeReferentiel = substr($image['observation']['determination.referentiel'], 0, strpos($image['observation']['determination.referentiel'], ':'));
211
		$codeReferentiel = substr($image['observation']['determination.referentiel'], 0, strpos($image['observation']['determination.referentiel'], ':'));
212
		$localiteLibelle = array($image['observation']['zone_geo'],
212
		$localiteLibelle = array($image['observation']['zone_geo'],
213
				$image['observation']['lieudit'],
213
				$image['observation']['lieudit'],
214
				$image['observation']['station'],
214
				$image['observation']['station'],
215
				$image['observation']['milieu']);
215
				$image['observation']['milieu']);
216
		$retourImage = array(
216
		$retourImage = array(
217
				'date' => $image['observation']['date_observation'],
217
				'date' => $image['observation']['date_observation'],
218
				'mime' => 'image/jpeg',
218
				'mime' => 'image/jpeg',
219
				'auteur.libelle' => $libelleAuteur,
219
				'auteur.libelle' => $libelleAuteur,
220
				'auteur.id' => $image['observation']['auteur.id'],
220
				'auteur.id' => $image['observation']['auteur.id'],
221
				'binaire.href' => $image['binaire.href'],
221
				'binaire.href' => $image['binaire.href'],
222
				'observation.id' => $image['observation']['id_observation'],
222
				'observation.id' => $image['observation']['id_observation'],
223
				'determination.libelle' => $image['observation']['determination.ns'].'[Dét. : '.$libelleAuteur.']',
223
				'determination.libelle' => $image['observation']['determination.ns'].'[Dét. : '.$libelleAuteur.']',
224
				'determination.nom_sci' => $image['observation']['determination.ns'],
224
				'determination.nom_sci' => $image['observation']['determination.ns'],
225
				'determination.nom_sci.code' => $codeReferentiel.'.'.$image['observation']['determination.nn'],
225
				'determination.nom_sci.code' => $codeReferentiel.'.'.$image['observation']['determination.nn'],
226
				'station.commune' => $image['observation']['zone_geo'],
226
				'station.commune' => $image['observation']['zone_geo'],
227
				'station.lieudit' => $image['observation']['lieudit'],
227
				'station.lieudit' => $image['observation']['lieudit'],
228
				'station.station' => $image['observation']['station'],
228
				'station.station' => $image['observation']['station'],
229
				'station.milieu' => $image['observation']['milieu'],
229
				'station.milieu' => $image['observation']['milieu'],
230
				'station.libelle' => $this->formaterLocalite($localiteLibelle)
230
				'station.libelle' => $this->formaterLocalite($localiteLibelle)
231
		);
231
		);
232
		return $retourImage;
232
		return $retourImage;
233
	}
233
	}
234
	
234
	
235
	private function formaterLocalite($infosLocalite) {
235
	private function formaterLocalite($infosLocalite) {
236
		$localiteFmt = array();
236
		$localiteFmt = array();
237
		foreach ($infosLocalite as $localite) {
237
		foreach ($infosLocalite as $localite) {
238
			if($localite != '') {
238
			if($localite != '') {
239
				$localiteFmt[] = $localite;
239
				$localiteFmt[] = $localite;
240
			}
240
			}
241
		}
241
		}
242
		if (empty($localiteFmt)) {
242
		if (empty($localiteFmt)) {
243
			$localiteFmt[0] = 'localité inconnue';
243
			$localiteFmt[0] = 'localité inconnue';
244
		}
244
		}
245
		return implode(" > ", $localiteFmt);
245
		return implode(" > ", $localiteFmt);
246
	}
246
	}
247
}
247
}
248
?>
248
?>