Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 947 | Rev 1116 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
130 jpm 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe gérant les images.
5
 *
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @copyright	2011 Tela-Botanica
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
13
 * @version		$Id$
14
 */
15
class Images extends Eflore {
624 mathilde 16
 
17
	private $nntaxon;
18
	private $limite;
19
	private $depart;
495 jpm 20
 
624 mathilde 21
	public function setNnTaxon($nntax) {
22
		$this->nntaxon = $nntax;
23
	}
24
 
25
	public function setLimite($limite) {
26
		$this->limite = $limite;
27
	}
28
 
29
	public function setDepart($depart) {
30
		$this->depart = $depart;
31
	}
32
 
339 aurelien 33
	//TODO: créer des fonctions spécifiques cel et photoflora pour plus de clarté ?
130 jpm 34
	public function getUrlsImagesParIdsNoms(Array $idsNoms) {
35
		$infosImages = $this->getInfosImagesParIdsNoms($idsNoms);
36
		$urls = array();
509 jpm 37
		if (count($infosImages) > 0) {
38
			foreach ($infosImages as $img) {
39
				$id = $img['determination.nom_sci.code'];
40
				$urls[$id][] = $img['binaire.href'];
41
			}
130 jpm 42
		}
43
		return $urls;
44
	}
45
 
46
	public function getInfosImagesParIdsNoms(Array $idsNoms) {
898 aurelien 47
		$pas = 800;
48
		if(count($idsNoms) >= $pas) {
49
			$images = array();
50
			$idsPartages = array_chunk($idsNoms, $pas);
51
			foreach ($idsPartages as $sousEnsembleIdsNoms) {
52
				$url = $this->getUrlImagesParIdsNoms($sousEnsembleIdsNoms);
53
				$donnees = $this->chargerDonnees($url);
54
				$resultats = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
55
				$images += $resultats;
56
			}
57
		} else {
58
			$url = $this->getUrlImagesParIdsNoms($idsNoms);
59
			$donnees = $this->chargerDonnees($url);
60
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
61
		}
1115 mathias 62
		return $this->formaterResultatImages($images);
130 jpm 63
	}
495 jpm 64
 
475 delphine 65
	public function getInfosImageParIdImage($id_image) {
1115 mathias 66
		$tpl = $this->obtenirSqueletteSelonApi('imagesPopup');
947 aurelien 67
		$url = $this->formaterUrl($tpl, array('id' => $id_image, 'referentiel' => Registre::get('parametres.referentiel')));
1115 mathias 68
		$image = $this->chargerDonnees($url);
69
		return $this->formaterResultatImages($image, true);
475 delphine 70
	}
624 mathilde 71
 
72
	public function getInfosImages() {
73
		$url = $this->getUrlImages();
1115 mathias 74
		$donnees = $this->chargerDonnees($url);
624 mathilde 75
		$images = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
1115 mathias 76
		return $this->formaterResultatImages($images);
624 mathilde 77
	}
898 aurelien 78
 
624 mathilde 79
	public function getInfosImagesTaxons() {
898 aurelien 80
		$pas = 800;
81
		$idsTaxons = explode(',', $this->nntaxon);
82
		if(count($idsTaxons) >= $pas) {
83
			$images = array();
84
			$idsPartages = array_chunk($idsTaxons, $pas);
85
			foreach ($idsPartages as $sousEnsembleIdsTaxons) {
86
				$url = $this->getUrlImagesTaxons(implode(',',$sousEnsembleIdsTaxons));
87
				$donnees = $this->chargerDonnees($url);
88
				$resultats = (empty($donnees['resultats']) == false) ? $donnees['resultats'] : array();
89
				$images += $resultats;
90
			}
91
		} else {
92
			$url = $this->getUrlImagesTaxons($idsTaxons);
93
			$donnees = $this->chargerDonnees($url);
94
			$images = (isset($donnees['resultats'])) ? $donnees['resultats'] : array();
95
		}
1115 mathias 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);
624 mathilde 111
		return $images;
112
	}
1115 mathias 113
 
130 jpm 114
	private function getUrlImagesParIdsNoms($idsNoms) {
1115 mathias 115
		$tpl = $this->obtenirSqueletteSelonApi('imagesResultatsDetermination');
947 aurelien 116
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
130 jpm 117
		$url = $this->formaterUrl($tpl, $params);
118
		return $url;
119
	}
495 jpm 120
 
1115 mathias 121
	private function getUrlPremiereImageParIdsNoms($idsNoms) {
122
		$tpl = $this->obtenirSqueletteSelonApi('imagesPremiere');
947 aurelien 123
		$params = array('idsNoms' => implode(',', $idsNoms), 'referentiel' => Registre::get('parametres.referentiel'));
1115 mathias 124
		return $this->formaterUrl($tpl, $params);
414 delphine 125
	}
1115 mathias 126
 
127
	private function getUrlImages($nn = false) {
128
		$tpl = $this->obtenirSqueletteSelonApi('images');
129
		if ($this->getApi() == Eflore::API_EFLORE) {
130
			$params = array('projet' => $this->getProjet(), 'limite' => $this->limite, 'depart' => $this->depart, 'referentiel' => Registre::get('parametres.referentiel'));
131
		}
624 mathilde 132
		$url = $this->formaterUrl($tpl, $params);
133
		return $url;
134
	}
1115 mathias 135
 
898 aurelien 136
	private function getUrlImagesTaxons($idsTaxons) {
1115 mathias 137
		$tpl = $this->obtenirSqueletteSelonApi('imagesTaxons');
947 aurelien 138
		$params = array('projet' => $this->getProjet(),'nntaxon'=> $idsTaxons, 'referentiel' => Registre::get('parametres.referentiel'));
624 mathilde 139
		$url = $this->formaterUrl($tpl, $params);
140
		return $url;
141
	}
1115 mathias 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
	}
130 jpm 221
}
222
?>