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 |
// Lancement du service
|
49 |
// Lancement du service
|
50 |
$liaisons = $this->chargerLiaisons();
|
50 |
$liaisons = $this->chargerLiaisons();
|
51 |
$observation = array();
|
51 |
$observation = array();
|
52 |
|
52 |
|
53 |
if($liaisons) {
|
53 |
if($liaisons) {
|
54 |
$observation = $this->chargerObservation($liaisons);
|
54 |
$observation = $this->chargerObservation($liaisons);
|
55 |
// modifie $observation
|
55 |
// modifie $observation
|
56 |
$this->chargerImages($observation);
|
56 |
$this->chargerImages($observation);
|
57 |
// modifie $observation
|
57 |
// modifie $observation
|
58 |
$this->chargerCommentaires($observation);
|
58 |
$this->chargerCommentaires($observation);
|
59 |
}
|
59 |
}
|
- |
|
60 |
else {
|
- |
|
61 |
header('HTTP/1.0 404 Not Found');
|
- |
|
62 |
// don't die (phpunit)
|
- |
|
63 |
throw(new Exception());
|
- |
|
64 |
}
|
60 |
|
65 |
|
61 |
// Mettre en forme le résultat et l'envoyer pour affichage
|
66 |
// Mettre en forme le résultat et l'envoyer pour affichage
|
62 |
$resultat = new ResultatService();
|
67 |
$resultat = new ResultatService();
|
63 |
$resultat->corps = $observation;
|
68 |
$resultat->corps = $observation;
|
64 |
return $resultat;
|
69 |
return $resultat;
|
65 |
}
|
70 |
}
|
66 |
|
71 |
|
67 |
/*-------------------------------------------------------------------------------
|
72 |
/*-------------------------------------------------------------------------------
|
68 |
CONFIGURATION DU SERVICE
|
73 |
CONFIGURATION DU SERVICE
|
69 |
--------------------------------------------------------------------------------*/
|
74 |
--------------------------------------------------------------------------------*/
|
70 |
/**
|
75 |
/**
|
71 |
* Configuration du service en fonction du fichier de config config_del.ini
|
76 |
* Configuration du service en fonction du fichier de config config_del.ini
|
72 |
* */
|
77 |
* */
|
73 |
private function configurer($ressources) {
|
78 |
private function configurer($ressources) {
|
74 |
$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
|
79 |
$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
|
75 |
$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
|
80 |
$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
|
76 |
$this->mappingCommentaire = $this->conteneur->getParametre('mapping_commentaire');
|
81 |
$this->mappingCommentaire = $this->conteneur->getParametre('mapping_commentaire');
|
77 |
if (empty($ressources) || sizeof($ressources) > 1 ) {
|
82 |
if (empty($ressources) || sizeof($ressources) > 1 ) {
|
78 |
$e = 'Le service observation accepete 1 et 1 seule ressource';
|
83 |
$e = 'Le service observation accepete 1 et 1 seule ressource';
|
79 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
84 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
80 |
} else {
|
85 |
} else {
|
81 |
$this->id_observation = $ressources[0];
|
86 |
$this->id_observation = $ressources[0];
|
82 |
}
|
87 |
}
|
83 |
}
|
88 |
}
|
84 |
|
89 |
|
85 |
/**
|
90 |
/**
|
86 |
* Vérifier que le service est bien configuré
|
91 |
* Vérifier que le service est bien configuré
|
87 |
* */
|
92 |
* */
|
88 |
private function verifierConfiguration() {
|
93 |
private function verifierConfiguration() {
|
89 |
|
94 |
|
90 |
$erreurs = array();
|
95 |
$erreurs = array();
|
91 |
$tableauImages = $this->conteneur->getParametre('observations');
|
96 |
$tableauImages = $this->conteneur->getParametre('observations');
|
92 |
if (empty($tableauImages)) {
|
97 |
if (empty($tableauImages)) {
|
93 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [images] ou celui-ci est vide ;';
|
98 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [images] ou celui-ci est vide ;';
|
94 |
} else {
|
99 |
} else {
|
95 |
if ($this->conteneur->getParametre('url_service') == null) {
|
100 |
if ($this->conteneur->getParametre('url_service') == null) {
|
96 |
$erreurs[] = '- paramètre "url_service" manquant ;';
|
101 |
$erreurs[] = '- paramètre "url_service" manquant ;';
|
97 |
}
|
102 |
}
|
98 |
|
103 |
|
99 |
if ($this->conteneur->getParametre('url_images') == null) {
|
104 |
if ($this->conteneur->getParametre('url_images') == null) {
|
100 |
$erreurs[] = '- paramètre "url_images" manquant ;';
|
105 |
$erreurs[] = '- paramètre "url_images" manquant ;';
|
101 |
}
|
106 |
}
|
102 |
|
107 |
|
103 |
}
|
108 |
}
|
104 |
|
109 |
|
105 |
if (empty($this->mappingObservation)) {
|
110 |
if (empty($this->mappingObservation)) {
|
106 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_observation] ou celui-ci est vide ;';
|
111 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_observation] ou celui-ci est vide ;';
|
107 |
} else {
|
112 |
} else {
|
108 |
$champsMappingObs = array('id_observation', 'date_observation', 'date_transmission', 'famille', 'nom_sel', 'nom_sel_nn', 'nt',
|
113 |
$champsMappingObs = array('id_observation', 'date_observation', 'date_transmission', 'famille', 'nom_sel', 'nom_sel_nn', 'nt',
|
109 |
'ce_zone_geo', 'zone_geo', 'lieudit', 'station', 'courriel', 'ce_utilisateur', 'nom', 'prenom');
|
114 |
'ce_zone_geo', 'zone_geo', 'lieudit', 'station', 'courriel', 'ce_utilisateur', 'nom', 'prenom');
|
110 |
|
115 |
|
111 |
foreach ($champsMappingObs as $champ) {
|
116 |
foreach ($champsMappingObs as $champ) {
|
112 |
if (!isset($this->mappingObservation[$champ])) {
|
117 |
if (!isset($this->mappingObservation[$champ])) {
|
113 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
|
118 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
|
114 |
}
|
119 |
}
|
115 |
}
|
120 |
}
|
116 |
}
|
121 |
}
|
117 |
|
122 |
|
118 |
if (empty($this->mappingCommentaire)) {
|
123 |
if (empty($this->mappingCommentaire)) {
|
119 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_commentaire] ou celui-ci est vide ;';
|
124 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_commentaire] ou celui-ci est vide ;';
|
120 |
} else {
|
125 |
} else {
|
121 |
$champsMappingCom = array('id_commentaire', 'texte', 'ce_utilisateur', 'utilisateur_nom', 'utilisateur_prenom', 'utilisateur_courriel', 'date');
|
126 |
$champsMappingCom = array('id_commentaire', 'texte', 'ce_utilisateur', 'utilisateur_nom', 'utilisateur_prenom', 'utilisateur_courriel', 'date');
|
122 |
foreach ($champsMappingCom as $champ) {
|
127 |
foreach ($champsMappingCom as $champ) {
|
123 |
if (!isset($this->mappingCommentaire[$champ])) {
|
128 |
if (!isset($this->mappingCommentaire[$champ])) {
|
124 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
|
129 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
|
125 |
}
|
130 |
}
|
126 |
}
|
131 |
}
|
127 |
}
|
132 |
}
|
128 |
|
133 |
|
129 |
if (!empty($erreurs)) {
|
134 |
if (!empty($erreurs)) {
|
130 |
$e = 'Erreur lors de la configuration : '."\n";
|
135 |
$e = 'Erreur lors de la configuration : '."\n";
|
131 |
$e .= implode("\n", $erreurs);
|
136 |
$e .= implode("\n", $erreurs);
|
132 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
137 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
133 |
}
|
138 |
}
|
134 |
}
|
139 |
}
|
135 |
|
140 |
|
136 |
/*-------------------------------------------------------------------------------
|
141 |
/*-------------------------------------------------------------------------------
|
137 |
CHARGEMENT DES OBSERVATIONS
|
142 |
CHARGEMENT DES OBSERVATIONS
|
138 |
--------------------------------------------------------------------------------*/
|
143 |
--------------------------------------------------------------------------------*/
|
139 |
/**
|
144 |
/**
|
140 |
* Chargement depuis la bdd de toutes les liaisons entre images et observations
|
145 |
* Chargement depuis la bdd de toutes les liaisons entre images et observations
|
141 |
* */
|
146 |
* */
|
142 |
private function chargerLiaisons() {
|
147 |
private function chargerLiaisons() {
|
143 |
|
148 |
|
144 |
$requeteLiaisons = 'SELECT *, dob.commentaire as dob_commentaire '.
|
149 |
$requeteLiaisons = 'SELECT *, dob.commentaire as dob_commentaire '.
|
145 |
'FROM '.$this->gestionBdd->formaterTable('del_observation', 'dob').
|
150 |
'FROM '.$this->gestionBdd->formaterTable('del_observation', 'dob').
|
146 |
'INNER JOIN '.$this->gestionBdd->formaterTable('del_obs_image', 'doi').
|
151 |
'INNER JOIN '.$this->gestionBdd->formaterTable('del_obs_image', 'doi').
|
147 |
'ON doi.id_observation = dob.id_observation '.
|
152 |
'ON doi.id_observation = dob.id_observation '.
|
148 |
'LEFT JOIN del_utilisateur du '.
|
153 |
'LEFT JOIN del_utilisateur du '.
|
149 |
'ON du.id_utilisateur = dob.ce_utilisateur '.
|
154 |
'ON du.id_utilisateur = dob.ce_utilisateur '.
|
150 |
'WHERE doi.id_observation = '.$this->id_observation;
|
155 |
'WHERE doi.id_observation = '.$this->id_observation;
|
151 |
$requeteLiaisons .= ' GROUP BY doi.id_observation';
|
156 |
$requeteLiaisons .= ' GROUP BY doi.id_observation';
|
152 |
$requeteLiaisons .= ' ORDER BY date_transmission DESC ';
|
157 |
$requeteLiaisons .= ' ORDER BY date_transmission DESC ';
|
153 |
$requeteLiaisons .= $this->gestionBdd->getLimitSql();
|
158 |
$requeteLiaisons .= $this->gestionBdd->getLimitSql();
|
154 |
|
159 |
|
155 |
return $this->bdd->recuperer($requeteLiaisons);
|
160 |
return $this->bdd->recuperer($requeteLiaisons);
|
156 |
}
|
161 |
}
|
157 |
|
162 |
|
158 |
/**
|
163 |
/**
|
159 |
* Retourner un tableau d'images formaté en fonction des liaisons trouvées
|
164 |
* Retourner un tableau d'images formaté en fonction des liaisons trouvées
|
160 |
* @param $liaisons les liaisons de la table del_obs_images
|
165 |
* @param $liaisons les liaisons de la table del_obs_images
|
161 |
* */
|
166 |
* */
|
162 |
private function chargerObservation($liaison) {
|
167 |
private function chargerObservation($liaison) {
|
163 |
|
168 |
|
164 |
if($liaison['ce_utilisateur'] == 0) {
|
169 |
if($liaison['ce_utilisateur'] == 0) {
|
165 |
$liaison['nom'] = $liaison['nom_utilisateur'];
|
170 |
$liaison['nom'] = $liaison['nom_utilisateur'];
|
166 |
$liaison['prenom'] =$liaison['prenom_utilisateur'];
|
171 |
$liaison['prenom'] =$liaison['prenom_utilisateur'];
|
167 |
}
|
172 |
}
|
168 |
|
173 |
|
169 |
$observation = $this->formaterObservation($liaison);
|
174 |
$observation = $this->formaterObservation($liaison);
|
170 |
return $observation;
|
175 |
return $observation;
|
171 |
}
|
176 |
}
|
172 |
|
177 |
|
173 |
/**
|
178 |
/**
|
174 |
* Sélectionner toutes les images de chaque observation
|
179 |
* Sélectionner toutes les images de chaque observation
|
175 |
* @param array $observations la liste des observations
|
180 |
* @param array $observations la liste des observations
|
176 |
* */
|
181 |
* */
|
177 |
private function chargerImages(&$observation) {
|
182 |
private function chargerImages(&$observation) {
|
178 |
$images = $this->bdd->recupererTous(sprintf(
|
183 |
$images = $this->bdd->recupererTous(sprintf(
|
179 |
'SELECT * FROM %s INNER JOIN %s ON doi.id_image = di.id_image WHERE doi.id_observation = %d',
|
184 |
'SELECT * FROM %s INNER JOIN %s ON doi.id_image = di.id_image WHERE doi.id_observation = %d',
|
180 |
$this->gestionBdd->formaterTable('del_obs_image', 'doi'),
|
185 |
$this->gestionBdd->formaterTable('del_obs_image', 'doi'),
|
181 |
$this->gestionBdd->formaterTable('del_image', 'di'),
|
186 |
$this->gestionBdd->formaterTable('del_image', 'di'),
|
182 |
$observation['id_observation']));
|
187 |
$observation['id_observation']));
|
183 |
if(!$images) return;
|
188 |
if(!$images) return;
|
184 |
$images = $this->formaterImages($images);
|
189 |
$images = $this->formaterImages($images);
|
185 |
// modifie $images
|
190 |
// modifie $images
|
186 |
$this->chargerVotesImage($images);
|
191 |
$this->chargerVotesImage($images);
|
187 |
$observation['images'] = $images;
|
192 |
$observation['images'] = $images;
|
188 |
}
|
193 |
}
|
189 |
|
194 |
|
190 |
/**
|
195 |
/**
|
191 |
* Charger les votes pour chaque image
|
196 |
* Charger les votes pour chaque image
|
192 |
* */
|
197 |
* */
|
193 |
private function chargerVotesImage(&$images) {
|
198 |
private function chargerVotesImage(&$images) {
|
194 |
$resultatsVotes = $this->bdd->recupererTous(sprintf(
|
199 |
$resultatsVotes = $this->bdd->recupererTous(sprintf(
|
195 |
'SELECT v.*, p.* FROM %s INNER JOIN del_image_protocole p ON v.ce_protocole = p.id_protocole %s -- %s',
|
200 |
'SELECT v.*, p.* FROM %s INNER JOIN del_image_protocole p ON v.ce_protocole = p.id_protocole %s -- %s',
|
196 |
$this->gestionBdd->formaterTable('del_image_vote', 'v'),
|
201 |
$this->gestionBdd->formaterTable('del_image_vote', 'v'),
|
197 |
$this->chargerClauseWhereVotesImage(),
|
202 |
$this->chargerClauseWhereVotesImage(),
|
198 |
__FILE__ . ':' . __LINE__));
|
203 |
__FILE__ . ':' . __LINE__));
|
199 |
if(!$resultatsVotes) return;
|
204 |
if(!$resultatsVotes) return;
|
200 |
|
205 |
|
201 |
$votes = $this->formaterVotesImages($resultatsVotes);
|
206 |
$votes = $this->formaterVotesImages($resultatsVotes);
|
202 |
foreach ($images as $id => $image) {
|
207 |
foreach ($images as $id => $image) {
|
203 |
if (isset($votes[$image['id_image']])) {
|
208 |
if (isset($votes[$image['id_image']])) {
|
204 |
foreach($votes[$image['id_image']] as $id_vote => $vote_image) {
|
209 |
foreach($votes[$image['id_image']] as $id_vote => $vote_image) {
|
205 |
$images[$id]['protocoles_votes'][$id_vote] = $vote_image;
|
210 |
$images[$id]['protocoles_votes'][$id_vote] = $vote_image;
|
206 |
}
|
211 |
}
|
207 |
}
|
212 |
}
|
208 |
}
|
213 |
}
|
209 |
}
|
214 |
}
|
210 |
|
215 |
|
211 |
private function chargerClauseWhereVotesImage() {
|
216 |
private function chargerClauseWhereVotesImage() {
|
212 |
if (sizeof($this->imageIds) > 0) {
|
217 |
if (sizeof($this->imageIds) > 0) {
|
213 |
$chaineImageIds = implode(',', $this->imageIds);
|
218 |
$chaineImageIds = implode(',', $this->imageIds);
|
214 |
$where[] = 'v.ce_image IN ('.$chaineImageIds.')';
|
219 |
$where[] = 'v.ce_image IN ('.$chaineImageIds.')';
|
215 |
}
|
220 |
}
|
216 |
if (isset($this->parametres['protocole'])) {
|
221 |
if (isset($this->parametres['protocole'])) {
|
217 |
$where[] = 'v.ce_protocole = '.$this->proteger($this->parametres['protocole']);
|
222 |
$where[] = 'v.ce_protocole = '.$this->proteger($this->parametres['protocole']);
|
218 |
}
|
223 |
}
|
219 |
|
224 |
|
220 |
$where = (!empty($where)) ? 'WHERE '.implode(' AND ', $where) : '';
|
225 |
$where = (!empty($where)) ? 'WHERE '.implode(' AND ', $where) : '';
|
221 |
return $where;
|
226 |
return $where;
|
222 |
}
|
227 |
}
|
223 |
|
228 |
|
224 |
/**
|
229 |
/**
|
225 |
* Récupérer tous les commentaires au total
|
230 |
* Récupérer tous les commentaires au total
|
226 |
* @param array $observations la liste des observations à mettre à jour
|
231 |
* @param array $observations la liste des observations à mettre à jour
|
227 |
* */
|
232 |
* */
|
228 |
private function chargerCommentaires(&$observation) {
|
233 |
private function chargerCommentaires(&$observation) {
|
229 |
$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
|
234 |
$requeteCommentaires = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
|
230 |
'WHERE ce_observation = '.$observation['id_observation'];
|
235 |
'WHERE ce_observation = '.$observation['id_observation'];
|
231 |
$commentaires = $this->bdd->recupererTous($requeteCommentaires);
|
236 |
$commentaires = $this->bdd->recupererTous($requeteCommentaires);
|
232 |
if(!$commentaires) return;
|
237 |
if(!$commentaires) return;
|
233 |
|
238 |
|
234 |
$commentaires_formates = array();
|
239 |
$commentaires_formates = array();
|
235 |
foreach ($commentaires as $commentaire) {
|
240 |
foreach ($commentaires as $commentaire) {
|
236 |
$commentaire = $this->formaterCommentaire($commentaire);
|
241 |
$commentaire = $this->formaterCommentaire($commentaire);
|
237 |
if (isset($commentaire['nom_sel']) && $commentaire['nom_sel'] != null) {
|
242 |
if (isset($commentaire['nom_sel']) && $commentaire['nom_sel'] != null) {
|
238 |
$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
|
243 |
$commentaire['votes'] = $this->chargerVotes($commentaire['id_commentaire']);
|
239 |
}
|
244 |
}
|
240 |
$commentaires_formates[$commentaire['id_commentaire']] = $commentaire;
|
245 |
$commentaires_formates[$commentaire['id_commentaire']] = $commentaire;
|
241 |
}
|
246 |
}
|
242 |
$observation['commentaires'] = $commentaires_formates;
|
247 |
$observation['commentaires'] = $commentaires_formates;
|
243 |
}
|
248 |
}
|
244 |
|
249 |
|
245 |
private function chargerVotes($id_commentaire) {
|
250 |
private function chargerVotes($id_commentaire) {
|
246 |
$requeteVotes = 'SELECT * FROM '.
|
251 |
$requeteVotes = 'SELECT * FROM '.
|
247 |
$this->gestionBdd->formaterTable('del_commentaire_vote').
|
252 |
$this->gestionBdd->formaterTable('del_commentaire_vote').
|
248 |
'WHERE ce_proposition = '.$this->proteger($id_commentaire);
|
253 |
'WHERE ce_proposition = '.$this->proteger($id_commentaire);
|
249 |
$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
|
254 |
$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
|
250 |
$votes = array();
|
255 |
$votes = array();
|
251 |
foreach ($resultatsVotes as $vote) {
|
256 |
foreach ($resultatsVotes as $vote) {
|
252 |
$id_vote = $vote['id_vote'];
|
257 |
$id_vote = $vote['id_vote'];
|
253 |
$votes[$id_vote] = $this->formaterVote($vote);
|
258 |
$votes[$id_vote] = $this->formaterVote($vote);
|
254 |
}
|
259 |
}
|
255 |
return $votes;
|
260 |
return $votes;
|
256 |
}
|
261 |
}
|
257 |
|
262 |
|
258 |
|
263 |
|
259 |
/*-------------------------------------------------------------------------------
|
264 |
/*-------------------------------------------------------------------------------
|
260 |
FORMATER ET METTRE EN FORME
|
265 |
FORMATER ET METTRE EN FORME
|
261 |
--------------------------------------------------------------------------------*/
|
266 |
--------------------------------------------------------------------------------*/
|
262 |
|
267 |
|
263 |
/**
|
268 |
/**
|
264 |
* Formater les images d'une observation
|
269 |
* Formater les images d'une observation
|
265 |
* @param array $images les images de l'observation
|
270 |
* @param array $images les images de l'observation
|
266 |
* // TODO: en faire le maximum dans le SELECT
|
271 |
* // TODO: en faire le maximum dans le SELECT
|
267 |
* */
|
272 |
* */
|
268 |
private function formaterImages($images) {
|
273 |
private function formaterImages($images) {
|
269 |
$imagesRetour = array();
|
274 |
$imagesRetour = array();
|
270 |
foreach ($images as $image) {
|
275 |
foreach ($images as $image) {
|
271 |
|
276 |
|
272 |
$this->imageIds[] = $image['id_image'];
|
277 |
$this->imageIds[] = $image['id_image'];
|
273 |
$imageCourante = array();
|
278 |
$imageCourante = array();
|
274 |
$imageCourante['id_image'] = $image['id_image'];
|
279 |
$imageCourante['id_image'] = $image['id_image'];
|
275 |
$imageCourante['date'] = $image['date_prise_de_vue'];
|
280 |
$imageCourante['date'] = $image['date_prise_de_vue'];
|
276 |
$imageCourante['binaire.href'] = $this->formaterLienImage($image['id_image']);
|
281 |
$imageCourante['binaire.href'] = $this->formaterLienImage($image['id_image']);
|
277 |
$imageCourante['hauteur'] = $image['hauteur'];
|
282 |
$imageCourante['hauteur'] = $image['hauteur'];
|
278 |
$imageRetour['largeur'] = $image['largeur'];
|
283 |
$imageRetour['largeur'] = $image['largeur'];
|
279 |
|
284 |
|
280 |
$imagesRetour[] = $imageCourante;
|
285 |
$imagesRetour[] = $imageCourante;
|
281 |
}
|
286 |
}
|
282 |
|
287 |
|
283 |
return $imagesRetour;
|
288 |
return $imagesRetour;
|
284 |
}
|
289 |
}
|
285 |
|
290 |
|
286 |
/**
|
291 |
/**
|
287 |
* Formater une observation depuis une ligne liaison
|
292 |
* Formater une observation depuis une ligne liaison
|
288 |
* @param $liaison liaison issue de la recherche
|
293 |
* @param $liaison liaison issue de la recherche
|
289 |
* @return $observation l'observation mise en forme
|
294 |
* @return $observation l'observation mise en forme
|
290 |
* */
|
295 |
* */
|
291 |
private function formaterObservation($liaison) {
|
296 |
private function formaterObservation($liaison) {
|
292 |
$observation = array();
|
297 |
$observation = array();
|
293 |
|
298 |
|
294 |
foreach ($this->mappingObservation as $nomOriginal => $nomFinal) {
|
299 |
foreach ($this->mappingObservation as $nomOriginal => $nomFinal) {
|
295 |
$observation[$nomFinal] = $liaison[$nomOriginal];
|
300 |
$observation[$nomFinal] = $liaison[$nomOriginal];
|
296 |
}
|
301 |
}
|
297 |
|
302 |
|
298 |
$observation['images'] = array();
|
303 |
$observation['images'] = array();
|
299 |
|
304 |
|
300 |
return $observation;
|
305 |
return $observation;
|
301 |
}
|
306 |
}
|
302 |
|
307 |
|
303 |
/**
|
308 |
/**
|
304 |
* Formater le lien de l'image en fonction du fichier de config et de l'identifiant de l'image
|
309 |
* Formater le lien de l'image en fonction du fichier de config et de l'identifiant de l'image
|
305 |
* */
|
310 |
* */
|
306 |
private function formaterLienImage($idImage) {
|
311 |
private function formaterLienImage($idImage) {
|
307 |
$idImage = sprintf('%09s', $idImage);
|
312 |
$idImage = sprintf('%09s', $idImage);
|
308 |
$url = $this->conteneur->getParametre('url_images');
|
313 |
$url = $this->conteneur->getParametre('url_images');
|
309 |
$urlImage = str_replace('%s', $idImage, $url);
|
314 |
$urlImage = str_replace('%s', $idImage, $url);
|
310 |
return $urlImage;
|
315 |
return $urlImage;
|
311 |
}
|
316 |
}
|
312 |
|
317 |
|
313 |
private function proteger($valeur) {
|
318 |
private function proteger($valeur) {
|
314 |
if (is_array($valeur)) {
|
319 |
if (is_array($valeur)) {
|
315 |
return $this->bdd->protegerTableau($valeur);
|
320 |
return $this->bdd->protegerTableau($valeur);
|
316 |
} else {
|
321 |
} else {
|
317 |
return $this->bdd->proteger($valeur);
|
322 |
return $this->bdd->proteger($valeur);
|
318 |
}
|
323 |
}
|
319 |
}
|
324 |
}
|
320 |
|
325 |
|
321 |
/**
|
326 |
/**
|
322 |
*
|
327 |
*
|
323 |
* Formate un commentaire en fonction du fichier de configuration
|
328 |
* Formate un commentaire en fonction du fichier de configuration
|
324 |
*/
|
329 |
*/
|
325 |
private function formaterCommentaire($commentaire) {
|
330 |
private function formaterCommentaire($commentaire) {
|
326 |
$commentaire_formate = array();
|
331 |
$commentaire_formate = array();
|
327 |
foreach ($this->mappingCommentaire as $nomOriginal => $nomFinal) {
|
332 |
foreach ($this->mappingCommentaire as $nomOriginal => $nomFinal) {
|
328 |
if (isset($commentaire[$nomOriginal])) {
|
333 |
if (isset($commentaire[$nomOriginal])) {
|
329 |
$commentaire_formate[$nomFinal] = $commentaire[$nomOriginal];
|
334 |
$commentaire_formate[$nomFinal] = $commentaire[$nomOriginal];
|
330 |
}
|
335 |
}
|
331 |
}
|
336 |
}
|
332 |
return $commentaire_formate;
|
337 |
return $commentaire_formate;
|
333 |
}
|
338 |
}
|
334 |
|
339 |
|
335 |
/**
|
340 |
/**
|
336 |
* Formater un vote en fonction du fichier de configuration config_votes.ini
|
341 |
* Formater un vote en fonction du fichier de configuration config_votes.ini
|
337 |
* @param $votes array()
|
342 |
* @param $votes array()
|
338 |
* */
|
343 |
* */
|
339 |
private function formaterVote($vote) {
|
344 |
private function formaterVote($vote) {
|
340 |
$retour = array();
|
345 |
$retour = array();
|
341 |
foreach ($vote as $param => $valeur) {
|
346 |
foreach ($vote as $param => $valeur) {
|
342 |
$retour[$this->mappingVotes[$param]] = $valeur;
|
347 |
$retour[$this->mappingVotes[$param]] = $valeur;
|
343 |
}
|
348 |
}
|
344 |
return $retour;
|
349 |
return $retour;
|
345 |
}
|
350 |
}
|
346 |
|
351 |
|
347 |
/**
|
352 |
/**
|
348 |
* Formater une observation depuis une ligne liaison
|
353 |
* Formater une observation depuis une ligne liaison
|
349 |
* @param $liaison liaison issue de la recherche
|
354 |
* @param $liaison liaison issue de la recherche
|
350 |
* @return $observation l'observation mise en forme
|
355 |
* @return $observation l'observation mise en forme
|
351 |
* */
|
356 |
* */
|
352 |
private function formaterVotesImages($votes) {
|
357 |
private function formaterVotesImages($votes) {
|
353 |
$retour = array();
|
358 |
$retour = array();
|
354 |
foreach ($votes as $vote) {
|
359 |
foreach ($votes as $vote) {
|
355 |
$retour_vote = array();
|
360 |
$retour_vote = array();
|
356 |
foreach ($vote as $param=>$valeur) {
|
361 |
foreach ($vote as $param=>$valeur) {
|
357 |
if (strpos($this->mappingVotes[$param], 'protocole.') === 0) {
|
362 |
if (strpos($this->mappingVotes[$param], 'protocole.') === 0) {
|
358 |
$retour_protocole[$this->mappingVotes[$param]] = $valeur;
|
363 |
$retour_protocole[$this->mappingVotes[$param]] = $valeur;
|
359 |
} else {
|
364 |
} else {
|
360 |
$retour_vote[$this->mappingVotes[$param]] = $valeur;
|
365 |
$retour_vote[$this->mappingVotes[$param]] = $valeur;
|
361 |
}
|
366 |
}
|
362 |
}
|
367 |
}
|
363 |
if (!isset($retour[$vote['ce_image']][$vote['ce_protocole']])) {
|
368 |
if (!isset($retour[$vote['ce_image']][$vote['ce_protocole']])) {
|
364 |
$retour[$vote['ce_image']][$vote['ce_protocole']] = $retour_protocole;
|
369 |
$retour[$vote['ce_image']][$vote['ce_protocole']] = $retour_protocole;
|
365 |
}
|
370 |
}
|
366 |
$retour[$vote['ce_image']][$vote['ce_protocole']]['votes'][$vote['id_vote']] = $retour_vote;
|
371 |
$retour[$vote['ce_image']][$vote['ce_protocole']]['votes'][$vote['id_vote']] = $retour_vote;
|
367 |
}
|
372 |
}
|
368 |
|
373 |
|
369 |
return $retour;
|
374 |
return $retour;
|
370 |
}
|
375 |
}
|
371 |
}
|
376 |
}
|
372 |
?>
|
377 |
?>
|