Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev Author Line No. Line
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();
1281 aurelien 43
 
1123 mathias 44
		$this->getPhotosCaracteresIdentification();
45
		$pso = $this->getPhotosSixOrganes();
1165 aurelien 46
 
1281 aurelien 47
		// Le framework n'avait pas prévu l'inclusion de sous squelettes dans les modules
48
		// en attendant, on utilise un chemin complet vers le fichier de squelette
49
		$chemin_sous_squelette = Config::get('chemin_modules').AppControleur::getNomDossierDepuisClasse('Fiche').DS.Config::get('dossier_squelettes').DS;
50
		$params = array('organes' => $pso, 'referentiel' => $this->referentiel,
51
						'nnr' => $this->donnees['nnr'],
52
						'nomComplet' => $this->donnees['nomComplet']);
53
		$this->donnees['illustrationsOrganes'] = $this->getVue($chemin_sous_squelette.'fiche_illustrations_organes.tpl.html',$params);
1335 mathias 54
		$this->donnees['organes'] = $pso;
1281 aurelien 55
 
1146 mathias 56
		// chemins
1273 aurelien 57
		$this->donnees['base_url_widget_saisie'] = Config::get('base_url_widget_saisie');
1335 mathias 58
		$this->donnees['base_url_pictoflora'] = Config::get('base_url_pictoflora');
955 delphine 59
		return $this->donnees;
238 delphine 60
	}
697 mathilde 61
 
62
	public function obtenirDonneesExport() {
955 delphine 63
		$this->donnees['nt'] = $this->nomCourant->getNt();
64
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
65
		$this->donnees['cel'] = $this->getCelExport();
1357 mathias 66
		if ($this->referentiel == 'bdtfx') {
67
			$this->donnees['coste'] = $this->getCoste();
68
		}
955 delphine 69
		return $this->donnees;
697 mathilde 70
	}
291 jpm 71
 
72
	public function getBloc() {
1136 mathias 73
		$this->donnees = $this->images->getInfosMeilleureImageParPrioriteTags($nnr = $this->nomCourant->getNnr(), array(
74
				'fleur', 'feuille', 'fruit', 'ecorce', 'port', 'rameau'));
955 delphine 75
		if (empty($this->donnees)) {
1137 mathias 76
			$this->donnees = $this->getPhoto('cel');
77
			if (empty($this->donnees)) {
78
				$infos_image = $this->getDessin();
79
				if (empty($infos_image) == false ) {
80
					$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
81
				}
631 mathilde 82
			}
1136 mathias 83
		} else {
84
			// extraction de l'url
85
			$this->donnees = array('imageUrl' => $this->donnees['binaire.href']);
631 mathilde 86
		}
1403 mathias 87
		// Photoflora (alias Copyrightflora alias Egoflora) n'est dispo que pour BDTFX
88
		if (empty($this->donnees) && $this->referentiel == "bdtfx") {
955 delphine 89
			$this->donnees = $this->getPhoto('photoflora');
631 mathilde 90
		}
955 delphine 91
		return $this->donnees;
631 mathilde 92
	}
93
 
1381 aurelien 94
	public function obtenirPhotoCelTpl() {
95
		$images = $this->initialiserPhotos('cel');
96
		$this->formaterListePhotos('cel', $images);
97
		$this->formaterMetaPhotos('cel');
98
		$chemin_sous_squelette = Config::get('chemin_modules').AppControleur::getNomDossierDepuisClasse('Fiche').DS.Config::get('dossier_squelettes').DS;
99
		$donnees = array('cel' => array('images' => $this->donnees['cel']['images'], 'meta' => $this->donnees['cel']['meta'] ));
100
		$html_tpl = $this->getVue($chemin_sous_squelette.'fiche_illustrations_cel.tpl.html', $donnees);
101
		return $html_tpl;
102
	}
631 mathilde 103
 
1382 aurelien 104
	//TODO: factoriser les deux fonctions ci dessous et ci dessus
105
	public function obtenirTranchesCelTpl($projet) {
1383 aurelien 106
		// On ne prend que la tranche des images (12)
1382 aurelien 107
		$images = $this->initialiserTranchePhotos($projet);
108
		$this->formaterListePhotos($projet, $images);
109
		$this->formaterMetaPhotos($projet);
110
		$chemin_sous_squelette = Config::get('chemin_modules').AppControleur::getNomDossierDepuisClasse('Fiche').DS.Config::get('dossier_squelettes').DS;
111
		$donnees = array('cel' => array('images' => $this->donnees['cel']['images'], 'meta' => $this->donnees[$projet]['meta'] ));
112
		$html_tpl = $this->getVue($chemin_sous_squelette.'fiche_illustrations_cel.tpl.html', $donnees);
1398 aurelien 113
		$this->donnees[$projet]['illustrationsCel'] = $html_tpl;
114
		$this->donnees[$projet]['cel_present'] = count($images) > 0;
1382 aurelien 115
		// Ensuite on fait juste un lien qui permettra de les charger
116
		$this->donnees[$projet]['ajax_url'] = $this->formaterUrlAjaxPhotoCel();
117
	}
118
 
631 mathilde 119
	public function getPhoto($source) {
120
		$donnees = array();
121
		$this->images->setProjet($source);
448 delphine 122
		$nnr = $this->nomCourant->getNnr();
1115 mathias 123
		$infos_image = $this->images->setApi(Eflore::API_EFLORE)->getInfosPremiereImageParIdsNoms(array($nnr));
801 delphine 124
		if ($infos_image != array()) {
125
			$image = array_shift($infos_image);
631 mathilde 126
			$donnees['imageUrl'] =  $image['binaire.href'];
470 aurelien 127
		}
291 jpm 128
		return $donnees;
129
	}
478 jpm 130
 
1014 raphael 131
	public function getCoste() {
132
		$coste = array();
133
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
134
		$this->images->setProjet('coste');
135
		$this->images->setNnTaxon($tax);
1115 mathias 136
		$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
1014 raphael 137
		foreach ($costeImg as $infos) {
138
			$coste['images'][] = $infos['binaire.href'];
139
		}
140
		$this->meta->setProjet('coste');
141
		$meta = $this->meta->getMetaDonnees();
1130 aurelien 142
		$coste['meta'] = $meta[0];
1014 raphael 143
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
144
		return $coste;
145
	}
146
 
955 delphine 147
	public function getDessin() {
148
		$projet = Config::get($this->referentiel.'.baseDessins');
149
		if ($projet != "") {
150
			$dessin = array();
151
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
152
			$this->images->setProjet($projet);
153
			$this->images->setNnTaxon($tax);
1115 mathias 154
			$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
955 delphine 155
				foreach ($costeImg as $infos) {
156
					$dessin['images'][] = $infos['binaire.href'];
157
				}
1251 aurelien 158
			$this->meta->setProjet($projet);
955 delphine 159
			$meta = $this->meta->getMetaDonnees();
1130 aurelien 160
			$dessin['meta'] = $meta[0];
955 delphine 161
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
1251 aurelien 162
			$this->donnees[$projet] = $dessin;
955 delphine 163
		}
164
	}
165
 
166
	public function getPhotos() {
167
		$projets[] = Config::get($this->referentiel.'.baseImages');
168
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
169
		foreach ($projets as $projet) {
170
			if ($projet != "") {
1115 mathias 171
				if ($projet == "cel") {
1382 aurelien 172
					// Chargement des 10 premieres images + un lien pour en afficher plus
173
					$this->obtenirTranchesCelTpl($projet);
1115 mathias 174
				} else {
175
					$this->images->setApi(Eflore::API_EFLORE);
1381 aurelien 176
					$images = $this->initialiserPhotos($projet);
177
					$this->formaterListePhotos($projet, $images);
178
					$this->formaterMetaPhotos($projet);
1115 mathias 179
				}
621 mathilde 180
			}
955 delphine 181
		}
621 mathilde 182
	}
1123 mathias 183
 
1381 aurelien 184
	private function formaterUrlAjaxPhotoCel() {
185
		$infos = array('referentiel' => $this->referentiel,
186
						'module' => 'fiche',
187
						'action' => 'templateAjax',
188
						'sous_action' => 'photoCelTpl',
189
						'num_nom' => $this->nomCourant->getNnr(),
190
						'onglet' => 'illustrations');
191
		return Config::get('base_url_application_onglets').'?'.http_build_query($infos);
192
	}
193
 
1123 mathias 194
	public function getPhotosSixOrganes() {
1165 aurelien 195
		$organes = $this->getOrganes();
1123 mathias 196
		$nnr = $this->nomCourant->getNnr();
197
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 6, 'CRX2S');
1303 aurelien 198
 
1123 mathias 199
		$vide = true;
200
		foreach ($infosOrganes as $tag => $organe) {
1349 mathias 201
			foreach ($organe as $id_image => &$image) {
202
				$image['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($image['observation']['id_observation']);
203
			}
1123 mathias 204
			$organes[$tag] = $organe;
205
			$nbImages = count($organe);
206
			if ($nbImages != 0) {
207
				$vide = false;
208
				for ($i = 6; $i > $nbImages; $i--) {
209
					$organes[$tag][] = null;
210
				}
211
			}
212
		}
213
		if ($vide) {
214
			$organes = array();
215
		}
1303 aurelien 216
 
1123 mathias 217
		return $organes;
218
	}
219
 
220
	public function getPhotosOrganes() {
1165 aurelien 221
		$organes = $this->getOrganes();
1123 mathias 222
		$nnr = $this->nomCourant->getNnr();
223
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 1);
224
		$vide = true;
225
		foreach ($infosOrganes as $tag => $organe) {
226
			$nbImages = count($organe);
227
			// une image par organe seulement
228
			$organes[$tag] = array_pop($organe);
229
			if ($nbImages != 0) {
230
				$vide = false;
231
			}
232
		}
233
		if ($vide) {
234
			$organes = array();
235
		}
236
		$this->donnees['organes'] = $organes;
237
	}
238
 
239
	public function getPhotosCaracteresIdentification() {
240
		$caracteres = array();
241
		$nnr = $this->nomCourant->getNnr();
1166 mathias 242
		// pas de tag: on cherche les mieux votées pour ce protocole sans tenir compte des tags
243
		$infosCaracteres = $this->images->getInfosMeilleuresImagesParTag($nnr, '', Eflore::PROTOCOLE_CARACTERES, 3);
1123 mathias 244
		if (! empty($infosCaracteres) && ! empty($infosCaracteres[''])) { // le tag est vide, ici
1166 mathias 245
			$caracteres = $infosCaracteres[''];
1123 mathias 246
		}
1337 aurelien 247
		foreach($caracteres as $id_image => &$caractere) {
248
			$caractere['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($id_image);
249
			$caractere['urlImgGrandFormat'] = $this->obtenirUrlImageGrandFormatCel($id_image);
250
			$caractere['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($caractere['auteur.id'], $id_image);
251
			$caractere['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($caractere['auteur.id']);
252
			$caractere['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($caractere['observation']['id_observation']);
253
		}
1123 mathias 254
		$this->donnees['caracteres'] = $caracteres;
255
	}
1165 aurelien 256
 
257
	private function getOrganes() {
258
		return array(
259
				'fleur' => array(),
260
				'feuille' => array(),
261
				'fruit' => array(),
262
				'ecorce' => array(),
263
				'port' => array(),
264
				'rameau' => array());
265
	}
1088 raphael 266
 
267
	// XXX: webservice:
268
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
955 delphine 269
	private function initialiserPhotos($projet) {
270
		$this->images->setProjet($projet);
448 delphine 271
		$nnr = $this->nomCourant->getNnr();
1123 mathias 272
		$ret = $this->images->getInfosImagesParIdsNoms(array($nnr));
273
		return $ret;
955 delphine 274
	}
1382 aurelien 275
 
276
	private function initialiserTranchePhotos($projet) {
277
		$this->images->setProjet($projet);
278
		$nnr = $this->nomCourant->getNnr();
1383 aurelien 279
		$ret = $this->images->getInfosTrancheImagesParIdsNoms(array($nnr), Config::get('nbTrancheImagesResultatsDeterminationAffichees'));
1382 aurelien 280
		return $ret;
281
	}
955 delphine 282
 
283
	private function formaterListePhotos($projet, $images) {
284
		foreach ($images as $idImg => $img) {
285
			$infosImg = array();
286
			$infosImg['src'] = $img['binaire.href'];
287
			$infosImg['nomSci'] = $img['determination.nom_sci'];
288
			$infosImg['station'] = $img['station.libelle'];
289
			$infosImg['date'] = $this->formaterDateImg($img['date']);
290
			$infosImg['auteur'] = $img['auteur.libelle'];
1135 mathias 291
			$infosImg['auteur.id'] = $img['auteur.id'];
955 delphine 292
			if ($projet == "cel") {
293
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
1303 aurelien 294
				$infosImg['urlImgGrandFormat'] = $this->obtenirUrlImageGrandFormatCel($idImg);
955 delphine 295
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
1114 aurelien 296
				$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
297
				$infosImg['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
955 delphine 298
			}
299
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
515 jpm 300
		}
955 delphine 301
	}
302
 
1311 aurelien 303
	public static function obtenirUrlImageGrandFormatCel($id, $format = "O") {
1303 aurelien 304
		$tpl = Config::get('baseUrlImageCelTpl');
305
		return sprintf($tpl, str_pad($id, 9, '0', STR_PAD_LEFT).$format.'.jpg');
306
	}
307
 
308
	// XXX: public static pour être injecté dans le squelette d'entete
1311 aurelien 309
	public static function obtenirTemplateUrlImageGrandFormatOrganes($format = "O") {
1303 aurelien 310
		return $tpl = sprintf(Config::get('baseUrlImageCelTpl').$format.'.jpg', '{id_image}');
311
	}
312
 
955 delphine 313
	private function formaterMetaPhotos($projet) {
314
		$this->meta->setProjet($projet);
339 aurelien 315
		$meta = $this->meta->getMetaDonnees();
1130 aurelien 316
		$titreMeta = $meta[0];
317
		$this->donnees[$projet]['meta'] = $titreMeta;
955 delphine 318
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
339 aurelien 319
	}
697 mathilde 320
 
955 delphine 321
 
322
 
697 mathilde 323
	public function getCelExport() {
324
		$cel = array();
325
		$this->images->setProjet('cel');
326
		$nnr = $this->nomCourant->getNnr();
327
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
328
		if($img) {
329
			$img = array_values($img);
330
			$cel['images']['src'] = $img[0]['binaire.href'];
331
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
978 aurelien 332
			$cel['images']['station'] = $img[0]['station.libelle'];
697 mathilde 333
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
334
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
335
			$this->meta->setProjet('cel');
336
			$meta = $this->meta->getMetaDonnees();
1130 aurelien 337
			$cel['meta'] = $meta[0];
697 mathilde 338
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
339
		}
340
		return $cel;
341
	}
342
 
497 jpm 343
	private function formaterDateImg($date) {
344
		$dateFmt = $date;
1326 mathias 345
		if ($date == '' || $date == null || strpos($date, '0000-00-00') !== false || $date == '1970-01-01 01:01:01') {
1019 raphael 346
			return 'inconnue';
497 jpm 347
		}
1019 raphael 348
		$time = strtotime($date);
349
		if(!$time) {
350
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
351
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
352
			   si FALSE pour avant 1901: problème php
353
			   On retourne alors simplement l'année.
354
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
355
			$dateFmt = explode('-', $date);
356
			return $dateFmt[0];
357
		}
358
		return strftime('%e %B %Y', strtotime($date));
497 jpm 359
	}
360
 
955 delphine 361
	private function formaterNomSci($nom) {
362
		$nomFmt = $nom;
363
		if (is_null($nom) || $nom == '') {
364
			$nomFmt = 'inconnu';
365
		}
366
		return $nomFmt;
497 jpm 367
	}
238 delphine 368
}
369
?>