Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1180 Rev 1280
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
	* Le web service observations récupère toutes les observations et, pour chacune d'elle, les
4
	* Le web service observations récupère toutes les observations et, pour chacune d'elle, les
5
	* images qui lui sont associées.
5
	* images qui lui sont associées.
6
 *
6
 *
7
 * @category	php 5.2
7
 * @category	php 5.2
8
 * @package	del
8
 * @package	del
9
 * @subpackage images
9
 * @subpackage images
10
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @copyright	Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
11
 * @copyright	Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
12
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
13
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
14
 * @version	$Id: Bdd.php 403 2012-02-22 14:35:20Z gduche $
14
 * @version	$Id: Bdd.php 403 2012-02-22 14:35:20Z gduche $
15
 * @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=ApiIdentiplante01Observations
15
 * @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=ApiIdentiplante01Observations
16
 */
16
 */
17
 
17
 
18
// http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
18
// http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
19
class Observation {
19
class Observation {
20
	
20
	
21
	private $conteneur;
21
	private $conteneur;
22
	private $gestionBdd;
22
	private $gestionBdd;
23
	private $bdd;
23
	private $bdd;
24
	private $id_observation;
24
	private $id_observation;
25
	private $imageIds;
25
	private $imageIds;
26
	
26
	
27
	public function __construct(Conteneur $conteneur = null) {
27
	public function __construct(Conteneur $conteneur = null) {
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
29
		$this->conteneur->chargerConfiguration('config_votes.ini');
29
		$this->conteneur->chargerConfiguration('config_votes.ini');
30
		$this->conteneur->chargerConfiguration('config_mapping_votes.ini');
30
		$this->conteneur->chargerConfiguration('config_mapping_votes.ini');
31
		$this->conteneur->chargerConfiguration('config_mapping_commentaires.ini');
31
		$this->conteneur->chargerConfiguration('config_mapping_commentaires.ini');
32
		$this->gestionBdd = $conteneur->getGestionBdd();
32
		$this->gestionBdd = $conteneur->getGestionBdd();
33
		$this->bdd = $this->gestionBdd->getBdd();
33
		$this->bdd = $this->gestionBdd->getBdd();
34
	}
34
	}
35
	
35
	
36
	/**
36
	/**
37
	 * Méthode principale de la classe.
37
	 * Méthode principale de la classe.
38
	 * Lance la récupération des images dans la base et les place dans un objet ResultatService 
38
	 * Lance la récupération des images dans la base et les place dans un objet ResultatService 
39
	 * pour l'afficher.
39
	 * pour l'afficher.
40
	 * @param array $ressources les ressources situées après l'url de base (ex : http://url/ressource1/ressource2)
40
	 * @param array $ressources les ressources situées après l'url de base (ex : http://url/ressource1/ressource2)
41
	 * @param array $parametres les paramètres situés après le ? dans l'url
41
	 * @param array $parametres les paramètres situés après le ? dans l'url
42
	 * */
42
	 * */
43
	public function consulter($ressources, $parametres) {
43
	public function consulter($ressources, $parametres) {
44
		
44
		
45
		// Gestion des configuration du script
45
		// Gestion des configuration du script
46
		$this->configurer($ressources);
46
		$this->configurer($ressources);
47
		$this->verifierConfiguration();
47
		$this->verifierConfiguration();
48
		
48
		
49
		
49
		
50
		// Lancement du service
50
		// Lancement du service
51
		$liaisons = $this->chargerLiaisons();
51
		$liaisons = $this->chargerLiaisons();
52
		$observation = $this->chargerObservation($liaisons);
52
		$observation = $this->chargerObservation($liaisons);
53
		$observation = $this->chargerImages($observation);
53
		$observation = $this->chargerImages($observation);
54
		$observation = $this->chargerCommentaires($observation);
54
		$observation = $this->chargerCommentaires($observation);
55
		
55
		
56
		// Mettre en forme le résultat et l'envoyer pour affichage
56
		// Mettre en forme le résultat et l'envoyer pour affichage
57
		$resultat = new ResultatService();
57
		$resultat = new ResultatService();
58
		$resultat->corps = $observation;
58
		$resultat->corps = $observation;
59
		return $resultat;
59
		return $resultat;
60
	}
60
	}
61
	
61
	
62
	/*-------------------------------------------------------------------------------
62
	/*-------------------------------------------------------------------------------
63
	 							CONFIGURATION DU SERVICE
63
	 							CONFIGURATION DU SERVICE
64
	 --------------------------------------------------------------------------------*/
64
	 --------------------------------------------------------------------------------*/
65
	/**
65
	/**
66
	 * Configuration du service en fonction du fichier de config config_del.ini
66
	 * Configuration du service en fonction du fichier de config config_del.ini
67
	 * */
67
	 * */
68
	private function configurer($ressources) {
68
	private function configurer($ressources) {
69
		$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
69
		$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
70
		$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
70
		$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
71
		$this->mappingCommentaire = $this->conteneur->getParametre('mapping_commentaire');
71
		$this->mappingCommentaire = $this->conteneur->getParametre('mapping_commentaire');
72
		if (empty($ressources) || sizeof($ressources) > 1 ) {
72
		if (empty($ressources) || sizeof($ressources) > 1 ) {
73
			$e = 'Le service observation accepete 1 et 1 seule ressource';
73
			$e = 'Le service observation accepete 1 et 1 seule ressource';
74
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
74
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
75
		} else {
75
		} else {
76
			$this->id_observation = $ressources[0];
76
			$this->id_observation = $ressources[0];
77
		}
77
		}
78
	}
78
	}
79
	
79
	
80
	/**
80
	/**
81
	 * Vérifier que le service est bien configuré 
81
	 * Vérifier que le service est bien configuré 
82
	 * */
82
	 * */
83
	private function verifierConfiguration() {
83
	private function verifierConfiguration() {
84
	
84
	
85
		$erreurs = array();
85
		$erreurs = array();
86
		$tableauImages = $this->conteneur->getParametre('observations');
86
		$tableauImages = $this->conteneur->getParametre('observations');
87
		if (empty($tableauImages)) {
87
		if (empty($tableauImages)) {
88
			$erreurs[] = '- le fichier de configuration ne contient pas le tableau [images] ou celui-ci est vide ;'; 
88
			$erreurs[] = '- le fichier de configuration ne contient pas le tableau [images] ou celui-ci est vide ;'; 
89
		} else {
89
		} else {
90
			if ($this->conteneur->getParametre('url_service') == null) {
90
			if ($this->conteneur->getParametre('url_service') == null) {
91
				$erreurs[] = '- paramètre "url_service" manquant ;';
91
				$erreurs[] = '- paramètre "url_service" manquant ;';
92
			}
92
			}
93
			
93
			
94
			if ($this->conteneur->getParametre('url_images') == null) {
94
			if ($this->conteneur->getParametre('url_images') == null) {
95
				$erreurs[] = '- paramètre "url_images" manquant ;';
95
				$erreurs[] = '- paramètre "url_images" manquant ;';
96
			}
96
			}
97
			
97
			
98
		}
98
		}
99
 
99
 
100
		if (empty($this->mappingObservation)) {
100
		if (empty($this->mappingObservation)) {
101
			$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_observation] ou celui-ci est vide ;';
101
			$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_observation] ou celui-ci est vide ;';
102
		} else {
102
		} else {
103
			$champsMappingObs = array('id_observation', 'date_observation', 'date_transmission', 'famille', 'nom_sel', 'nom_sel_nn', 'nt',
103
			$champsMappingObs = array('id_observation', 'date_observation', 'date_transmission', 'famille', 'nom_sel', 'nom_sel_nn', 'nt',
104
								'ce_zone_geo', 'zone_geo', 'lieudit', 'station', 'courriel', 'ce_utilisateur', 'nom', 'prenom');
104
								'ce_zone_geo', 'zone_geo', 'lieudit', 'station', 'courriel', 'ce_utilisateur', 'nom', 'prenom');
105
			
105
			
106
			foreach ($champsMappingObs as $champ) {
106
			foreach ($champsMappingObs as $champ) {
107
				if (!isset($this->mappingObservation[$champ])) {
107
				if (!isset($this->mappingObservation[$champ])) {
108
					$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
108
					$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
109
				}				
109
				}				
110
			}
110
			}
111
		}
111
		}
112
		
112
		
113
		if (empty($this->mappingCommentaire)) {
113
		if (empty($this->mappingCommentaire)) {
114
			$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_commentaire] ou celui-ci est vide ;';
114
			$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_commentaire] ou celui-ci est vide ;';
115
		} else {
115
		} else {
116
			$champsMappingCom = array('id_commentaire', 'texte', 'ce_utilisateur', 'utilisateur_nom', 'utilisateur_prenom', 'utilisateur_courriel', 'date');
116
			$champsMappingCom = array('id_commentaire', 'texte', 'ce_utilisateur', 'utilisateur_nom', 'utilisateur_prenom', 'utilisateur_courriel', 'date');
117
			foreach ($champsMappingCom as $champ) {
117
			foreach ($champsMappingCom as $champ) {
118
				if (!isset($this->mappingCommentaire[$champ])) {
118
				if (!isset($this->mappingCommentaire[$champ])) {
119
					$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
119
					$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
120
				}
120
				}
121
			}
121
			}
122
		}
122
		}
123
		
123
		
124
		if (!empty($erreurs)) {
124
		if (!empty($erreurs)) {
125
			$e = 'Erreur lors de la configuration : '."\n";
125
			$e = 'Erreur lors de la configuration : '."\n";
126
			$e .= implode("\n", $erreurs);
126
			$e .= implode("\n", $erreurs);
127
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
127
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
128
		}
128
		}
129
	}
129
	}
130
	
130
	
131
	/*-------------------------------------------------------------------------------
131
	/*-------------------------------------------------------------------------------
132
								CHARGEMENT DES OBSERVATIONS 
132
								CHARGEMENT DES OBSERVATIONS 
133
	--------------------------------------------------------------------------------*/
133
	--------------------------------------------------------------------------------*/
134
	/**
134
	/**
135
	* Chargement depuis la bdd de toutes les liaisons entre images et observations
135
	* Chargement depuis la bdd de toutes les liaisons entre images et observations
136
	* */
136
	* */
137
	private function chargerLiaisons() {
137
	private function chargerLiaisons() {
138
	
138
	
139
		$requeteLiaisons = 'SELECT *, dob.commentaire as dob_commentaire '.
139
		$requeteLiaisons = 'SELECT *, dob.commentaire as dob_commentaire '.
140
						   'FROM '.$this->gestionBdd->formaterTable('del_observation', 'dob').
140
						   'FROM '.$this->gestionBdd->formaterTable('del_observation', 'dob').
141
						   'INNER JOIN '.$this->gestionBdd->formaterTable('del_obs_image', 'doi').
141
						   'INNER JOIN '.$this->gestionBdd->formaterTable('del_obs_image', 'doi').
142
						   'ON doi.id_observation = dob.id_observation '.
142
						   'ON doi.id_observation = dob.id_observation '.
143
						   'LEFT JOIN del_utilisateur du '.
143
						   'LEFT JOIN del_utilisateur du '.
144
						   'ON du.id_utilisateur = dob.ce_utilisateur '.
144
						   'ON du.id_utilisateur = dob.ce_utilisateur '.
145
						   'WHERE doi.id_observation = '.$this->id_observation;
145
						   'WHERE doi.id_observation = '.$this->id_observation;
146
		$requeteLiaisons .=  ' GROUP BY doi.id_observation';
146
		$requeteLiaisons .=  ' GROUP BY doi.id_observation';
147
		$requeteLiaisons .= ' ORDER BY date_transmission DESC ';
147
		$requeteLiaisons .= ' ORDER BY date_transmission DESC ';
148
		$requeteLiaisons .= $this->gestionBdd->getLimitSql();
148
		$requeteLiaisons .= $this->gestionBdd->getLimitSql();
149
		
149
		
150
		return $this->bdd->recuperer($requeteLiaisons);
150
		return $this->bdd->recuperer($requeteLiaisons);
151
	}
151
	}
152
	
152
	
153
	/**
153
	/**
154
	* Retourner un tableau d'images formaté en fonction des liaisons trouvées
154
	* Retourner un tableau d'images formaté en fonction des liaisons trouvées
155
	* @param $liaisons les liaisons de la table del_obs_images
155
	* @param $liaisons les liaisons de la table del_obs_images
156
	* */
156
	* */
157
	private function chargerObservation($liaison) {
157
	private function chargerObservation($liaison) {
-
 
158
		
-
 
159
		if($liaison['ce_utilisateur'] == 0) {
-
 
160
			$liaison['nom'] = $liaison['nom_utilisateur'];
-
 
161
			$liaison['prenom'] =$liaison['prenom_utilisateur'];
-
 
162
		}
-
 
163
		
158
		$observation = $this->formaterObservation($liaison);
164
		$observation = $this->formaterObservation($liaison);
159
		return $observation;
165
		return $observation;
160
	}
166
	}
161
	
167
	
162
	/**
168
	/**
163
	 * Sélectionner toutes les images de chaque observation
169
	 * Sélectionner toutes les images de chaque observation
164
	 * @param array $observations la liste des observations 
170
	 * @param array $observations la liste des observations 
165
	 * */
171
	 * */
166
	private function chargerImages($observation) {
172
	private function chargerImages($observation) {
167
		$requeteImages = 'SELECT * FROM '. $this->gestionBdd->formaterTable('del_obs_image', 'doi').
173
		$requeteImages = 'SELECT * FROM '. $this->gestionBdd->formaterTable('del_obs_image', 'doi').
168
						 'INNER JOIN '.$this->gestionBdd->formaterTable('del_image', 'di').
174
						 'INNER JOIN '.$this->gestionBdd->formaterTable('del_image', 'di').
169
						 'ON doi.id_image = di.id_image '.
175
						 'ON doi.id_image = di.id_image '.
170
						 'WHERE doi.id_observation = '.$observation['id_observation'];
176
						 'WHERE doi.id_observation = '.$observation['id_observation'];
171
			
177
			
172
		$images = $this->bdd->recupererTous($requeteImages);
178
		$images = $this->bdd->recupererTous($requeteImages);
173
		$images = $this->formaterImages($images);
179
		$images = $this->formaterImages($images);
174
		$images = $this->chargerVotesImage($images);
180
		$images = $this->chargerVotesImage($images);
175
		$observation['images'] = $images;
181
		$observation['images'] = $images;
176
		
182
		
177
		return $observation;
183
		return $observation;
178
	}
184
	}
179
	
185
	
180
	/**
186
	/**
181
	* Charger les votes pour chaque image
187
	* Charger les votes pour chaque image
182
	* */
188
	* */
183
	private function chargerVotesImage($images) {
189
	private function chargerVotesImage($images) {
184
		$requeteVotes = 'SELECT v.*, p.* FROM '.
190
		$requeteVotes = 'SELECT v.*, p.* FROM '.
185
		$this->gestionBdd->formaterTable('del_image_vote', 'v').
191
		$this->gestionBdd->formaterTable('del_image_vote', 'v').
186
									' INNER JOIN del_image_protocole p '.
192
									' INNER JOIN del_image_protocole p '.
187
										'ON v.ce_protocole = p.id_protocole '.
193
										'ON v.ce_protocole = p.id_protocole '.
188
		$this->chargerClauseWhereVotesImage();
194
		$this->chargerClauseWhereVotesImage();
189
		$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
195
		$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
190
 
196
 
191
		$votes = $this->formaterVotesImages($resultatsVotes);
197
		$votes = $this->formaterVotesImages($resultatsVotes);
192
 
198
 
193
		foreach ($images as $id => $image) {
199
		foreach ($images as $id => $image) {
194
			if (isset($votes[$image['id_image']])) {
200
			if (isset($votes[$image['id_image']])) {
195
				foreach($votes[$image['id_image']] as $id_vote => $vote_image) {
201
				foreach($votes[$image['id_image']] as $id_vote => $vote_image) {
196
					$images[$id]['protocoles_votes'][$id_vote] = $vote_image;
202
					$images[$id]['protocoles_votes'][$id_vote] = $vote_image;
197
				}
203
				}
198
			}
204
			}
199
		}
205
		}
200
	
206
	
201
		return $images;
207
		return $images;
202
	}
208
	}
203
	
209
	
204
	private function chargerClauseWhereVotesImage() {
210
	private function chargerClauseWhereVotesImage() {
205
		if (sizeof($this->imageIds) > 0) {
211
		if (sizeof($this->imageIds) > 0) {
206
			$chaineImageIds = implode(',', $this->imageIds);
212
			$chaineImageIds = implode(',', $this->imageIds);
207
			$where[] = 'v.ce_image  IN ('.$chaineImageIds.')';
213
			$where[] = 'v.ce_image  IN ('.$chaineImageIds.')';
208
		}
214
		}
209
		if (isset($this->parametres['protocole'])) {
215
		if (isset($this->parametres['protocole'])) {
210
			$where[] = 'v.ce_protocole = '.$this->proteger($this->parametres['protocole']);
216
			$where[] = 'v.ce_protocole = '.$this->proteger($this->parametres['protocole']);
211
		}
217
		}
212
	
218
	
213
		$where = (!empty($where)) ? 'WHERE '.implode(' AND ', $where) : '';
219
		$where = (!empty($where)) ? 'WHERE '.implode(' AND ', $where) : '';
214
		return $where;
220
		return $where;
215
	}
221
	}
216
	
222
	
217
	/**
223
	/**
218
	* Récupérer tous les commentaires au total
224
	* Récupérer tous les commentaires au total
219
	* @param array $observations la liste des observations à mettre à jour
225
	* @param array $observations la liste des observations à mettre à jour
220
	* */
226
	* */
221
	private function chargerCommentaires($observation) {
227
	private function chargerCommentaires($observation) {
222
		
228
		
223
		$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
229
		$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
224
							   'WHERE ce_observation = '.$observation['id_observation'];
230
							   'WHERE ce_observation = '.$observation['id_observation'];
225
		$commentaires = $this->bdd->recupererTous($requeteCommentaires);
231
		$commentaires = $this->bdd->recupererTous($requeteCommentaires);
226
		
232
		
227
		$commentaires_formates = array();
233
		$commentaires_formates = array();
228
		foreach ($commentaires as $commentaire) {
234
		foreach ($commentaires as $commentaire) {
229
			$commentaire = $this->formaterCommentaire($commentaire);
235
			$commentaire = $this->formaterCommentaire($commentaire);
230
			if (isset($commentaire['nom_sel']) && $commentaire['nom_sel'] != null) {
236
			if (isset($commentaire['nom_sel']) && $commentaire['nom_sel'] != null) {
231
				$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
237
				$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
232
			}
238
			}
233
			$commentaires_formates[$commentaire['id_commentaire']] = $commentaire;
239
			$commentaires_formates[$commentaire['id_commentaire']] = $commentaire;
234
		}
240
		}
235
		$observation['commentaires'] = $commentaires_formates;
241
		$observation['commentaires'] = $commentaires_formates;
236
		
242
		
237
		return $observation;
243
		return $observation;
238
	}
244
	}
239
	
245
	
240
	private function chargerVotes($id_commentaire) {
246
	private function chargerVotes($id_commentaire) {
241
		$requeteVotes = 'SELECT * FROM '.
247
		$requeteVotes = 'SELECT * FROM '.
242
			$this->gestionBdd->formaterTable('del_commentaire_vote').
248
			$this->gestionBdd->formaterTable('del_commentaire_vote').
243
			'WHERE ce_proposition = '.$this->proteger($id_commentaire);
249
			'WHERE ce_proposition = '.$this->proteger($id_commentaire);
244
		$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
250
		$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
245
		$votes = array();
251
		$votes = array();
246
		foreach ($resultatsVotes as $vote) {
252
		foreach ($resultatsVotes as $vote) {
247
			$id_vote = $vote['id_vote'];
253
			$id_vote = $vote['id_vote'];
248
			$votes[$id_vote] = $this->formaterVote($vote);
254
			$votes[$id_vote] = $this->formaterVote($vote);
249
		}
255
		}
250
		return $votes;
256
		return $votes;
251
	}
257
	}
252
	
258
	
253
	
259
	
254
	/*-------------------------------------------------------------------------------
260
	/*-------------------------------------------------------------------------------
255
								FORMATER ET METTRE EN FORME
261
								FORMATER ET METTRE EN FORME
256
	--------------------------------------------------------------------------------*/
262
	--------------------------------------------------------------------------------*/
257
	
263
	
258
	/**
264
	/**
259
	 * Formater les images d'une observation
265
	 * Formater les images d'une observation
260
	 * @param array $images les images de l'observation
266
	 * @param array $images les images de l'observation
261
	 * */
267
	 * */
262
	private function formaterImages($images) {
268
	private function formaterImages($images) {
263
		$imagesRetour = array();
269
		$imagesRetour = array();
264
		foreach ($images as $image) {
270
		foreach ($images as $image) {
265
			
271
			
266
			$this->imageIds[] = $image['id_image'];
272
			$this->imageIds[] = $image['id_image'];
267
			$imageCourante = array();
273
			$imageCourante = array();
268
			$imageCourante['id_image'] = $image['id_image'];
274
			$imageCourante['id_image'] = $image['id_image'];
269
			$imageCourante['date'] = $image['date_prise_de_vue'];
275
			$imageCourante['date'] = $image['date_prise_de_vue'];
270
			$imageCourante['binaire.href'] = $this->formaterLienImage($image['id_image']);
276
			$imageCourante['binaire.href'] = $this->formaterLienImage($image['id_image']);
271
			$imageCourante['hauteur'] = $image['hauteur'];
277
			$imageCourante['hauteur'] = $image['hauteur'];
272
			$imageRetour['largeur'] = $image['largeur'];
278
			$imageRetour['largeur'] = $image['largeur'];
273
			
279
			
274
			$imagesRetour[] = $imageCourante;
280
			$imagesRetour[] = $imageCourante;
275
		}
281
		}
276
		
282
		
277
		return $imagesRetour;
283
		return $imagesRetour;
278
	} 
284
	} 
279
	
285
	
280
	/**
286
	/**
281
	*  Formater une observation depuis une ligne liaison
287
	*  Formater une observation depuis une ligne liaison
282
	*  @param $liaison liaison issue de la recherche
288
	*  @param $liaison liaison issue de la recherche
283
	*  @return $observation l'observation mise en forme
289
	*  @return $observation l'observation mise en forme
284
	* */
290
	* */
285
	private function formaterObservation($liaison) {
291
	private function formaterObservation($liaison) {
286
		$observation = array();
292
		$observation = array();
287
		
293
		
288
		foreach ($this->mappingObservation as $nomOriginal => $nomFinal) {
294
		foreach ($this->mappingObservation as $nomOriginal => $nomFinal) {
289
			$observation[$nomFinal] = $liaison[$nomOriginal];
295
			$observation[$nomFinal] = $liaison[$nomOriginal];
290
		}
296
		}
291
		
297
		
292
		$observation['images'] = array();
298
		$observation['images'] = array();
293
 
299
 
294
		return $observation;
300
		return $observation;
295
	}
301
	}
296
	
302
	
297
	/**
303
	/**
298
	 * Formater le lien de l'image en fonction du fichier de config et de l'identifiant de l'image
304
	 * Formater le lien de l'image en fonction du fichier de config et de l'identifiant de l'image
299
	 * */
305
	 * */
300
	private function formaterLienImage($idImage) {
306
	private function formaterLienImage($idImage) {
301
		$idImage = sprintf('%09s', $idImage);
307
		$idImage = sprintf('%09s', $idImage);
302
		$url = $this->conteneur->getParametre('url_images');
308
		$url = $this->conteneur->getParametre('url_images');
303
		$urlImage = str_replace('%s', $idImage, $url);
309
		$urlImage = str_replace('%s', $idImage, $url);
304
		return $urlImage;
310
		return $urlImage;
305
	}
311
	}
306
	
312
	
307
	private function proteger($valeur) {
313
	private function proteger($valeur) {
308
		if (is_array($valeur)) {
314
		if (is_array($valeur)) {
309
			return $this->bdd->protegerTableau($valeur);
315
			return $this->bdd->protegerTableau($valeur);
310
		} else {
316
		} else {
311
			return $this->bdd->proteger($valeur);
317
			return $this->bdd->proteger($valeur);
312
		}
318
		}
313
	}
319
	}
314
	
320
	
315
	/**
321
	/**
316
	*
322
	*
317
	* Formate un commentaire en fonction du fichier de configuration
323
	* Formate un commentaire en fonction du fichier de configuration
318
	*/
324
	*/
319
	private function formaterCommentaire($commentaire) {
325
	private function formaterCommentaire($commentaire) {
320
		$commentaire_formate = array();
326
		$commentaire_formate = array();
321
		foreach ($this->mappingCommentaire as $nomOriginal => $nomFinal) {
327
		foreach ($this->mappingCommentaire as $nomOriginal => $nomFinal) {
322
			if (isset($commentaire[$nomOriginal])) {
328
			if (isset($commentaire[$nomOriginal])) {
323
			$commentaire_formate[$nomFinal] = $commentaire[$nomOriginal];
329
			$commentaire_formate[$nomFinal] = $commentaire[$nomOriginal];
324
			}
330
			}
325
		}
331
		}
326
		return $commentaire_formate;
332
		return $commentaire_formate;
327
	}
333
	}
328
	
334
	
329
	/**
335
	/**
330
	*  Formater un vote en fonction du fichier de configuration config_votes.ini
336
	*  Formater un vote en fonction du fichier de configuration config_votes.ini
331
	*  @param $votes array()
337
	*  @param $votes array()
332
	* */
338
	* */
333
	private function formaterVote($vote) {
339
	private function formaterVote($vote) {
334
		$retour = array();
340
		$retour = array();
335
		foreach ($vote as $param => $valeur) {
341
		foreach ($vote as $param => $valeur) {
336
			$retour[$this->mappingVotes[$param]] = $valeur;
342
			$retour[$this->mappingVotes[$param]] = $valeur;
337
		}
343
		}
338
		return $retour;
344
		return $retour;
339
	}
345
	}
340
	
346
	
341
	/**
347
	/**
342
	*  Formater une observation depuis une ligne liaison
348
	*  Formater une observation depuis une ligne liaison
343
	*  @param $liaison liaison issue de la recherche
349
	*  @param $liaison liaison issue de la recherche
344
	*  @return $observation l'observation mise en forme
350
	*  @return $observation l'observation mise en forme
345
	* */
351
	* */
346
	private function formaterVotesImages($votes) {
352
	private function formaterVotesImages($votes) {
347
		$retour = array();
353
		$retour = array();
348
		foreach ($votes as $vote) {
354
		foreach ($votes as $vote) {
349
			$retour_vote = array();
355
			$retour_vote = array();
350
			foreach ($vote as $param=>$valeur) {
356
			foreach ($vote as $param=>$valeur) {
351
				if (strpos($this->mappingVotes[$param], 'protocole.') === 0) {
357
				if (strpos($this->mappingVotes[$param], 'protocole.') === 0) {
352
					$retour_protocole[$this->mappingVotes[$param]] = $valeur;
358
					$retour_protocole[$this->mappingVotes[$param]] = $valeur;
353
				} else {
359
				} else {
354
					$retour_vote[$this->mappingVotes[$param]] = $valeur;
360
					$retour_vote[$this->mappingVotes[$param]] = $valeur;
355
				}
361
				}
356
			}
362
			}
357
			if (!isset($retour[$vote['ce_image']][$vote['ce_protocole']])) {
363
			if (!isset($retour[$vote['ce_image']][$vote['ce_protocole']])) {
358
				$retour[$vote['ce_image']][$vote['ce_protocole']] = $retour_protocole;
364
				$retour[$vote['ce_image']][$vote['ce_protocole']] = $retour_protocole;
359
			}
365
			}
360
			$retour[$vote['ce_image']][$vote['ce_protocole']]['votes'][$vote['id_vote']] = $retour_vote;
366
			$retour[$vote['ce_image']][$vote['ce_protocole']]['votes'][$vote['id_vote']] = $retour_vote;
361
		}
367
		}
362
	
368
	
363
		return $retour;
369
		return $retour;
364
	}
370
	}
365
}
371
}
366
?>
372
?>