238 |
delphine |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe mère du module Liste.
|
|
|
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 Illustrations extends aControleur {
|
291 |
jpm |
16 |
|
|
|
17 |
private $conteneur = null;
|
294 |
delphine |
18 |
private $nomCourant = null;
|
291 |
jpm |
19 |
private $images = null;
|
478 |
jpm |
20 |
private $appUrls = null;
|
|
|
21 |
private $meta = null;
|
955 |
delphine |
22 |
private $referentiel = 'bdtfx';
|
|
|
23 |
private $donnees = array();
|
291 |
jpm |
24 |
|
|
|
25 |
public function __construct(Conteneur $conteneur) {
|
|
|
26 |
$this->conteneur = $conteneur;
|
294 |
delphine |
27 |
$this->nomCourant = $this->conteneur->getNomCourant();
|
955 |
delphine |
28 |
$this->referentiel = $this->conteneur->getParametre('referentiel');
|
291 |
jpm |
29 |
$this->images = $this->conteneur->getApiImages();
|
|
|
30 |
$this->appUrls = $this->conteneur->getAppUrls();
|
320 |
aurelien |
31 |
$this->meta = $this->conteneur->getApiMetaDonnees();
|
238 |
delphine |
32 |
}
|
291 |
jpm |
33 |
|
|
|
34 |
public function obtenirDonnees() {
|
955 |
delphine |
35 |
$this->donnees['nt'] = $this->nomCourant->getNt();
|
1123 |
mathias |
36 |
$this->donnees['nnr'] = $this->nomCourant->getNnr();
|
1181 |
aurelien |
37 |
$this->donnees['referentiel'] = $this->referentiel;
|
955 |
delphine |
38 |
$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
|
1123 |
mathias |
39 |
$infosNomRetenu = $this->nomCourant->getNomRetenu()->getInfos();
|
|
|
40 |
$this->donnees['nomComplet'] = $infosNomRetenu['nom_complet'];
|
955 |
delphine |
41 |
$this->getPhotos();
|
|
|
42 |
$this->getDessin();
|
1156 |
mathias |
43 |
//$this->getPhotosOrganes();
|
1123 |
mathias |
44 |
$this->getPhotosCaracteresIdentification();
|
|
|
45 |
$pso = $this->getPhotosSixOrganes();
|
1156 |
mathias |
46 |
// reconstruction de getPhotosOrganes à partir des données de getPhotosSixOrganes
|
1171 |
mathias |
47 |
/*$this->donnees['organes'] = array();
|
1156 |
mathias |
48 |
foreach ($pso as $organe => $images) {
|
|
|
49 |
$clefs = array_keys($images);
|
|
|
50 |
$image = $images[$clefs[0]];
|
|
|
51 |
// changement de format - en dur, cracra !
|
|
|
52 |
$image['binaire.href'] = str_replace('CRX2S', 'CRS', $image['binaire.href']);
|
|
|
53 |
$this->donnees['organes'][$organe] = $image;
|
1171 |
mathias |
54 |
}*/
|
1156 |
mathias |
55 |
// --
|
1123 |
mathias |
56 |
$this->setCheminSquelette('modules/fiche/squelettes/'); // @FIXME le chemin devrait déjà être défini correctement !?
|
1181 |
aurelien |
57 |
$params = array('organes' => $pso, 'referentiel' => $this->referentiel, 'nnr' => $this->donnees['nnr'], 'nomComplet' => $this->donnees['nomComplet']);
|
1165 |
aurelien |
58 |
$this->donnees['illustrationsOrganes'] = $this->getVue('fiche_illustrations_organes',$params);
|
|
|
59 |
|
1146 |
mathias |
60 |
// chemins
|
|
|
61 |
$this->donnees['base_url_widget'] = Config::get('base_url_widget');
|
|
|
62 |
$this->donnees['base_url_del'] = Config::get('base_url_del');
|
955 |
delphine |
63 |
return $this->donnees;
|
238 |
delphine |
64 |
}
|
697 |
mathilde |
65 |
|
|
|
66 |
public function obtenirDonneesExport() {
|
955 |
delphine |
67 |
$this->donnees['nt'] = $this->nomCourant->getNt();
|
|
|
68 |
$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
|
|
|
69 |
$this->donnees['cel'] = $this->getCelExport();
|
1014 |
raphael |
70 |
$this->donnees['coste'] = $this->getCoste();
|
955 |
delphine |
71 |
return $this->donnees;
|
697 |
mathilde |
72 |
}
|
291 |
jpm |
73 |
|
|
|
74 |
public function getBloc() {
|
1136 |
mathias |
75 |
$this->donnees = $this->images->getInfosMeilleureImageParPrioriteTags($nnr = $this->nomCourant->getNnr(), array(
|
|
|
76 |
'fleur', 'feuille', 'fruit', 'ecorce', 'port', 'rameau'));
|
955 |
delphine |
77 |
if (empty($this->donnees)) {
|
1137 |
mathias |
78 |
$this->donnees = $this->getPhoto('cel');
|
|
|
79 |
if (empty($this->donnees)) {
|
|
|
80 |
$infos_image = $this->getDessin();
|
|
|
81 |
if (empty($infos_image) == false ) {
|
|
|
82 |
$this->donnees['imageUrl'] = array_shift($infos_image['images']);
|
|
|
83 |
}
|
631 |
mathilde |
84 |
}
|
1136 |
mathias |
85 |
} else {
|
|
|
86 |
// extraction de l'url
|
|
|
87 |
$this->donnees = array('imageUrl' => $this->donnees['binaire.href']);
|
631 |
mathilde |
88 |
}
|
955 |
delphine |
89 |
if (empty($this->donnees)) {
|
|
|
90 |
$this->donnees = $this->getPhoto('photoflora');
|
631 |
mathilde |
91 |
}
|
955 |
delphine |
92 |
return $this->donnees;
|
631 |
mathilde |
93 |
}
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
public function getPhoto($source) {
|
|
|
97 |
$donnees = array();
|
|
|
98 |
$this->images->setProjet($source);
|
448 |
delphine |
99 |
$nnr = $this->nomCourant->getNnr();
|
1115 |
mathias |
100 |
$infos_image = $this->images->setApi(Eflore::API_EFLORE)->getInfosPremiereImageParIdsNoms(array($nnr));
|
801 |
delphine |
101 |
if ($infos_image != array()) {
|
|
|
102 |
$image = array_shift($infos_image);
|
631 |
mathilde |
103 |
$donnees['imageUrl'] = $image['binaire.href'];
|
470 |
aurelien |
104 |
}
|
291 |
jpm |
105 |
return $donnees;
|
|
|
106 |
}
|
478 |
jpm |
107 |
|
1014 |
raphael |
108 |
public function getCoste() {
|
|
|
109 |
$coste = array();
|
|
|
110 |
$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
|
|
|
111 |
$this->images->setProjet('coste');
|
|
|
112 |
$this->images->setNnTaxon($tax);
|
1115 |
mathias |
113 |
$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
|
1014 |
raphael |
114 |
foreach ($costeImg as $infos) {
|
|
|
115 |
$coste['images'][] = $infos['binaire.href'];
|
|
|
116 |
}
|
|
|
117 |
$this->meta->setProjet('coste');
|
|
|
118 |
$meta = $this->meta->getMetaDonnees();
|
1130 |
aurelien |
119 |
$coste['meta'] = $meta[0];
|
1014 |
raphael |
120 |
$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
|
|
|
121 |
return $coste;
|
|
|
122 |
}
|
|
|
123 |
|
955 |
delphine |
124 |
public function getDessin() {
|
|
|
125 |
$projet = Config::get($this->referentiel.'.baseDessins');
|
|
|
126 |
if ($projet != "") {
|
|
|
127 |
$dessin = array();
|
|
|
128 |
$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
|
|
|
129 |
$this->images->setProjet($projet);
|
|
|
130 |
$this->images->setNnTaxon($tax);
|
1115 |
mathias |
131 |
$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
|
955 |
delphine |
132 |
foreach ($costeImg as $infos) {
|
|
|
133 |
$dessin['images'][] = $infos['binaire.href'];
|
|
|
134 |
}
|
|
|
135 |
$this->meta->setProjet('coste');
|
|
|
136 |
$meta = $this->meta->getMetaDonnees();
|
1130 |
aurelien |
137 |
$dessin['meta'] = $meta[0];
|
955 |
delphine |
138 |
$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
|
|
|
139 |
$this->donnees['coste'] = $dessin;
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public function getPhotos() {
|
|
|
144 |
$projets[] = Config::get($this->referentiel.'.baseImages');
|
|
|
145 |
$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
|
|
|
146 |
foreach ($projets as $projet) {
|
|
|
147 |
if ($projet != "") {
|
1115 |
mathias |
148 |
if ($projet == "cel") {
|
|
|
149 |
$this->images->setApi(Eflore::API_EFLORE); // prêt à passer à API_DEL
|
|
|
150 |
} else {
|
|
|
151 |
$this->images->setApi(Eflore::API_EFLORE);
|
|
|
152 |
}
|
955 |
delphine |
153 |
$images = $this->initialiserPhotos($projet);
|
|
|
154 |
$this->formaterListePhotos($projet, $images);
|
|
|
155 |
$this->formaterMetaPhotos($projet);
|
621 |
mathilde |
156 |
}
|
955 |
delphine |
157 |
}
|
621 |
mathilde |
158 |
}
|
1123 |
mathias |
159 |
|
|
|
160 |
public function getPhotosSixOrganes() {
|
1165 |
aurelien |
161 |
$organes = $this->getOrganes();
|
1123 |
mathias |
162 |
$nnr = $this->nomCourant->getNnr();
|
|
|
163 |
$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 6, 'CRX2S');
|
|
|
164 |
$vide = true;
|
|
|
165 |
foreach ($infosOrganes as $tag => $organe) {
|
|
|
166 |
$organes[$tag] = $organe;
|
|
|
167 |
$nbImages = count($organe);
|
|
|
168 |
if ($nbImages != 0) {
|
|
|
169 |
$vide = false;
|
|
|
170 |
for ($i = 6; $i > $nbImages; $i--) {
|
|
|
171 |
$organes[$tag][] = null;
|
|
|
172 |
}
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
if ($vide) {
|
|
|
176 |
$organes = array();
|
|
|
177 |
}
|
|
|
178 |
return $organes;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
public function getPhotosOrganes() {
|
1165 |
aurelien |
182 |
$organes = $this->getOrganes();
|
1123 |
mathias |
183 |
$nnr = $this->nomCourant->getNnr();
|
|
|
184 |
$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 1);
|
|
|
185 |
$vide = true;
|
|
|
186 |
foreach ($infosOrganes as $tag => $organe) {
|
|
|
187 |
$nbImages = count($organe);
|
|
|
188 |
// une image par organe seulement
|
|
|
189 |
$organes[$tag] = array_pop($organe);
|
|
|
190 |
if ($nbImages != 0) {
|
|
|
191 |
$vide = false;
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
if ($vide) {
|
|
|
195 |
$organes = array();
|
|
|
196 |
}
|
|
|
197 |
$this->donnees['organes'] = $organes;
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
public function getPhotosCaracteresIdentification() {
|
|
|
201 |
$caracteres = array();
|
|
|
202 |
$nnr = $this->nomCourant->getNnr();
|
1166 |
mathias |
203 |
// pas de tag: on cherche les mieux votées pour ce protocole sans tenir compte des tags
|
|
|
204 |
$infosCaracteres = $this->images->getInfosMeilleuresImagesParTag($nnr, '', Eflore::PROTOCOLE_CARACTERES, 3);
|
1123 |
mathias |
205 |
if (! empty($infosCaracteres) && ! empty($infosCaracteres[''])) { // le tag est vide, ici
|
1166 |
mathias |
206 |
$caracteres = $infosCaracteres[''];
|
1123 |
mathias |
207 |
}
|
|
|
208 |
$this->donnees['caracteres'] = $caracteres;
|
|
|
209 |
}
|
1165 |
aurelien |
210 |
|
|
|
211 |
private function getOrganes() {
|
|
|
212 |
return array(
|
|
|
213 |
'fleur' => array(),
|
|
|
214 |
'feuille' => array(),
|
|
|
215 |
'fruit' => array(),
|
|
|
216 |
'ecorce' => array(),
|
|
|
217 |
'port' => array(),
|
|
|
218 |
'rameau' => array());
|
|
|
219 |
}
|
1088 |
raphael |
220 |
|
|
|
221 |
// XXX: webservice:
|
|
|
222 |
// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
|
955 |
delphine |
223 |
private function initialiserPhotos($projet) {
|
|
|
224 |
$this->images->setProjet($projet);
|
448 |
delphine |
225 |
$nnr = $this->nomCourant->getNnr();
|
1123 |
mathias |
226 |
$ret = $this->images->getInfosImagesParIdsNoms(array($nnr));
|
|
|
227 |
return $ret;
|
955 |
delphine |
228 |
}
|
|
|
229 |
|
|
|
230 |
private function formaterListePhotos($projet, $images) {
|
|
|
231 |
foreach ($images as $idImg => $img) {
|
|
|
232 |
$infosImg = array();
|
|
|
233 |
$infosImg['src'] = $img['binaire.href'];
|
|
|
234 |
$infosImg['nomSci'] = $img['determination.nom_sci'];
|
|
|
235 |
$infosImg['station'] = $img['station.libelle'];
|
|
|
236 |
$infosImg['date'] = $this->formaterDateImg($img['date']);
|
|
|
237 |
$infosImg['auteur'] = $img['auteur.libelle'];
|
1135 |
mathias |
238 |
$infosImg['auteur.id'] = $img['auteur.id'];
|
955 |
delphine |
239 |
if ($projet == "cel") {
|
|
|
240 |
$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
|
|
|
241 |
$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
|
1114 |
aurelien |
242 |
$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
|
|
|
243 |
$infosImg['urlMauvaiseIdentification'] = $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
|
955 |
delphine |
244 |
}
|
|
|
245 |
$this->donnees[$projet]['images'][$idImg] = $infosImg;
|
515 |
jpm |
246 |
}
|
955 |
delphine |
247 |
}
|
|
|
248 |
|
|
|
249 |
private function formaterMetaPhotos($projet) {
|
|
|
250 |
$this->meta->setProjet($projet);
|
339 |
aurelien |
251 |
$meta = $this->meta->getMetaDonnees();
|
1130 |
aurelien |
252 |
$titreMeta = $meta[0];
|
|
|
253 |
$this->donnees[$projet]['meta'] = $titreMeta;
|
955 |
delphine |
254 |
$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
|
339 |
aurelien |
255 |
}
|
697 |
mathilde |
256 |
|
955 |
delphine |
257 |
|
|
|
258 |
|
697 |
mathilde |
259 |
public function getCelExport() {
|
|
|
260 |
$cel = array();
|
|
|
261 |
$this->images->setProjet('cel');
|
|
|
262 |
$nnr = $this->nomCourant->getNnr();
|
|
|
263 |
$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
|
|
|
264 |
if($img) {
|
|
|
265 |
$img = array_values($img);
|
|
|
266 |
$cel['images']['src'] = $img[0]['binaire.href'];
|
|
|
267 |
$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
|
978 |
aurelien |
268 |
$cel['images']['station'] = $img[0]['station.libelle'];
|
697 |
mathilde |
269 |
$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
|
|
|
270 |
$cel['images']['auteur'] = $img[0]['auteur.libelle'];
|
|
|
271 |
$this->meta->setProjet('cel');
|
|
|
272 |
$meta = $this->meta->getMetaDonnees();
|
1130 |
aurelien |
273 |
$cel['meta'] = $meta[0];
|
697 |
mathilde |
274 |
$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
|
|
|
275 |
}
|
|
|
276 |
return $cel;
|
|
|
277 |
}
|
|
|
278 |
|
497 |
jpm |
279 |
private function formaterDateImg($date) {
|
|
|
280 |
$dateFmt = $date;
|
978 |
aurelien |
281 |
if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
|
1019 |
raphael |
282 |
return 'inconnue';
|
497 |
jpm |
283 |
}
|
1019 |
raphael |
284 |
$time = strtotime($date);
|
|
|
285 |
if(!$time) {
|
|
|
286 |
/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
|
|
|
287 |
TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
|
|
|
288 |
si FALSE pour avant 1901: problème php
|
|
|
289 |
On retourne alors simplement l'année.
|
|
|
290 |
si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
|
|
|
291 |
$dateFmt = explode('-', $date);
|
|
|
292 |
return $dateFmt[0];
|
|
|
293 |
}
|
|
|
294 |
return strftime('%e %B %Y', strtotime($date));
|
497 |
jpm |
295 |
}
|
|
|
296 |
|
955 |
delphine |
297 |
private function formaterNomSci($nom) {
|
|
|
298 |
$nomFmt = $nom;
|
|
|
299 |
if (is_null($nom) || $nom == '') {
|
|
|
300 |
$nomFmt = 'inconnu';
|
|
|
301 |
}
|
|
|
302 |
return $nomFmt;
|
497 |
jpm |
303 |
}
|
238 |
delphine |
304 |
}
|
|
|
305 |
?>
|