Subversion Repositories eFlore/Applications.del

Rev

Rev 820 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 820 Rev 841
Line 20... Line 20...
20
	
20
	
21
	private $conteneur;
21
	private $conteneur;
22
	private $gestionBdd;
22
	private $gestionBdd;
23
	private $bdd;
23
	private $bdd;
-
 
24
	private $id_observation;
Line 24... Line 25...
24
	private $id_observation;
25
	private $imageIds;
25
	
26
	
26
	public function __construct(Conteneur $conteneur = null) {
27
	public function __construct(Conteneur $conteneur = null) {
-
 
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
27
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
29
		$this->conteneur->chargerConfiguration('config_votes.ini');
28
		$this->conteneur->chargerConfiguration('config_votes.ini');
30
		$this->conteneur->chargerConfiguration('config_mapping_votes.ini');
29
		$this->gestionBdd = $conteneur->getGestionBdd();
31
		$this->gestionBdd = $conteneur->getGestionBdd();
Line 30... Line 32...
30
		$this->bdd = $this->gestionBdd->getBdd();
32
		$this->bdd = $this->gestionBdd->getBdd();
Line 154... Line 156...
154
						 'ON doi.id_image = di.id_image '.
156
						 'ON doi.id_image = di.id_image '.
155
						 'WHERE doi.id_observation = '.$observation['id_observation'];
157
						 'WHERE doi.id_observation = '.$observation['id_observation'];
Line 156... Line 158...
156
			
158
			
157
		$images = $this->bdd->recupererTous($requeteImages);
159
		$images = $this->bdd->recupererTous($requeteImages);
-
 
160
		$images = $this->formaterImages($images);
158
		$images = $this->formaterImages($images);
161
		$images = $this->chargerVotesImage($images);
Line 159... Line 162...
159
		$observation['images'] = $images;
162
		$observation['images'] = $images;
160
		
163
		
Line 161... Line 164...
161
		return $observation;
164
		return $observation;
-
 
165
	}
-
 
166
	
-
 
167
	/**
-
 
168
	* Charger les votes pour chaque image
-
 
169
	* */
-
 
170
	private function chargerVotesImage($images) {
-
 
171
		$requeteVotes = 'SELECT v.*, p.* FROM '.
-
 
172
		$this->gestionBdd->formaterTable('del_image_vote', 'v').
-
 
173
									' INNER JOIN del_image_protocole p '.
-
 
174
										'ON v.ce_protocole = p.id_protocole '.
-
 
175
		$this->chargerClauseWhereVotesImage();
-
 
176
		$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
-
 
177
 
-
 
178
		$votes = $this->formaterVotesImages($resultatsVotes);
-
 
179
 
-
 
180
		foreach ($images as $id => $image) {
-
 
181
			if (isset($votes[$image['id_image']])) {
-
 
182
				foreach($votes[$image['id_image']] as $id_vote => $vote_image) {
-
 
183
					$images[$id]['protocoles_votes'][$id_vote] = $vote_image;
-
 
184
				}
-
 
185
			}
-
 
186
		}
-
 
187
	
-
 
188
		return $images;
-
 
189
	}
-
 
190
	
-
 
191
	private function chargerClauseWhereVotesImage() {
-
 
192
		if (sizeof($this->imageIds) > 0) {
-
 
193
			$chaineImageIds = implode(',', $this->imageIds);
-
 
194
			$where[] = 'v.ce_image  IN ('.$chaineImageIds.')';
-
 
195
		}
-
 
196
		if (isset($this->parametres['protocole'])) {
-
 
197
			$where[] = 'v.ce_protocole = '.$this->proteger($this->parametres['protocole']);
-
 
198
		}
-
 
199
	
-
 
200
		$where = (!empty($where)) ? 'WHERE '.implode(' AND ', $where) : '';
-
 
201
		return $where;
162
	}
202
	}
163
	
203
	
164
	/**
204
	/**
165
	* Récupérer tous les commentaires au total
205
	* Récupérer tous les commentaires au total
Line 166... Line 206...
166
	* @param array $observations la liste des observations à mettre à jour
206
	* @param array $observations la liste des observations à mettre à jour
167
	* */
207
	* */
168
	private function chargerCommentaires($observation) {
208
	private function chargerCommentaires($observation) {
-
 
209
		
-
 
210
		$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
169
		
211
							   'WHERE ce_observation = '.$observation['id_observation'];
170
		$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
212
		$commentaires = $this->bdd->recupererTous($requeteCommentaires);
171
							   'WHERE ce_observation = '.$observation['id_observation'];
213
		
172
		$commentaires = $this->bdd->recupererTous($requeteCommentaires);
214
		$commentaires_formates = array();
173
		foreach ($commentaires as $id=>$commentaire) {
215
		foreach ($commentaires as $commentaire) {
174
			if ($commentaire['nom_sel'] != null) {
216
			if ($commentaire['nom_sel'] != null) {
175
				$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
217
				$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
Line 176... Line 218...
176
			}
218
			}
177
			$commentaires[$id] = $commentaire;
219
			$commentaires_formates[$commentaire['id_commentaire']] = $commentaire;
Line 178... Line 220...
178
		}
220
		}
179
		$observation['commentaires'] = $commentaires;
221
		$observation['commentaires'] = $commentaires_formates;
180
		
222
		
181
		return $observation;
223
		return $observation;
182
	}
224
	}
-
 
225
	
-
 
226
	private function chargerVotes($id_commentaire) {
183
	
227
		$requeteVotes = 'SELECT * FROM '.
-
 
228
			$this->gestionBdd->formaterTable('del_commentaire_vote').
184
	private function chargerVotes($id_commentaire) {
229
			'WHERE ce_proposition = '.$this->proteger($id_commentaire);
185
		$requeteVotes = 'SELECT * FROM '.
230
		$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
Line 186... Line 231...
186
			$this->gestionBdd->formaterTable('del_commentaire_vote').
231
		$votes = array();
Line 200... Line 245...
200
	 * @param array $images les images de l'observation
245
	 * @param array $images les images de l'observation
201
	 * */
246
	 * */
202
	private function formaterImages($images) {
247
	private function formaterImages($images) {
203
		$imagesRetour = array();
248
		$imagesRetour = array();
204
		foreach ($images as $image) {
249
		foreach ($images as $image) {
-
 
250
			
-
 
251
			$this->imageIds[] = $image['id_image'];
205
			$imageCourante = array();
252
			$imageCourante = array();
206
			$imageCourante['id_image'] = $image['id_image'];
253
			$imageCourante['id_image'] = $image['id_image'];
207
			$imageCourante['date'] = $image['date_prise_de_vue'];
254
			$imageCourante['date'] = $image['date_prise_de_vue'];
208
			$imageCourante['binaire.href'] = $this->formaterLienImage($image['id_image']);
255
			$imageCourante['binaire.href'] = $this->formaterLienImage($image['id_image']);
209
			$imageCourante['hauteur'] = $image['hauteur'];
256
			$imageCourante['hauteur'] = $image['hauteur'];
Line 252... Line 299...
252
	
299
	
253
	/**
300
	/**
254
	*  Formater un vote en fonction du fichier de configuration config_votes.ini
301
	*  Formater un vote en fonction du fichier de configuration config_votes.ini
255
	*  @param $votes array()
302
	*  @param $votes array()
256
	* */
303
	* */
-
 
304
	private function formaterVotes($vote) {
-
 
305
		$retour = array();
-
 
306
		foreach ($vote as $param => $valeur) {
-
 
307
			$retour[$this->mappingVotes[$param]] = $valeur;
-
 
308
		}
-
 
309
		return $retour;
-
 
310
	}
-
 
311
	
-
 
312
	/**
-
 
313
	*  Formater une observation depuis une ligne liaison
-
 
314
	*  @param $liaison liaison issue de la recherche
-
 
315
	*  @return $observation l'observation mise en forme
-
 
316
	* */
257
	private function formaterVotes($votes) {
317
	private function formaterVotesImages($votes) {
258
		$retour = array();
318
		$retour = array();
-
 
319
		foreach ($votes as $vote) {
259
		foreach ($votes as $vote) {
320
			$retour_vote = array();
-
 
321
			foreach ($vote as $param=>$valeur) {
-
 
322
				if (strpos($this->mappingVotes[$param], 'protocole.') === 0) {
-
 
323
					$retour_protocole[$this->mappingVotes[$param]] = $valeur;
260
			foreach ($vote as $p=>$valeur) {
324
				} else {
-
 
325
					$retour_vote[$this->mappingVotes[$param]] = $valeur;
-
 
326
				}
-
 
327
			}
-
 
328
			if (!isset($retour[$vote['ce_image']][$vote['ce_protocole']])) {
261
				$retour[$vote['id_vote']][$this->mappingVotes[$p]] = $valeur;
329
				$retour[$vote['ce_image']][$vote['ce_protocole']] = $retour_protocole;
-
 
330
			}
262
			}
331
			$retour[$vote['ce_image']][$vote['ce_protocole']]['votes'][$vote['id_vote']] = $retour_vote;
-
 
332
		}
263
		}
333
	
264
		return $retour;
334
		return $retour;
265
	}
335
	}
266
}
336
}
267
?>
337
?>