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