Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 367 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 367 Rev 408
Line 11... Line 11...
11
* 
11
*
12
*/
12
*/
13
class Images {
13
class Images {
Line 14... Line 14...
14
	
14
 
-
 
15
	const MIME_JPEG = 'image/jpeg';
15
	const MIME_JPEG = 'image/jpeg';
16
	const MIME_PNG = 'image/png';
16
	const MIME_JSON = 'application/json';
17
	const MIME_JSON = 'application/json';
Line 17... Line 18...
17
	const MIME_XML = 'text/xml';
18
	const MIME_XML = 'text/xml';
18
	
19
 
Line 123... Line 124...
123
	}
124
	}
Line 124... Line 125...
124
 
125
 
125
	public function obtenirImages() {
126
	public function obtenirImages() {
126
		//TODO: tri par date, mais les dates dans la bdd photoflora sont des chaines en entités HTML
127
		//TODO: tri par date, mais les dates dans la bdd photoflora sont des chaines en entités HTML
127
		// donc un tri dessus n'a pas de sens
128
		// donc un tri dessus n'a pas de sens
-
 
129
		$requete = 	'SELECT photos.*, taxons.NumTaxon, taxons.NumNomen, taxons.Combinaison, photographes.Nom, '.
128
		$requete = 	'SELECT photos.*,taxons.NumTaxon, taxons.NumNomen, taxons.Combinaison, photographes.Nom, photographes.Prenom, photographes.Initiales, photographes.Mail '.
130
			'	photographes.Prenom, photographes.Initiales, photographes.Mail '.
129
								'FROM '.self::BDD_PF.'.photos, '.self::BDD_PF.'.photographes, '.self::BDD_PF.'.taxons '.
131
			'FROM '.self::BDD_PF.'.photos, '.self::BDD_PF.'.photographes, '.self::BDD_PF.'.taxons '.
130
								'WHERE '.
132
			'WHERE '.
131
								'photos.Auteur = photographes.ID '.
133
			'photos.Auteur = photographes.ID '.
132
								'AND photos.NumTaxon = taxons.NumTaxon '.
134
			'AND photos.NumTaxon = taxons.NumTaxon '.
Line 180... Line 182...
180
	
182
 
181
	private function formaterRetourJson($photographies) {	
183
	private function formaterRetourJson($photographies) {
182
		$resultat = array();
184
		$resultat = array();
183
		if(is_array($photographies)) {
185
		if (is_array($photographies)) {
184
			foreach ($photographies as $photo) {
-
 
185
 
186
			foreach ($photographies as $photo) {
186
				$image = array();
187
				$image = array();
187
				$url = $this->getUrlPhotoPourInitiales($photo['Initiales'], $photo['NumPhoto'], $this->format);
188
				$url = $this->getUrlPhotoPourInitiales($photo['Initiales'], $photo['NumPhoto'], $this->format);
188
				$urlmax = $this->getUrlPhotoPourInitiales($photo['Initiales'], $photo['NumPhoto'], 'max');
189
				$urlmax = $this->getUrlPhotoPourInitiales($photo['Initiales'], $photo['NumPhoto'], 'max');
-
 
190
				$id = str_replace(array('.jpg','.jpeg', '.png'), '', $photo['NumPhoto']);
189
				$id = str_replace(array('.jpg','.jpeg'),'',$photo['NumPhoto']);
191
 
190
				// Post-traitement des valeurs
-
 
191
				$image['station'] = $this->formaterChaineEncodeeBddPhotoflora($photo['lieu']);
192
				// Post-traitement des valeurs
192
				$image['date'] = $this->donnerDate($this->formaterChaineEncodeeBddPhotoflora($photo['Date']));
193
				$image['date'] = $this->donnerDate($this->formaterChaineEncodeeBddPhotoflora($photo['Date']));
193
				$image['auteur'] = $this->formaterChaineEncodeeBddPhotoflora($photo['Prenom'].' '.$photo['Nom']);
194
				$image['mime'] = $this->extraireMime($photo['NumPhoto']);
194
				$image['determination'] = $photo['Combinaison'].' ['.$photo['Prenom'].' '.$photo['Nom'].']';
-
 
195
				$image['determination.nom_sci'] = $photo['Combinaison'];
-
 
196
				$image['determination.nom_sci.code'] = "bdtfx.".$photo['NumNomen'];
195
				$image['auteur.libelle'] = $this->formaterChaineEncodeeBddPhotoflora($photo['Prenom'].' '.$photo['Nom']);
197
				$image['binaire.href'] = $url;
196
				$image['binaire.href'] = $url;
-
 
197
				$image['binaire.hrefmax'] = $urlmax;
-
 
198
				$image['determination.libelle'] = $photo['Combinaison'].' ['.$photo['Prenom'].' '.$photo['Nom'].']';
-
 
199
				$image['determination.nom_sci.libelle'] = $photo['Combinaison'];
-
 
200
				$image['determination.nom_sci.code'] = "bdtfx.".$photo['NumNomen'];
Line 198... Line 201...
198
				$image['binaire.hrefmax'] = $urlmax;
201
				$image['station.libelle'] = $this->formaterStation($photo['lieu']);
199
				
202
 
200
				$resultat[$id] = $image;
203
				$resultat[$id] = $image;
201
			}
-
 
202
		}
204
			}
203
		
205
		}
Line -... Line 206...
-
 
206
		return $resultat;
-
 
207
	}
-
 
208
 
-
 
209
	private function extraireMime($fichierImg) {
-
 
210
		$mime = '';
-
 
211
		if (strpos($fichierImg, '.jpg') || strpos($fichierImg, '.jpeg')) {
-
 
212
			$mime = self::MIME_JPEG;
-
 
213
		} else if (strpos($fichierImg, '.png')) {
-
 
214
			$mime = self::MIME_PNG;
-
 
215
		}
-
 
216
		return $mime;
-
 
217
	}
-
 
218
 
-
 
219
	private function formaterStation($station) {
-
 
220
		$station = $this->formaterChaineEncodeeBddPhotoflora($station);
-
 
221
		$station = preg_replace('/^ : /', '', $station);
204
		return $resultat;
222
		return $station;
205
	}
223
	}
206
	
224
 
Line 207... Line 225...
207
	private function callBackReplace($m) {
225
	private function callBackReplace($m) {
208
		return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
226
		return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
209
	}
-
 
210
	
227
	}
Line 211... Line 228...
211
	private function formaterChaineEncodeeBddPhotoflora($chaine) {
228
 
212
		return $chaine = preg_replace_callback("/(&#[0-9]+;)/", array($this, 'callBackReplace')
229
	private function formaterChaineEncodeeBddPhotoflora($chaine) {
213
		, $chaine);
230
		return $chaine = preg_replace_callback("/(&#[0-9]+;)/", array($this, 'callBackReplace'), $chaine);