720 |
gduche |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
737 |
gduche |
4 |
* Le web service observations récupère toutes les observations et, pour chacune d'elle, les
|
|
|
5 |
* images qui lui sont associées.
|
720 |
gduche |
6 |
*
|
|
|
7 |
* @category php 5.2
|
|
|
8 |
* @package del
|
|
|
9 |
* @subpackage images
|
|
|
10 |
* @author Jean-Pascal MILCENT <jpm@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
|
|
|
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 $
|
737 |
gduche |
15 |
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=ApiIdentiplante01Observations
|
720 |
gduche |
16 |
*/
|
|
|
17 |
|
755 |
gduche |
18 |
class ListeObservations {
|
720 |
gduche |
19 |
|
755 |
gduche |
20 |
|
720 |
gduche |
21 |
private $conteneur;
|
726 |
gduche |
22 |
private $navigation;
|
|
|
23 |
private $masque;
|
737 |
gduche |
24 |
private $gestionBdd;
|
|
|
25 |
private $bdd;
|
797 |
aurelien |
26 |
private $parametres = array();
|
|
|
27 |
private $ressources = array();
|
720 |
gduche |
28 |
|
|
|
29 |
public function __construct(Conteneur $conteneur = null) {
|
|
|
30 |
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
|
790 |
aurelien |
31 |
$this->conteneur->chargerConfiguration('config_departements_bruts.ini');
|
776 |
aurelien |
32 |
$this->conteneur->chargerConfiguration('config_observations.ini');
|
797 |
aurelien |
33 |
$this->conteneur->chargerConfiguration('config_mapping_votes.ini');
|
726 |
gduche |
34 |
$this->navigation = $conteneur->getNavigation();
|
|
|
35 |
$this->masque = $conteneur->getMasque();
|
737 |
gduche |
36 |
$this->gestionBdd = $conteneur->getGestionBdd();
|
|
|
37 |
$this->bdd = $this->gestionBdd->getBdd();
|
720 |
gduche |
38 |
}
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Méthode principale de la classe.
|
|
|
42 |
* Lance la récupération des images dans la base et les place dans un objet ResultatService
|
|
|
43 |
* pour l'afficher.
|
|
|
44 |
* @param array $ressources les ressources situées après l'url de base (ex : http://url/ressource1/ressource2)
|
|
|
45 |
* @param array $parametres les paramètres situés après le ? dans l'url
|
|
|
46 |
* */
|
|
|
47 |
public function consulter($ressources, $parametres) {
|
797 |
aurelien |
48 |
$this->initialiserRessourcesEtParametres($ressources, $parametres);
|
720 |
gduche |
49 |
|
|
|
50 |
// Gestion des configuration du script
|
|
|
51 |
$this->configurer();
|
|
|
52 |
$this->verifierConfiguration();
|
|
|
53 |
|
|
|
54 |
// Lancement du service
|
|
|
55 |
$liaisons = $this->chargerLiaisons();
|
737 |
gduche |
56 |
$total = $this->compterObservations();
|
726 |
gduche |
57 |
$this->navigation->setTotal($total);
|
755 |
gduche |
58 |
$observations = $this->chargerObservations($liaisons);
|
|
|
59 |
$observations = $this->chargerImages($observations);
|
|
|
60 |
$observations = $this->chargerDeterminations($observations);
|
720 |
gduche |
61 |
|
|
|
62 |
// Mettre en forme le résultat et l'envoyer pour affichage
|
|
|
63 |
$resultat = new ResultatService();
|
755 |
gduche |
64 |
$resultat->corps = array('entete' => $this->conteneur->getEntete(), 'resultats' => $observations);
|
720 |
gduche |
65 |
return $resultat;
|
|
|
66 |
}
|
|
|
67 |
|
797 |
aurelien |
68 |
private function initialiserRessourcesEtParametres($ressources, $parametres) {
|
|
|
69 |
$this->ressources = $ressources;
|
|
|
70 |
$this->parametres = $parametres;
|
|
|
71 |
}
|
720 |
gduche |
72 |
/*-------------------------------------------------------------------------------
|
|
|
73 |
CONFIGURATION DU SERVICE
|
|
|
74 |
--------------------------------------------------------------------------------*/
|
|
|
75 |
/**
|
|
|
76 |
* Configuration du service en fonction du fichier de config config_del.ini
|
|
|
77 |
* */
|
755 |
gduche |
78 |
private function configurer() {
|
720 |
gduche |
79 |
$this->mappingFiltre = $this->conteneur->getParametre('mapping_masque');
|
|
|
80 |
$this->mappingObservation = $this->conteneur->getParametre('mapping_observation');
|
787 |
delphine |
81 |
$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
|
720 |
gduche |
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Vérifier que le service est bien configuré
|
|
|
86 |
* */
|
755 |
gduche |
87 |
private function verifierConfiguration() {
|
737 |
gduche |
88 |
|
720 |
gduche |
89 |
$erreurs = array();
|
755 |
gduche |
90 |
$tableauObservations = $this->conteneur->getParametre('observations');
|
|
|
91 |
if (empty($tableauObservations)) {
|
720 |
gduche |
92 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [images] ou celui-ci est vide ;';
|
|
|
93 |
} else {
|
737 |
gduche |
94 |
if ($this->conteneur->getParametre('url_service') == null) {
|
720 |
gduche |
95 |
$erreurs[] = '- paramètre "url_service" manquant ;';
|
|
|
96 |
}
|
|
|
97 |
|
737 |
gduche |
98 |
if ($this->conteneur->getParametre('url_images') == null) {
|
720 |
gduche |
99 |
$erreurs[] = '- paramètre "url_images" manquant ;';
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
if (empty($this->mappingObservation)) {
|
|
|
105 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_observation] ou celui-ci est vide ;';
|
|
|
106 |
} else {
|
|
|
107 |
$champsMappingObs = array('id_observation', 'date_observation', 'date_transmission', 'famille', 'nom_sel', 'nom_sel_nn', 'nt',
|
737 |
gduche |
108 |
'ce_zone_geo', 'zone_geo', 'lieudit', 'station', 'courriel', 'ce_utilisateur', 'nom', 'prenom');
|
|
|
109 |
|
720 |
gduche |
110 |
foreach ($champsMappingObs as $champ) {
|
|
|
111 |
if (!isset($this->mappingObservation[$champ])) {
|
|
|
112 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
if (empty($this->mappingFiltre)) {
|
|
|
118 |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_masque] ou celui-ci est vide ;';
|
|
|
119 |
} else {
|
|
|
120 |
$champsMappingFiltre = array('famille', 'ns', 'nn', 'date', 'tag', 'commune');
|
|
|
121 |
foreach ($champsMappingFiltre as $champ) {
|
|
|
122 |
if (!isset($this->mappingFiltre[$champ])) {
|
|
|
123 |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour l\'observation est manquant ;';
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
if (!empty($erreurs)) {
|
|
|
129 |
$e = 'Erreur lors de la configuration : '."\n";
|
|
|
130 |
$e .= implode("\n", $erreurs);
|
|
|
131 |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
|
737 |
gduche |
132 |
}
|
720 |
gduche |
133 |
}
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Obtenir une chaine de caractère concaténant nom et prénom séparé par une virgule
|
|
|
139 |
* @param String $auteurId l'identifiant de l'auteur
|
|
|
140 |
* @return String la chaine de concaténation
|
|
|
141 |
* */
|
|
|
142 |
private function getChaineNomPrenom($auteurId) {
|
|
|
143 |
$nomPrenom = explode(' ', $auteurId);
|
|
|
144 |
$nomPrenom = $this->proteger($nomPrenom);
|
|
|
145 |
$chaineNomPrenom = implode(', ', $nomPrenom);
|
|
|
146 |
return $chaineNomPrenom;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* Charger la clause WHERE en fonction des paramètres de masque
|
|
|
151 |
* */
|
|
|
152 |
private function chargerClauseWhere() {
|
|
|
153 |
$where = array();
|
737 |
gduche |
154 |
$tableauMasque = $this->masque->getMasque();
|
|
|
155 |
if (!empty($tableauMasque)) {
|
|
|
156 |
foreach($tableauMasque as $idMasque => $valeurMasque) {
|
|
|
157 |
|
|
|
158 |
$idMasque = str_replace('masque.', '', $idMasque);
|
|
|
159 |
switch ($idMasque) {
|
|
|
160 |
// nom du masque => nom BDD
|
|
|
161 |
case 'auteur' :
|
797 |
aurelien |
162 |
$whereAuteur = ' '.$this->creerFiltreAuteur($this->masque->getMasque('auteur'));
|
|
|
163 |
if($whereAuteur != '') {
|
|
|
164 |
$where[] = $whereAuteur;
|
|
|
165 |
}
|
737 |
gduche |
166 |
break;
|
790 |
aurelien |
167 |
case 'date' :
|
797 |
aurelien |
168 |
$whereDate = ' '.$this->creerFiltreDate($valeurMasque);
|
|
|
169 |
if($whereDate != '') {
|
|
|
170 |
$where[] = $whereDate;
|
|
|
171 |
}
|
790 |
aurelien |
172 |
break;
|
737 |
gduche |
173 |
case 'departement' :
|
797 |
aurelien |
174 |
$where[] = ' '.$this->creerFiltreIdZoneGeo($valeurMasque);
|
737 |
gduche |
175 |
break;
|
|
|
176 |
case 'genre' :
|
744 |
gduche |
177 |
$where[] = ' '.$this->mappingFiltre['ns'].' LIKE '.$this->proteger('%'.$valeurMasque.'% %');
|
737 |
gduche |
178 |
break;
|
|
|
179 |
case 'tag' :
|
797 |
aurelien |
180 |
$where[] = ' '.$this->creerFiltreMotsCles($valeurMasque);
|
737 |
gduche |
181 |
break;
|
776 |
aurelien |
182 |
case 'ns' :
|
797 |
aurelien |
183 |
$where[] = ' nom_sel LIKE '.$this->proteger($valeurMasque.'%');
|
|
|
184 |
break;
|
790 |
aurelien |
185 |
case 'commune' :
|
797 |
aurelien |
186 |
$where[] = ' '.$this->mappingFiltre[$idMasque].' LIKE '.$this->proteger(str_replace(array('-',' '), '_', $valeurMasque).'%');
|
790 |
aurelien |
187 |
break;
|
|
|
188 |
case 'masque' :
|
797 |
aurelien |
189 |
$where[] = ' '.$this->creerFiltreMasqueGeneral($valeurMasque);
|
790 |
aurelien |
190 |
break;
|
737 |
gduche |
191 |
default:
|
797 |
aurelien |
192 |
$where[] = ' '.$this->mappingFiltre[$idMasque].' = '.$this->proteger($valeurMasque);
|
|
|
193 |
break;
|
737 |
gduche |
194 |
}
|
|
|
195 |
}
|
720 |
gduche |
196 |
}
|
|
|
197 |
|
|
|
198 |
if (!empty($where)) {
|
|
|
199 |
return ' WHERE '.implode('AND', $where);
|
|
|
200 |
} else {
|
|
|
201 |
return;
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
|
790 |
aurelien |
205 |
private function creerFiltreMasqueGeneral($valeurMasque) {
|
797 |
aurelien |
206 |
//TODO: affecter d'aborder les variables, puis les tester pour les
|
|
|
207 |
// ajouter à la chaine
|
790 |
aurelien |
208 |
$whereAuteur = $this->creerFiltreAuteur($valeurMasque);
|
797 |
aurelien |
209 |
$whereIdZoneGeo = $this->creerFiltreIdZoneGeo($valeurMasque);
|
|
|
210 |
|
790 |
aurelien |
211 |
$masqueGeneral = '( '.
|
797 |
aurelien |
212 |
(($whereAuteur != '') ? $whereAuteur.' OR ' : '' ).
|
|
|
213 |
(($whereIdZoneGeo != '') ? $whereIdZoneGeo.' OR ' : '' ).
|
|
|
214 |
'zone_geo LIKE '.$this->proteger($this->remplacerParJokerCaractere($valeurMasque).'%').' OR '.
|
|
|
215 |
$this->creerFiltreMotsCles($valeurMasque).' OR '.
|
|
|
216 |
'nom_sel LIKE '.$this->proteger($valeurMasque.'%').' OR '.
|
|
|
217 |
'famille LIKE '.$this->proteger($valeurMasque.'%').' OR '.
|
|
|
218 |
'milieu LIKE '.$this->proteger($valeurMasque).' OR '.
|
|
|
219 |
$this->mappingFiltre['ns'].' LIKE '.$this->proteger('%'.$valeurMasque.'% %').' OR '.
|
|
|
220 |
$this->creerFiltreDate($valeurMasque).
|
|
|
221 |
') ';
|
790 |
aurelien |
222 |
|
|
|
223 |
return $masqueGeneral;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
private function creerFiltreAuteur($valeurMasque) {
|
|
|
227 |
$masque = '';
|
|
|
228 |
$auteurId = $valeurMasque;
|
|
|
229 |
if (is_numeric($auteurId)) {
|
|
|
230 |
$masque = ' ce_utilisateur = '.$auteurId;
|
|
|
231 |
} else {
|
|
|
232 |
if (strpos($auteurId, '@') === false) {
|
|
|
233 |
$tableauNomPrenom = explode(' ',$auteurId, 2);
|
|
|
234 |
if(count($tableauNomPrenom) == 2) {
|
|
|
235 |
// on teste potentiellement un nom prenom ou bien un prénom nom
|
|
|
236 |
$masque = '('.
|
797 |
aurelien |
237 |
'(nom LIKE '.$this->proteger($tableauNomPrenom[0].'%').' AND '.
|
|
|
238 |
'prenom LIKE '.$this->proteger($tableauNomPrenom[1].'%').') OR '.
|
|
|
239 |
'(nom LIKE '.$this->proteger($tableauNomPrenom[1].'%').' AND '.
|
|
|
240 |
'prenom LIKE '.$this->proteger($tableauNomPrenom[0].'%').')'.
|
|
|
241 |
')';
|
790 |
aurelien |
242 |
} else {
|
|
|
243 |
$masque = '(
|
797 |
aurelien |
244 |
(nom LIKE '.$this->proteger($auteurId.'%').' OR '.
|
|
|
245 |
'prenom LIKE '.$this->proteger($auteurId.'%').')'.
|
|
|
246 |
')';
|
790 |
aurelien |
247 |
}
|
|
|
248 |
} else {
|
|
|
249 |
$masque = " courriel LIKE ".$this->proteger($valeurMasque.'%')." ";
|
|
|
250 |
}
|
|
|
251 |
}
|
|
|
252 |
return $masque;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
private function remplacerParJokerCaractere($valeurMasque) {
|
|
|
256 |
return str_replace(array('-',' '), '_', $valeurMasque);
|
|
|
257 |
}
|
797 |
aurelien |
258 |
//TODO: déplacer les fonctions ci dessus et dessous dans une classe
|
790 |
aurelien |
259 |
// utilitaire
|
|
|
260 |
function supprimerAccents($str, $charset='utf-8')
|
|
|
261 |
{
|
|
|
262 |
$str = htmlentities($str, ENT_NOQUOTES, $charset);
|
|
|
263 |
|
|
|
264 |
$str = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
|
|
|
265 |
$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. 'œ'
|
|
|
266 |
$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
|
|
|
267 |
|
|
|
268 |
return $str;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
private function obtenirIdDepartement($nomDpt) {
|
797 |
aurelien |
272 |
|
790 |
aurelien |
273 |
$nomDpt = $this->supprimerAccents($nomDpt);
|
|
|
274 |
$nomDpt = strtolower(str_replace(' ','-',$nomDpt));
|
797 |
aurelien |
275 |
|
790 |
aurelien |
276 |
$idDpt = $this->conteneur->getParametre($nomDpt);
|
|
|
277 |
if($idDpt == null || $idDpt == ' ') {
|
|
|
278 |
$idDpt = ' ';
|
|
|
279 |
}
|
|
|
280 |
return $idDpt;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
private function creerFiltreIdZoneGeo($valeurMasque) {
|
|
|
284 |
$masque = '';
|
|
|
285 |
$dept = $valeurMasque;
|
|
|
286 |
if (is_numeric($dept)) {
|
|
|
287 |
$dept = sprintf('%02s', $dept);
|
|
|
288 |
$dept = sprintf("%-'_5s", $dept);
|
|
|
289 |
$masque = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$dept);
|
|
|
290 |
} else {
|
|
|
291 |
$deptId = $this->conteneur->getParametre($dept);
|
|
|
292 |
if ($deptId != null) {
|
|
|
293 |
$masque = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$deptId.'%');
|
|
|
294 |
} else {
|
|
|
295 |
$id = $this->obtenirIdDepartement($valeurMasque);
|
|
|
296 |
$masque = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$id.'%');
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
return $masque;
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
private function creerFiltreDate($valeurMasque) {
|
|
|
303 |
//TODO: définir dans le fichier de config un tableau contenant plusieurs format de date
|
|
|
304 |
// autorisés pour la recherche, qui seraient ajoutés au OR
|
|
|
305 |
$masque = '(';
|
|
|
306 |
$masque .= (is_numeric($valeurMasque)) ? ' YEAR(date_observation) = '.$this->proteger($valeurMasque).' OR ' : '';
|
|
|
307 |
$masque .= " DATE_FORMAT(date_observation, '%d/%m/%Y') = ".$this->proteger($valeurMasque).' '.
|
797 |
aurelien |
308 |
')';
|
790 |
aurelien |
309 |
return $masque;
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
private function creerFiltreMotsCles($valeurMasque) {
|
|
|
313 |
$masque = '(di.mots_cles_texte LIKE '.$this->proteger('%'.$valeurMasque.'%').' OR '.
|
797 |
aurelien |
314 |
' dob.mots_cles_texte LIKE '.$this->proteger('%'.$valeurMasque.'%').') ';
|
|
|
315 |
return $masque;
|
790 |
aurelien |
316 |
}
|
|
|
317 |
|
720 |
gduche |
318 |
/*-------------------------------------------------------------------------------
|
745 |
gduche |
319 |
CHARGEMENT DES OBSERVATIONS
|
720 |
gduche |
320 |
--------------------------------------------------------------------------------*/
|
|
|
321 |
/**
|
|
|
322 |
* Chargement depuis la bdd de toutes les liaisons entre images et observations
|
|
|
323 |
* */
|
|
|
324 |
private function chargerLiaisons() {
|
797 |
aurelien |
325 |
|
|
|
326 |
$requeteLiaisons = 'SELECT SQL_CALC_FOUND_ROWS * '.
|
737 |
gduche |
327 |
'FROM '.$this->gestionBdd->formaterTable('del_observation', 'dob').
|
766 |
aurelien |
328 |
'INNER JOIN '.$this->gestionBdd->formaterTable('del_obs_image', 'doi').
|
737 |
gduche |
329 |
'ON doi.id_observation = dob.id_observation '.
|
720 |
gduche |
330 |
'INNER JOIN del_utilisateur du '.
|
797 |
aurelien |
331 |
'ON du.id_utilisateur = doi.id_utilisateur ';
|
720 |
gduche |
332 |
$requeteLiaisons .= $this->chargerClauseWhere();
|
737 |
gduche |
333 |
$requeteLiaisons .= ' GROUP BY doi.id_observation';
|
|
|
334 |
$requeteLiaisons .= ' ORDER BY date_transmission DESC ';
|
|
|
335 |
$requeteLiaisons .= $this->gestionBdd->getLimitSql();
|
797 |
aurelien |
336 |
|
720 |
gduche |
337 |
return $this->bdd->recupererTous($requeteLiaisons);
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
/**
|
|
|
341 |
* Compter le nombre total d'images dans la base pour affichage dans entete.
|
|
|
342 |
* */
|
737 |
gduche |
343 |
private function compterObservations() {
|
720 |
gduche |
344 |
$requete = 'SELECT FOUND_ROWS() AS nbre ';
|
|
|
345 |
$resultats = $this->bdd->recuperer($requete);
|
766 |
aurelien |
346 |
return (int) $resultats['nbre'];
|
720 |
gduche |
347 |
}
|
|
|
348 |
|
|
|
349 |
/**
|
|
|
350 |
* Retourner un tableau d'images formaté en fonction des liaisons trouvées
|
|
|
351 |
* @param $liaisons les liaisons de la table del_obs_images
|
|
|
352 |
* */
|
737 |
gduche |
353 |
private function chargerObservations($liaisons) {
|
720 |
gduche |
354 |
|
737 |
gduche |
355 |
$observations = array();
|
720 |
gduche |
356 |
foreach ($liaisons as $liaison) {
|
737 |
gduche |
357 |
$idObs = $liaison[$this->mappingObservation['id_observation']];
|
720 |
gduche |
358 |
|
745 |
gduche |
359 |
$observation = $this->formaterObservation($liaison);
|
737 |
gduche |
360 |
$observations[$idObs] = $observation;
|
720 |
gduche |
361 |
}
|
737 |
gduche |
362 |
return $observations;
|
720 |
gduche |
363 |
}
|
|
|
364 |
|
|
|
365 |
/**
|
737 |
gduche |
366 |
* Sélectionner toutes les images de chaque observation
|
|
|
367 |
* @param array $observations la liste des observations
|
|
|
368 |
* */
|
755 |
gduche |
369 |
private function chargerImages($observations) {
|
720 |
gduche |
370 |
|
737 |
gduche |
371 |
foreach ($observations as $id => $observation) {
|
720 |
gduche |
372 |
|
766 |
aurelien |
373 |
$requeteImages = 'SELECT * FROM '. $this->gestionBdd->formaterTable('del_obs_image', 'doi').
|
737 |
gduche |
374 |
'INNER JOIN '.$this->gestionBdd->formaterTable('del_image', 'di').
|
|
|
375 |
'ON doi.id_image = di.id_image '.
|
|
|
376 |
'WHERE doi.id_observation = '.$observation['id_observation'];
|
720 |
gduche |
377 |
|
737 |
gduche |
378 |
$images = $this->bdd->recupererTous($requeteImages);
|
|
|
379 |
$images = $this->formaterImages($images);
|
|
|
380 |
$observations[$id]['images'] = $images;
|
720 |
gduche |
381 |
}
|
|
|
382 |
|
737 |
gduche |
383 |
return $observations;
|
720 |
gduche |
384 |
}
|
|
|
385 |
|
755 |
gduche |
386 |
/**
|
|
|
387 |
* Récupérer toutes les déterminations et le nombre de commentaire au total
|
|
|
388 |
* @param array $observations la liste des observations à mettre à jour
|
|
|
389 |
* */
|
|
|
390 |
private function chargerDeterminations($observations) {
|
|
|
391 |
foreach ($observations as $id => $observation) {
|
|
|
392 |
$requetePropositions = 'SELECT * FROM '.$this->gestionBdd->formaterTable('del_commentaire', 'dc').
|
|
|
393 |
'WHERE dc.nom_sel IS NOT NULL AND ce_observation = '.$observation['id_observation'];
|
|
|
394 |
$propositions = $this->bdd->recupererTous($requetePropositions);
|
781 |
delphine |
395 |
$observations[$id]['propositions'] = $this->formaterDeterminations($propositions);
|
755 |
gduche |
396 |
}
|
|
|
397 |
return $observations;
|
|
|
398 |
}
|
737 |
gduche |
399 |
|
781 |
delphine |
400 |
private function formaterDeterminations($propositions) {
|
|
|
401 |
$propositions_format = array();
|
|
|
402 |
if ($propositions != array()) {
|
|
|
403 |
foreach ($propositions as $id => $proposition) {
|
|
|
404 |
$propositions_format[$proposition['id_commentaire']] = $proposition;
|
|
|
405 |
$ids_proposition[] = $proposition['id_commentaire'];
|
|
|
406 |
}
|
|
|
407 |
$propositions_format = $this->chargerVotes($ids_proposition, $propositions_format);
|
|
|
408 |
$propositions_format = $this->chargerNombreCommentaire($ids_proposition, $propositions_format);
|
|
|
409 |
}
|
|
|
410 |
return $propositions_format;
|
|
|
411 |
}
|
755 |
gduche |
412 |
/**
|
781 |
delphine |
413 |
* Charger les votes sur les déterminations
|
797 |
aurelien |
414 |
* @param Array $observations le tableau des observations à mettre à jour
|
781 |
delphine |
415 |
* */
|
|
|
416 |
private function chargerVotes($ids_proposition, $propositions) {
|
|
|
417 |
$requeteVotes = 'SELECT * FROM '.
|
|
|
418 |
$this->gestionBdd->formaterTable('del_commentaire_vote').
|
|
|
419 |
'WHERE ce_proposition IN ('.implode(', ', $ids_proposition).')';
|
|
|
420 |
|
|
|
421 |
$resultatsVotes = $this->bdd->recupererTous($requeteVotes);
|
|
|
422 |
foreach ($resultatsVotes as $vote) {
|
787 |
delphine |
423 |
$propositions[$vote['ce_proposition']]['votes'][] = $this->formaterVotes($vote);
|
781 |
delphine |
424 |
}
|
|
|
425 |
return $propositions;
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
/**
|
755 |
gduche |
429 |
* Charger le nombre de commentaires (sans détermination) associé à l'observation
|
|
|
430 |
* @param Array $observations le tableau des observatins à mettre à jour
|
|
|
431 |
* */
|
781 |
delphine |
432 |
private function chargerNombreCommentaire($ids_proposition, $propositions) {
|
|
|
433 |
$requeteNbCommentaires = 'SELECT ce_proposition, COUNT('.$this->proteger('id_commentaire').') as nb '.
|
|
|
434 |
'FROM '.$this->gestionBdd->formaterTable('del_commentaire').
|
|
|
435 |
'WHERE ce_proposition IN ('.implode(', ', $ids_proposition).')';
|
|
|
436 |
$nbCommentaires = $this->bdd->recuperer($requeteNbCommentaires);
|
|
|
437 |
foreach ($nbCommentaires as $vote) {
|
|
|
438 |
$propositions[$vote['ce_proposition']]['commentaires']= $vote;
|
755 |
gduche |
439 |
}
|
781 |
delphine |
440 |
return $propositions;
|
755 |
gduche |
441 |
}
|
737 |
gduche |
442 |
|
720 |
gduche |
443 |
/*-------------------------------------------------------------------------------
|
|
|
444 |
FORMATER ET METTRE EN FORME
|
|
|
445 |
--------------------------------------------------------------------------------*/
|
|
|
446 |
|
|
|
447 |
/**
|
737 |
gduche |
448 |
* Formater les images d'une observation
|
|
|
449 |
* @param array $images les images de l'observation
|
|
|
450 |
* */
|
|
|
451 |
private function formaterImages($images) {
|
|
|
452 |
$imagesRetour = array();
|
|
|
453 |
foreach ($images as $image) {
|
|
|
454 |
$imageCourante = array();
|
|
|
455 |
$imageCourante['id_image'] = $image['id_image'];
|
|
|
456 |
$imageCourante['date'] = $image['date_prise_de_vue'];
|
|
|
457 |
$imageCourante['binaire.href'] = $this->formaterLienImage($image['id_image']);
|
|
|
458 |
$imageCourante['hauteur'] = $image['hauteur'];
|
|
|
459 |
$imageRetour['largeur'] = $image['largeur'];
|
|
|
460 |
|
|
|
461 |
$imagesRetour[] = $imageCourante;
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
return $imagesRetour;
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
/**
|
720 |
gduche |
468 |
* Formater une observation depuis une ligne liaison
|
|
|
469 |
* @param $liaison liaison issue de la recherche
|
|
|
470 |
* @return $observation l'observation mise en forme
|
|
|
471 |
* */
|
|
|
472 |
private function formaterObservation($liaison) {
|
|
|
473 |
$observation = array();
|
|
|
474 |
|
|
|
475 |
foreach ($this->mappingObservation as $nomOriginal => $nomFinal) {
|
|
|
476 |
$observation[$nomFinal] = $liaison[$nomOriginal];
|
|
|
477 |
}
|
745 |
gduche |
478 |
|
|
|
479 |
$observation['images'] = array();
|
720 |
gduche |
480 |
|
|
|
481 |
return $observation;
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
/**
|
|
|
486 |
* Formater le lien de l'image en fonction du fichier de config et de l'identifiant de l'image
|
|
|
487 |
* */
|
|
|
488 |
private function formaterLienImage($idImage) {
|
|
|
489 |
$idImage = sprintf('%09s', $idImage);
|
|
|
490 |
$url = $this->conteneur->getParametre('url_images');
|
|
|
491 |
$urlImage = str_replace('%s', $idImage, $url);
|
|
|
492 |
return $urlImage;
|
|
|
493 |
}
|
|
|
494 |
|
787 |
delphine |
495 |
/**
|
|
|
496 |
* Formater un vote en fonction du fichier de configuration config_votes.ini
|
|
|
497 |
* @param $votes array()
|
|
|
498 |
* */
|
|
|
499 |
private function formaterVotes($vote) {
|
|
|
500 |
$retour = array();
|
|
|
501 |
foreach ($vote as $param=>$valeur) {
|
|
|
502 |
$retour[$vote['id_vote']][$this->mappingVotes[$param]] = $valeur;
|
|
|
503 |
}
|
|
|
504 |
return $retour;
|
|
|
505 |
}
|
|
|
506 |
|
720 |
gduche |
507 |
private function proteger($valeur) {
|
|
|
508 |
if (is_array($valeur)) {
|
|
|
509 |
return $this->bdd->protegerTableau($valeur);
|
|
|
510 |
} else {
|
|
|
511 |
return $this->bdd->proteger($valeur);
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
}
|
|
|
515 |
?>
|