Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 947 Rev 1115
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 $images;
62
		return $this->formaterResultatImages($images);
63
	}
63
	}
64
 
64
 
65
	public function getInfosImageParIdImage($id_image) {
65
	public function getInfosImageParIdImage($id_image) {
66
		$tpl = Config::get('imagesPopupTpl');
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
		return $this->chargerDonnees($url);
68
		$image = $this->chargerDonnees($url);
-
 
69
		return $this->formaterResultatImages($image, true);
69
	}
70
	}
70
	
71
	
71
	public function getInfosImages() {
72
	public function getInfosImages() {
72
		$url = $this->getUrlImages();
73
		$url = $this->getUrlImages();
73
		$donnees = $this->chargerDonnees($url); 
74
		$donnees = $this->chargerDonnees($url);
74
		$images = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
75
		$images = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
75
		return $images;
76
		return $this->formaterResultatImages($images);
76
	}
77
	}
77
 
78
 
78
	public function getInfosImagesTaxons() {
79
	public function getInfosImagesTaxons() {
79
		$pas = 800;
80
		$pas = 800;
80
		$idsTaxons = explode(',', $this->nntaxon);
81
		$idsTaxons = explode(',', $this->nntaxon);
81
		if(count($idsTaxons) >= $pas) {
82
		if(count($idsTaxons) >= $pas) {
82
			$images = array();
83
			$images = array();
83
			$idsPartages = array_chunk($idsTaxons, $pas);
84
			$idsPartages = array_chunk($idsTaxons, $pas);
84
			foreach ($idsPartages as $sousEnsembleIdsTaxons) {
85
			foreach ($idsPartages as $sousEnsembleIdsTaxons) {
85
				$url = $this->getUrlImagesTaxons(implode(',',$sousEnsembleIdsTaxons));
86
				$url = $this->getUrlImagesTaxons(implode(',',$sousEnsembleIdsTaxons));
86
				$donnees = $this->chargerDonnees($url);
87
				$donnees = $this->chargerDonnees($url);
87
				$resultats = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
88
				$resultats = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
88
				$images += $resultats;
89
				$images += $resultats;
89
			}
90
			}
90
		} else {
91
		} else {
91
			$url = $this->getUrlImagesTaxons($idsTaxons);
92
			$url = $this->getUrlImagesTaxons($idsTaxons);
92
			$donnees = $this->chargerDonnees($url);
93
			$donnees = $this->chargerDonnees($url);
93
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
94
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
94
		}
95
		}
-
 
96
		return $this->formaterResultatImages($images);
-
 
97
	}
-
 
98
 
-
 
99
	public function getInfosPremiereImageParIdsNoms($idsNoms) {
-
 
100
		$url = $this->getUrlPremiereImageParIdsNoms($idsNoms);
-
 
101
		$donnees = $this->chargerDonnees($url);
-
 
102
		$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
-
 
103
		return $this->formaterResultatImages($images);
-
 
104
	}
-
 
105
 
-
 
106
	public function getInfosImagesGalerieMobile($nn) {
-
 
107
		$url = $this->getUrlImagesGalerieMobile($nn);
-
 
108
		$donnees = $this->chargerDonnees($url);
-
 
109
		$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
-
 
110
		$this->formaterResultatImagesDel($images);
95
		return $images;
111
		return $images;
96
	}
112
	}
97
	
113
 
98
	private function getUrlImagesParIdsNoms($idsNoms) {
114
	private function getUrlImagesParIdsNoms($idsNoms) {
99
		$tpl = Config::get('imagesResultatsDeterminationTpl');
115
		$tpl = $this->obtenirSqueletteSelonApi('imagesResultatsDetermination');
100
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
116
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
101
		$url = $this->formaterUrl($tpl, $params);
117
		$url = $this->formaterUrl($tpl, $params);
102
		return $url;
118
		return $url;
103
	}
119
	}
104
 
120
 
105
	public function getUrlPremiereImageParIdsNoms($idsNoms) {
121
	private function getUrlPremiereImageParIdsNoms($idsNoms) {
106
		$tpl = Config::get('imagesPremiereTpl');
122
		$tpl = $this->obtenirSqueletteSelonApi('imagesPremiere');
107
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
123
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
108
		$url = $this->formaterUrl($tpl, $params);
-
 
109
		$donnees = $this->chargerDonnees($url);
-
 
110
		$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
-
 
111
		return $images;
124
		return $this->formaterUrl($tpl, $params);
112
	}
125
	}
113
	
126
 
114
	private function getUrlImages() {
127
	private function getUrlImages($nn = false) {
-
 
128
		$tpl = $this->obtenirSqueletteSelonApi('images');
115
		$tpl = Config::get('imagesTpl');
129
		if ($this->getApi() == Eflore::API_EFLORE) {
-
 
130
			$params = array('projet' => $this->getProjet(), 'limite' => $this->limite, 'depart' => $this->depart, 'referentiel' => Registre::get('parametres.referentiel'));
116
		$params = array('projet' => $this->getProjet(), 'limite' => $this->limite, 'depart' => $this->depart, 'referentiel' => Registre::get('parametres.referentiel'));
131
		}
117
		$url = $this->formaterUrl($tpl, $params);
132
		$url = $this->formaterUrl($tpl, $params);
118
		return $url;
133
		return $url;
119
	}
134
	}
120
	
135
 
121
	private function getUrlImagesTaxons($idsTaxons) {
136
	private function getUrlImagesTaxons($idsTaxons) {
122
		$tpl = Config::get('imagesTaxonsTpl');
137
		$tpl = $this->obtenirSqueletteSelonApi('imagesTaxons');
123
		$params = array('projet' => $this->getProjet(),'nntaxon'=> $idsTaxons, 'referentiel' => Registre::get('parametres.referentiel'));
138
		$params = array('projet' => $this->getProjet(),'nntaxon'=> $idsTaxons, 'referentiel' => Registre::get('parametres.referentiel'));
124
		$url = $this->formaterUrl($tpl, $params);
139
		$url = $this->formaterUrl($tpl, $params);
125
		return $url;
140
		return $url;
126
	}
141
	}
-
 
142
 
-
 
143
	private function getUrlImagesGalerieMobile($nn) {
-
 
144
		$tpl = Config::get('delGalerieMobileTpl');
-
 
145
		$params = array('nn' => $nn);
-
 
146
		$url = $this->formaterUrl($tpl, $params);
-
 
147
		return $url;
-
 
148
	}
-
 
149
 
-
 
150
	/**
-
 
151
	 * Transforme les résultats issus des Webservices autres que eflore/cel afin de conserver un format homogène
-
 
152
	 * @param mixed $images
-
 
153
	 */
-
 
154
	private function formaterResultatImages($images, $seulementUne = false) {
-
 
155
		switch ($this->getApi()) {
-
 
156
			case Eflore::API_DEL:
-
 
157
				return $this->formaterResultatImagesDel($images, $seulementUne);
-
 
158
			break;
-
 
159
			default:
-
 
160
				return $images;
-
 
161
		}
-
 
162
	}
-
 
163
 
-
 
164
	private function formaterResultatImagesDel($images, $seulementUne = false) {
-
 
165
		if ($seulementUne) {
-
 
166
			return $this->formaterUnResultatImagesDel($images);
-
 
167
		} else {
-
 
168
			$retour = array();
-
 
169
			foreach ($images as $idObsImage => $image) {
-
 
170
				$retour[$image['id_image']] = array_merge($images[$idObsImage], $this->formaterUnResultatImagesDel($image));
-
 
171
			}
-
 
172
			return $retour;
-
 
173
		}
-
 
174
	}
-
 
175
 
-
 
176
	/**
-
 
177
	 * Convertit un array venant d'un Webservice del vers le format retourné par eflore/cel
-
 
178
	 * @param array $image
-
 
179
	 * @return array
-
 
180
	 */
-
 
181
	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'];
-
 
184
		$codeReferentiel = substr($image['observation']['determination.referentiel'], 0, strpos($image['observation']['determination.referentiel'], ':'));
-
 
185
		$localiteLibelle = array($image['observation']['zone_geo'],
-
 
186
				$image['observation']['lieudit'],
-
 
187
				$image['observation']['station'],
-
 
188
				$image['observation']['milieu']);
-
 
189
		$retourImage = array(
-
 
190
				'date' => $image['observation']['date_observation'],
-
 
191
				'mime' => 'image/jpeg',
-
 
192
				'auteur.libelle' => $libelleAuteur,
-
 
193
				'auteur.id' => $image['observation']['auteur.id'],
-
 
194
				'binaire.href' => $image['binaire.href'],
-
 
195
				'observation.id' => $image['observation']['id_observation'],
-
 
196
				'determination.libelle' => $image['observation']['determination.ns'].'[Dét. : '.$libelleAuteur.']',
-
 
197
				'determination.nom_sci' => $image['observation']['determination.ns'],
-
 
198
				'determination.nom_sci.code' => $codeReferentiel.'.'.$image['observation']['determination.nn'],
-
 
199
				'station.commune' => $image['observation']['zone_geo'],
-
 
200
				'station.lieudit' => $image['observation']['lieudit'],
-
 
201
				'station.station' => $image['observation']['station'],
-
 
202
				'station.milieu' => $image['observation']['milieu'],
-
 
203
				'station.libelle' => $this->formaterLocalite($localiteLibelle)
-
 
204
		);
-
 
205
		//echo "FORMAT CEL: <pre>"; print_r($retourImage); echo "</pre>";
-
 
206
		return $retourImage;
-
 
207
	}
-
 
208
	
-
 
209
	private function formaterLocalite($infosLocalite) {
-
 
210
		$localiteFmt = array();
-
 
211
		foreach ($infosLocalite as $localite) {
-
 
212
			if($localite != '') {
-
 
213
				$localiteFmt[] = $localite;
-
 
214
			}
-
 
215
		}
-
 
216
		if (empty($localiteFmt)) {
-
 
217
			$localiteFmt[0] = 'localité inconnue';
-
 
218
		}
-
 
219
		return implode(" > ", $localiteFmt);
-
 
220
	}
127
}
221
}
128
?>
222
?>