Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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