Line 26... |
Line 26... |
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->gestionBdd = $conteneur->getGestionBdd();
|
32 |
$this->gestionBdd = $conteneur->getGestionBdd();
|
32 |
$this->bdd = $this->gestionBdd->getBdd();
|
33 |
$this->bdd = $this->gestionBdd->getBdd();
|
Line 33... |
Line 34... |
33 |
}
|
34 |
}
|
Line 65... |
Line 66... |
65 |
* 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
|
66 |
* */
|
67 |
* */
|
67 |
private function configurer($ressources) {
|
68 |
private function configurer($ressources) {
|
68 |
$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
|
69 |
$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
|
69 |
$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
|
70 |
$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
|
- |
|
71 |
$this->mappingCommentaire = $this->conteneur->getParametre('mapping_commentaire');
|
70 |
if (empty($ressources) || sizeof($ressources) > 1 ) {
|
72 |
if (empty($ressources) || sizeof($ressources) > 1 ) {
|
71 |
$e = 'Le service observation accepete 1 et 1 seule ressource';
|
73 |
$e = 'Le service observation accepete 1 et 1 seule ressource';
|
72 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
74 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
73 |
} else {
|
75 |
} else {
|
74 |
$this->id_observation = $ressources[0];
|
76 |
$this->id_observation = $ressources[0];
|
Line 106... |
Line 108... |
106 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
|
108 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
|
107 |
}
|
109 |
}
|
108 |
}
|
110 |
}
|
109 |
}
|
111 |
}
|
Line -... |
Line 112... |
- |
|
112 |
|
- |
|
113 |
if (empty($this->mappingCommentaire)) {
|
- |
|
114 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_commentaire] ou celui-ci est vide ;';
|
- |
|
115 |
} else {
|
- |
|
116 |
$champsMappingCom = array('id_commentaire', 'texte', 'ce_utilisateur', 'utilisateur_nom', 'utilisateur_prenom', 'utilisateur_courriel', 'date');
|
- |
|
117 |
foreach ($champsMappingCom as $champ) {
|
- |
|
118 |
if (!isset($this->mappingCommentaire[$champ])) {
|
- |
|
119 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
|
- |
|
120 |
}
|
- |
|
121 |
}
|
- |
|
122 |
}
|
110 |
|
123 |
|
111 |
if (!empty($erreurs)) {
|
124 |
if (!empty($erreurs)) {
|
112 |
$e = 'Erreur lors de la configuration : '."\n";
|
125 |
$e = 'Erreur lors de la configuration : '."\n";
|
113 |
$e .= implode("\n", $erreurs);
|
126 |
$e .= implode("\n", $erreurs);
|
114 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
127 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
Line 211... |
Line 224... |
211 |
'WHERE ce_observation = '.$observation['id_observation'];
|
224 |
'WHERE ce_observation = '.$observation['id_observation'];
|
212 |
$commentaires = $this->bdd->recupererTous($requeteCommentaires);
|
225 |
$commentaires = $this->bdd->recupererTous($requeteCommentaires);
|
Line 213... |
Line 226... |
213 |
|
226 |
|
214 |
$commentaires_formates = array();
|
227 |
$commentaires_formates = array();
|
- |
|
228 |
foreach ($commentaires as $commentaire) {
|
215 |
foreach ($commentaires as $commentaire) {
|
229 |
$commentaire = $this->formaterCommentaire($commentaire);
|
216 |
if ($commentaire['nom_sel'] != null) {
|
230 |
if ($commentaire['nom_sel'] != null) {
|
217 |
$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
|
231 |
$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
|
218 |
}
|
232 |
}
|
219 |
$commentaires_formates[$commentaire['id_commentaire']] = $commentaire;
|
233 |
$commentaires_formates[$commentaire['id_commentaire']] = $commentaire;
|
Line 228... |
Line 242... |
228 |
$this->gestionBdd->formaterTable('del_commentaire_vote').
|
242 |
$this->gestionBdd->formaterTable('del_commentaire_vote').
|
229 |
'WHERE ce_proposition = '.$this->proteger($id_commentaire);
|
243 |
'WHERE ce_proposition = '.$this->proteger($id_commentaire);
|
230 |
$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
|
244 |
$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
|
231 |
$votes = array();
|
245 |
$votes = array();
|
232 |
foreach ($resultatsVotes as $vote) {
|
246 |
foreach ($resultatsVotes as $vote) {
|
- |
|
247 |
$id_vote = $vote['id_vote'];
|
233 |
$votes[$vote['id_vote']] = $this->formaterVotes($vote);
|
248 |
$votes[$id_vote] = $this->formaterVote($vote);
|
234 |
}
|
249 |
}
|
235 |
return $votes;
|
250 |
return $votes;
|
236 |
}
|
251 |
}
|
Line 296... |
Line 311... |
296 |
return $this->bdd->proteger($valeur);
|
311 |
return $this->bdd->proteger($valeur);
|
297 |
}
|
312 |
}
|
298 |
}
|
313 |
}
|
Line 299... |
Line 314... |
299 |
|
314 |
|
- |
|
315 |
/**
|
- |
|
316 |
*
|
- |
|
317 |
* Formate un commentaire en fonction du fichier de configuration
|
- |
|
318 |
*/
|
- |
|
319 |
private function formaterCommentaire($commentaire) {
|
- |
|
320 |
$commentaire_formate = array();
|
- |
|
321 |
foreach ($this->mappingCommentaire as $nomOriginal => $nomFinal) {
|
- |
|
322 |
$commentaire_formate[$nomFinal] = $commentaire[$nomOriginal];
|
- |
|
323 |
}
|
- |
|
324 |
return $commentaire_formate;
|
- |
|
325 |
}
|
- |
|
326 |
|
300 |
/**
|
327 |
/**
|
301 |
* Formater un vote en fonction du fichier de configuration config_votes.ini
|
328 |
* Formater un vote en fonction du fichier de configuration config_votes.ini
|
302 |
* @param $votes array()
|
329 |
* @param $votes array()
|
303 |
* */
|
330 |
* */
|
304 |
private function formaterVotes($vote) {
|
331 |
private function formaterVote($vote) {
|
305 |
$retour = array();
|
332 |
$retour = array();
|
306 |
foreach ($vote as $param => $valeur) {
|
333 |
foreach ($vote as $param => $valeur) {
|
307 |
$retour[$this->mappingVotes[$param]] = $valeur;
|
334 |
$retour[$this->mappingVotes[$param]] = $valeur;
|
308 |
}
|
335 |
}
|