Subversion Repositories eFlore/Applications.del

Rev

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

Rev 772 Rev 787
Line 23... Line 23...
23
	private $bdd;
23
	private $bdd;
24
	private $id_observation;
24
	private $id_observation;
Line 25... Line 25...
25
	
25
	
26
	public function __construct(Conteneur $conteneur = null) {
26
	public function __construct(Conteneur $conteneur = null) {
-
 
27
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
27
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
28
		$this->conteneur->chargerConfiguration('config_votes.ini');
28
		$this->gestionBdd = $conteneur->getGestionBdd();
29
		$this->gestionBdd = $conteneur->getGestionBdd();
29
		$this->bdd = $this->gestionBdd->getBdd();
30
		$this->bdd = $this->gestionBdd->getBdd();
Line 30... Line 31...
30
	}
31
	}
Line 61... Line 62...
61
	/**
62
	/**
62
	 * Configuration du service en fonction du fichier de config config_del.ini
63
	 * Configuration du service en fonction du fichier de config config_del.ini
63
	 * */
64
	 * */
64
	private function configurer($ressources) {
65
	private function configurer($ressources) {
65
		$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
66
		$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
-
 
67
		$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
66
		if (empty($ressources) || sizeof($ressources) > 1 ) {
68
		if (empty($ressources) || sizeof($ressources) > 1 ) {
67
			$e = 'Le service observation accepete 1 et 1 seule ressource';
69
			$e = 'Le service observation accepete 1 et 1 seule ressource';
68
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
70
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
69
		} else {
71
		} else {
70
			$this->id_observation = $ressources[0];
72
			$this->id_observation = $ressources[0];
Line 166... Line 168...
166
	private function chargerCommentaires($observation) {
168
	private function chargerCommentaires($observation) {
Line 167... Line 169...
167
		
169
		
168
		$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
170
		$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
169
							   'WHERE ce_observation = '.$observation['id_observation'];
171
							   'WHERE ce_observation = '.$observation['id_observation'];
-
 
172
		$commentaires = $this->bdd->recupererTous($requeteCommentaires);
-
 
173
		foreach ($commentaires as $id=>$commentaire) {
-
 
174
			if ($commentaire['nom_sel'] != null) {
-
 
175
				$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
-
 
176
			}
-
 
177
			$commentaires[$id] = $commentaire;
170
		$commentaires = $this->bdd->recupererTous($requeteCommentaires);
178
		}
Line 171... Line 179...
171
		$observation['commentaires'] = $commentaires;
179
		$observation['commentaires'] = $commentaires;
172
		
180
		
Line -... Line 181...
-
 
181
		return $observation;
-
 
182
	}
-
 
183
	
-
 
184
	private function chargerVotes($id_commentaire) {
-
 
185
		$requeteVotes = 'SELECT * FROM '.
-
 
186
			$this->gestionBdd->formaterTable('del_commentaire_vote').
-
 
187
			'WHERE ce_proposition = '.$this->proteger($id_commentaire);
-
 
188
		$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
Line 173... Line 189...
173
		return $observation;
189
		$votes = $this->formaterVotes($resultatsVotes);
174
	}
190
		return $votes;
175
	
191
	}
Line 231... Line 247...
231
			return $this->bdd->protegerTableau($valeur);
247
			return $this->bdd->protegerTableau($valeur);
232
		} else {
248
		} else {
233
			return $this->bdd->proteger($valeur);
249
			return $this->bdd->proteger($valeur);
234
		}
250
		}
235
	}
251
	}
-
 
252
	
-
 
253
	/**
-
 
254
	*  Formater un vote en fonction du fichier de configuration config_votes.ini
-
 
255
	*  @param $votes array()
-
 
256
	* */
-
 
257
	private function formaterVotes($votes) {
-
 
258
		$retour = array();
-
 
259
		foreach ($votes as $vote) {
-
 
260
			foreach ($vote as $p=>$valeur) {
-
 
261
				$retour[$vote['id_vote']][$this->mappingVotes[$p]] = $valeur;
-
 
262
			}
-
 
263
		}
-
 
264
		return $retour;
-
 
265
	}
236
}
266
}
237
?>
267
?>
238
268