Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1337 | Rev 1357 | 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();
1014 raphael 66
		$this->donnees['coste'] = $this->getCoste();
955 delphine 67
		return $this->donnees;
697 mathilde 68
	}
291 jpm 69
 
70
	public function getBloc() {
1136 mathias 71
		$this->donnees = $this->images->getInfosMeilleureImageParPrioriteTags($nnr = $this->nomCourant->getNnr(), array(
72
				'fleur', 'feuille', 'fruit', 'ecorce', 'port', 'rameau'));
955 delphine 73
		if (empty($this->donnees)) {
1137 mathias 74
			$this->donnees = $this->getPhoto('cel');
75
			if (empty($this->donnees)) {
76
				$infos_image = $this->getDessin();
77
				if (empty($infos_image) == false ) {
78
					$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
79
				}
631 mathilde 80
			}
1136 mathias 81
		} else {
82
			// extraction de l'url
83
			$this->donnees = array('imageUrl' => $this->donnees['binaire.href']);
631 mathilde 84
		}
955 delphine 85
		if (empty($this->donnees)) {
86
			$this->donnees = $this->getPhoto('photoflora');
631 mathilde 87
		}
955 delphine 88
		return $this->donnees;
631 mathilde 89
	}
90
 
91
 
92
	public function getPhoto($source) {
93
		$donnees = array();
94
		$this->images->setProjet($source);
448 delphine 95
		$nnr = $this->nomCourant->getNnr();
1115 mathias 96
		$infos_image = $this->images->setApi(Eflore::API_EFLORE)->getInfosPremiereImageParIdsNoms(array($nnr));
801 delphine 97
		if ($infos_image != array()) {
98
			$image = array_shift($infos_image);
631 mathilde 99
			$donnees['imageUrl'] =  $image['binaire.href'];
470 aurelien 100
		}
291 jpm 101
		return $donnees;
102
	}
478 jpm 103
 
1014 raphael 104
	public function getCoste() {
105
		$coste = array();
106
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
107
		$this->images->setProjet('coste');
108
		$this->images->setNnTaxon($tax);
1115 mathias 109
		$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
1014 raphael 110
		foreach ($costeImg as $infos) {
111
			$coste['images'][] = $infos['binaire.href'];
112
		}
113
		$this->meta->setProjet('coste');
114
		$meta = $this->meta->getMetaDonnees();
1130 aurelien 115
		$coste['meta'] = $meta[0];
1014 raphael 116
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
117
		return $coste;
118
	}
119
 
955 delphine 120
	public function getDessin() {
121
		$projet = Config::get($this->referentiel.'.baseDessins');
122
		if ($projet != "") {
123
			$dessin = array();
124
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
125
			$this->images->setProjet($projet);
126
			$this->images->setNnTaxon($tax);
1115 mathias 127
			$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
955 delphine 128
				foreach ($costeImg as $infos) {
129
					$dessin['images'][] = $infos['binaire.href'];
130
				}
1251 aurelien 131
			$this->meta->setProjet($projet);
955 delphine 132
			$meta = $this->meta->getMetaDonnees();
1130 aurelien 133
			$dessin['meta'] = $meta[0];
955 delphine 134
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
1251 aurelien 135
			$this->donnees[$projet] = $dessin;
955 delphine 136
		}
137
	}
138
 
139
	public function getPhotos() {
140
		$projets[] = Config::get($this->referentiel.'.baseImages');
141
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
142
		foreach ($projets as $projet) {
143
			if ($projet != "") {
1115 mathias 144
				if ($projet == "cel") {
145
					$this->images->setApi(Eflore::API_EFLORE); // prêt à passer à API_DEL
146
				} else {
147
					$this->images->setApi(Eflore::API_EFLORE);
148
				}
955 delphine 149
				$images = $this->initialiserPhotos($projet);
150
				$this->formaterListePhotos($projet, $images);
151
				$this->formaterMetaPhotos($projet);
621 mathilde 152
			}
955 delphine 153
		}
621 mathilde 154
	}
1123 mathias 155
 
156
	public function getPhotosSixOrganes() {
1165 aurelien 157
		$organes = $this->getOrganes();
1123 mathias 158
		$nnr = $this->nomCourant->getNnr();
159
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 6, 'CRX2S');
1303 aurelien 160
 
1123 mathias 161
		$vide = true;
162
		foreach ($infosOrganes as $tag => $organe) {
1349 mathias 163
			foreach ($organe as $id_image => &$image) {
164
				$image['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($image['observation']['id_observation']);
165
			}
1123 mathias 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
		}
1303 aurelien 178
 
1123 mathias 179
		return $organes;
180
	}
181
 
182
	public function getPhotosOrganes() {
1165 aurelien 183
		$organes = $this->getOrganes();
1123 mathias 184
		$nnr = $this->nomCourant->getNnr();
185
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 1);
186
		$vide = true;
187
		foreach ($infosOrganes as $tag => $organe) {
188
			$nbImages = count($organe);
189
			// une image par organe seulement
190
			$organes[$tag] = array_pop($organe);
191
			if ($nbImages != 0) {
192
				$vide = false;
193
			}
194
		}
195
		if ($vide) {
196
			$organes = array();
197
		}
198
		$this->donnees['organes'] = $organes;
199
	}
200
 
201
	public function getPhotosCaracteresIdentification() {
202
		$caracteres = array();
203
		$nnr = $this->nomCourant->getNnr();
1166 mathias 204
		// pas de tag: on cherche les mieux votées pour ce protocole sans tenir compte des tags
205
		$infosCaracteres = $this->images->getInfosMeilleuresImagesParTag($nnr, '', Eflore::PROTOCOLE_CARACTERES, 3);
1123 mathias 206
		if (! empty($infosCaracteres) && ! empty($infosCaracteres[''])) { // le tag est vide, ici
1166 mathias 207
			$caracteres = $infosCaracteres[''];
1123 mathias 208
		}
1337 aurelien 209
		foreach($caracteres as $id_image => &$caractere) {
210
			$caractere['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($id_image);
211
			$caractere['urlImgGrandFormat'] = $this->obtenirUrlImageGrandFormatCel($id_image);
212
			$caractere['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($caractere['auteur.id'], $id_image);
213
			$caractere['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($caractere['auteur.id']);
214
			$caractere['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($caractere['observation']['id_observation']);
215
		}
1123 mathias 216
		$this->donnees['caracteres'] = $caracteres;
217
	}
1165 aurelien 218
 
219
	private function getOrganes() {
220
		return array(
221
				'fleur' => array(),
222
				'feuille' => array(),
223
				'fruit' => array(),
224
				'ecorce' => array(),
225
				'port' => array(),
226
				'rameau' => array());
227
	}
1088 raphael 228
 
229
	// XXX: webservice:
230
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
955 delphine 231
	private function initialiserPhotos($projet) {
232
		$this->images->setProjet($projet);
448 delphine 233
		$nnr = $this->nomCourant->getNnr();
1123 mathias 234
		$ret = $this->images->getInfosImagesParIdsNoms(array($nnr));
235
		return $ret;
955 delphine 236
	}
237
 
238
	private function formaterListePhotos($projet, $images) {
239
		foreach ($images as $idImg => $img) {
240
			$infosImg = array();
241
			$infosImg['src'] = $img['binaire.href'];
242
			$infosImg['nomSci'] = $img['determination.nom_sci'];
243
			$infosImg['station'] = $img['station.libelle'];
244
			$infosImg['date'] = $this->formaterDateImg($img['date']);
245
			$infosImg['auteur'] = $img['auteur.libelle'];
1135 mathias 246
			$infosImg['auteur.id'] = $img['auteur.id'];
955 delphine 247
			if ($projet == "cel") {
248
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
1303 aurelien 249
				$infosImg['urlImgGrandFormat'] = $this->obtenirUrlImageGrandFormatCel($idImg);
955 delphine 250
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
1114 aurelien 251
				$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
252
				$infosImg['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
955 delphine 253
			}
254
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
515 jpm 255
		}
955 delphine 256
	}
257
 
1311 aurelien 258
	public static function obtenirUrlImageGrandFormatCel($id, $format = "O") {
1303 aurelien 259
		$tpl = Config::get('baseUrlImageCelTpl');
260
		return sprintf($tpl, str_pad($id, 9, '0', STR_PAD_LEFT).$format.'.jpg');
261
	}
262
 
263
	// XXX: public static pour être injecté dans le squelette d'entete
1311 aurelien 264
	public static function obtenirTemplateUrlImageGrandFormatOrganes($format = "O") {
1303 aurelien 265
		return $tpl = sprintf(Config::get('baseUrlImageCelTpl').$format.'.jpg', '{id_image}');
266
	}
267
 
955 delphine 268
	private function formaterMetaPhotos($projet) {
269
		$this->meta->setProjet($projet);
339 aurelien 270
		$meta = $this->meta->getMetaDonnees();
1130 aurelien 271
		$titreMeta = $meta[0];
272
		$this->donnees[$projet]['meta'] = $titreMeta;
955 delphine 273
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
339 aurelien 274
	}
697 mathilde 275
 
955 delphine 276
 
277
 
697 mathilde 278
	public function getCelExport() {
279
		$cel = array();
280
		$this->images->setProjet('cel');
281
		$nnr = $this->nomCourant->getNnr();
282
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
283
		if($img) {
284
			$img = array_values($img);
285
			$cel['images']['src'] = $img[0]['binaire.href'];
286
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
978 aurelien 287
			$cel['images']['station'] = $img[0]['station.libelle'];
697 mathilde 288
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
289
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
290
			$this->meta->setProjet('cel');
291
			$meta = $this->meta->getMetaDonnees();
1130 aurelien 292
			$cel['meta'] = $meta[0];
697 mathilde 293
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
294
		}
295
		return $cel;
296
	}
297
 
497 jpm 298
	private function formaterDateImg($date) {
299
		$dateFmt = $date;
1326 mathias 300
		if ($date == '' || $date == null || strpos($date, '0000-00-00') !== false || $date == '1970-01-01 01:01:01') {
1019 raphael 301
			return 'inconnue';
497 jpm 302
		}
1019 raphael 303
		$time = strtotime($date);
304
		if(!$time) {
305
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
306
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
307
			   si FALSE pour avant 1901: problème php
308
			   On retourne alors simplement l'année.
309
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
310
			$dateFmt = explode('-', $date);
311
			return $dateFmt[0];
312
		}
313
		return strftime('%e %B %Y', strtotime($date));
497 jpm 314
	}
315
 
955 delphine 316
	private function formaterNomSci($nom) {
317
		$nomFmt = $nom;
318
		if (is_null($nom) || $nom == '') {
319
			$nomFmt = 'inconnu';
320
		}
321
		return $nomFmt;
497 jpm 322
	}
238 delphine 323
}
324
?>