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