Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1114 | Rev 1123 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1114 Rev 1115
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Classe mère du module Liste.
4
 * Classe mère du module Liste.
5
 *
5
 *
6
 * @category	PHP 5.2
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
7
 * @package		eflore-consultation
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @copyright	2011 Tela-Botanica
10
 * @copyright	2011 Tela-Botanica
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
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
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class Illustrations extends aControleur {
15
class Illustrations extends aControleur {
16
 
16
 
17
	private $conteneur = null;
17
	private $conteneur = null;
18
	private $nomCourant = null;
18
	private $nomCourant = null;
19
	private $images = null;
19
	private $images = null;
20
	private $appUrls = null;
20
	private $appUrls = null;
21
	private $meta = null;
21
	private $meta = null;
22
	private $referentiel = 'bdtfx';
22
	private $referentiel = 'bdtfx';
23
	private $donnees = array();
23
	private $donnees = array();
24
 
24
 
25
	public function __construct(Conteneur $conteneur) {
25
	public function __construct(Conteneur $conteneur) {
26
		$this->conteneur = $conteneur;
26
		$this->conteneur = $conteneur;
27
		$this->nomCourant = $this->conteneur->getNomCourant();
27
		$this->nomCourant = $this->conteneur->getNomCourant();
28
		$this->referentiel = $this->conteneur->getParametre('referentiel');
28
		$this->referentiel = $this->conteneur->getParametre('referentiel');
29
		$this->images = $this->conteneur->getApiImages();
29
		$this->images = $this->conteneur->getApiImages();
30
		$this->appUrls = $this->conteneur->getAppUrls();
30
		$this->appUrls = $this->conteneur->getAppUrls();
31
		$this->meta = $this->conteneur->getApiMetaDonnees();
31
		$this->meta = $this->conteneur->getApiMetaDonnees();
32
	}
32
	}
33
 
33
 
34
	public function obtenirDonnees() {
34
	public function obtenirDonnees() {
35
		$this->donnees['nt'] = $this->nomCourant->getNt();
35
		$this->donnees['nt'] = $this->nomCourant->getNt();
36
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
36
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
37
		$this->getPhotos();
37
		$this->getPhotos();
38
		$this->getDessin();
38
		$this->getDessin();
39
		return $this->donnees;
39
		return $this->donnees;
40
	}
40
	}
41
	
41
	
42
	public function obtenirDonneesExport() {
42
	public function obtenirDonneesExport() {
43
		$this->donnees['nt'] = $this->nomCourant->getNt();
43
		$this->donnees['nt'] = $this->nomCourant->getNt();
44
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
44
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
45
		$this->donnees['cel'] = $this->getCelExport();
45
		$this->donnees['cel'] = $this->getCelExport();
46
		$this->donnees['coste'] = $this->getCoste();
46
		$this->donnees['coste'] = $this->getCoste();
47
		return $this->donnees;
47
		return $this->donnees;
48
	}
48
	}
49
 
49
 
50
	public function getBloc() {
50
	public function getBloc() {
51
		$this->donnees = $this->getPhoto('cel');
51
		$this->donnees = $this->getPhoto('cel');
52
		if (empty($this->donnees)) {
52
		if (empty($this->donnees)) {
53
			$infos_image = $this->getDessin();
53
			$infos_image = $this->getDessin();
54
			if (empty($infos_image) == false ){
54
			if (empty($infos_image) == false ){
55
				$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
55
				$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
56
			}
56
			}
57
		}
57
		}
58
		if (empty($this->donnees)) {
58
		if (empty($this->donnees)) {
59
			$this->donnees = $this->getPhoto('photoflora');
59
			$this->donnees = $this->getPhoto('photoflora');
60
		}
60
		}
61
		return $this->donnees;
61
		return $this->donnees;
62
	}
62
	}
63
	
63
	
64
	
64
	
65
	public function getPhoto($source) {
65
	public function getPhoto($source) {
66
		$donnees = array();
66
		$donnees = array();
67
		$this->images->setProjet($source);
67
		$this->images->setProjet($source);
68
		$nnr = $this->nomCourant->getNnr();
68
		$nnr = $this->nomCourant->getNnr();
69
		$infos_image = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
69
		$infos_image = $this->images->setApi(Eflore::API_EFLORE)->getInfosPremiereImageParIdsNoms(array($nnr));
70
		if ($infos_image != array()) {
70
		if ($infos_image != array()) {
71
			$image = array_shift($infos_image);
71
			$image = array_shift($infos_image);
72
			$donnees['imageUrl'] =  $image['binaire.href'];
72
			$donnees['imageUrl'] =  $image['binaire.href'];
73
		}
73
		}
74
		return $donnees;
74
		return $donnees;
75
	}
75
	}
76
 
76
 
77
	public function getCoste() {
77
	public function getCoste() {
78
		$coste = array();
78
		$coste = array();
79
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
79
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
80
		$this->images->setProjet('coste');
80
		$this->images->setProjet('coste');
81
		$this->images->setNnTaxon($tax);
81
		$this->images->setNnTaxon($tax);
82
		$costeImg = $this->images->getInfosImagesTaxons();
82
		$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
83
		foreach ($costeImg as $infos) {
83
		foreach ($costeImg as $infos) {
84
			$coste['images'][] = $infos['binaire.href'];
84
			$coste['images'][] = $infos['binaire.href'];
85
		}
85
		}
86
		$this->meta->setProjet('coste');
86
		$this->meta->setProjet('coste');
87
		$meta = $this->meta->getMetaDonnees();
87
		$meta = $this->meta->getMetaDonnees();
88
		$coste['meta']['titre']= $meta[0]['titre'];
88
		$coste['meta']['titre']= $meta[0]['titre'];
89
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
89
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
90
		return $coste;
90
		return $coste;
91
	}
91
	}
92
 
92
 
93
	public function getDessin() {
93
	public function getDessin() {
94
		$projet = Config::get($this->referentiel.'.baseDessins');
94
		$projet = Config::get($this->referentiel.'.baseDessins');
95
		if ($projet != "") {
95
		if ($projet != "") {
96
			$dessin = array();
96
			$dessin = array();
97
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
97
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
98
			$this->images->setProjet($projet);
98
			$this->images->setProjet($projet);
99
			$this->images->setNnTaxon($tax);
99
			$this->images->setNnTaxon($tax);
100
			$costeImg = $this->images->getInfosImagesTaxons();
100
			$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
101
				foreach ($costeImg as $infos) {
101
				foreach ($costeImg as $infos) {
102
					$dessin['images'][] = $infos['binaire.href'];
102
					$dessin['images'][] = $infos['binaire.href'];
103
				}
103
				}
104
			$this->meta->setProjet('coste');
104
			$this->meta->setProjet('coste');
105
			$meta = $this->meta->getMetaDonnees();
105
			$meta = $this->meta->getMetaDonnees();
106
			$dessin['meta']['titre']= $meta[0]['titre'];
106
			$dessin['meta']['titre']= $meta[0]['titre'];
107
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
107
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
108
			$this->donnees['coste'] = $dessin;
108
			$this->donnees['coste'] = $dessin;
109
		}
109
		}
110
	}
110
	}
111
	
111
	
112
	public function getPhotos() {
112
	public function getPhotos() {
113
		$projets[] = Config::get($this->referentiel.'.baseImages');
113
		$projets[] = Config::get($this->referentiel.'.baseImages');
114
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
114
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
115
		foreach ($projets as $projet) {
115
		foreach ($projets as $projet) {
116
			if ($projet != "") {
116
			if ($projet != "") {
-
 
117
				if ($projet == "cel") {
-
 
118
					$this->images->setApi(Eflore::API_EFLORE); // prêt à passer à API_DEL
-
 
119
				} else {
-
 
120
					$this->images->setApi(Eflore::API_EFLORE);
-
 
121
				}
117
				$images = $this->initialiserPhotos($projet);
122
				$images = $this->initialiserPhotos($projet);
118
				$this->formaterListePhotos($projet, $images);
123
				$this->formaterListePhotos($projet, $images);
119
				$this->formaterMetaPhotos($projet);
124
				$this->formaterMetaPhotos($projet);
120
			}
125
			}
121
		}
126
		}
122
	}
127
	}
123
 
128
 
124
	// XXX: webservice:
129
	// XXX: webservice:
125
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
130
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
126
	private function initialiserPhotos($projet) {
131
	private function initialiserPhotos($projet) {
127
		$this->images->setProjet($projet);
132
		$this->images->setProjet($projet);
128
		$nnr = $this->nomCourant->getNnr();
133
		$nnr = $this->nomCourant->getNnr();
129
		return $this->images->getInfosImagesParIdsNoms(array($nnr));
134
		return $this->images->getInfosImagesParIdsNoms(array($nnr));
130
	}
135
	}
131
	
136
	
132
	private function formaterListePhotos($projet, $images) {
137
	private function formaterListePhotos($projet, $images) {
133
		foreach ($images as $idImg => $img) {
138
		foreach ($images as $idImg => $img) {
134
			$infosImg = array();
139
			$infosImg = array();
135
			$infosImg['src'] = $img['binaire.href'];
140
			$infosImg['src'] = $img['binaire.href'];
136
			$infosImg['nomSci'] = $img['determination.nom_sci'];
141
			$infosImg['nomSci'] = $img['determination.nom_sci'];
137
			$infosImg['station'] = $img['station.libelle'];
142
			$infosImg['station'] = $img['station.libelle'];
138
			$infosImg['date'] = $this->formaterDateImg($img['date']);
143
			$infosImg['date'] = $this->formaterDateImg($img['date']);
139
			$infosImg['auteur'] = $img['auteur.libelle'];
144
			$infosImg['auteur'] = $img['auteur.libelle'];
140
			if ($projet == "cel") {
145
			if ($projet == "cel") {
141
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
146
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
142
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
147
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
143
				$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
148
				$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
144
				$infosImg['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
149
				$infosImg['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
145
			}
150
			}
146
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
151
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
147
		}
152
		}
148
	}
153
	}
149
	
154
	
150
	private function formaterMetaPhotos($projet) {
155
	private function formaterMetaPhotos($projet) {
151
		$this->meta->setProjet($projet);
156
		$this->meta->setProjet($projet);
152
		$meta = $this->meta->getMetaDonnees();
157
		$meta = $this->meta->getMetaDonnees();
153
		$titreMeta = $meta[0]['titre'];
158
		$titreMeta = $meta[0]['titre'];
154
		$this->donnees[$projet]['meta']['titre'] = $titreMeta;
159
		$this->donnees[$projet]['meta']['titre'] = $titreMeta;
155
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
160
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
156
	}
161
	}
157
	
162
	
158
	
163
	
159
	
164
	
160
	public function getCelExport() {
165
	public function getCelExport() {
161
		$cel = array();
166
		$cel = array();
162
		$this->images->setProjet('cel');
167
		$this->images->setProjet('cel');
163
		$nnr = $this->nomCourant->getNnr();
168
		$nnr = $this->nomCourant->getNnr();
164
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
169
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
165
		if($img) {
170
		if($img) {
166
			$img = array_values($img);
171
			$img = array_values($img);
167
			$cel['images']['src'] = $img[0]['binaire.href'];
172
			$cel['images']['src'] = $img[0]['binaire.href'];
168
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
173
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
169
			$cel['images']['station'] = $img[0]['station.libelle'];
174
			$cel['images']['station'] = $img[0]['station.libelle'];
170
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
175
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
171
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
176
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
172
			$this->meta->setProjet('cel');
177
			$this->meta->setProjet('cel');
173
			$meta = $this->meta->getMetaDonnees();
178
			$meta = $this->meta->getMetaDonnees();
174
			$titreMeta = $meta[0]['titre'];
179
			$titreMeta = $meta[0]['titre'];
175
			$cel['meta']['titre'] = $titreMeta;
180
			$cel['meta']['titre'] = $titreMeta;
176
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
181
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
177
		}
182
		}
178
		return $cel;
183
		return $cel;
179
	}
184
	}
180
 
185
 
181
	private function formaterDateImg($date) {
186
	private function formaterDateImg($date) {
182
		$dateFmt = $date;
187
		$dateFmt = $date;
183
		if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
188
		if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
184
			return 'inconnue';
189
			return 'inconnue';
185
		}
190
		}
186
		$time = strtotime($date);
191
		$time = strtotime($date);
187
		if(!$time) {
192
		if(!$time) {
188
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
193
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
189
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
194
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
190
			   si FALSE pour avant 1901: problème php
195
			   si FALSE pour avant 1901: problème php
191
			   On retourne alors simplement l'année.
196
			   On retourne alors simplement l'année.
192
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
197
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
193
			$dateFmt = explode('-', $date);
198
			$dateFmt = explode('-', $date);
194
			return $dateFmt[0];
199
			return $dateFmt[0];
195
		}
200
		}
196
		return strftime('%e %B %Y', strtotime($date));
201
		return strftime('%e %B %Y', strtotime($date));
197
	}
202
	}
198
 
203
 
199
	private function formaterNomSci($nom) {
204
	private function formaterNomSci($nom) {
200
		$nomFmt = $nom;
205
		$nomFmt = $nom;
201
		if (is_null($nom) || $nom == '') {
206
		if (is_null($nom) || $nom == '') {
202
			$nomFmt = 'inconnu';
207
			$nomFmt = 'inconnu';
203
		}
208
		}
204
		return $nomFmt;
209
		return $nomFmt;
205
	}
210
	}
206
}
211
}
207
?>
212
?>