694 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
696 |
jpm |
3 |
* Service fournissant des statistiques de l'application CEL au format texte (JSON).
|
694 |
jpm |
4 |
* Encodage en entrée : utf8
|
|
|
5 |
* Encodage en sortie : utf8
|
|
|
6 |
*
|
|
|
7 |
* Cas d'utilisation :
|
696 |
jpm |
8 |
* /CelStatistiqueTxt/TypeDeStat : retourne les statistiques demandées
|
694 |
jpm |
9 |
* Paramêtres :
|
696 |
jpm |
10 |
* utilisateur=courriel : retourne les statistiques d'un utilisateur donné.
|
694 |
jpm |
11 |
*
|
696 |
jpm |
12 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
13 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
14 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
15 |
* @version $Id$
|
|
|
16 |
* @copyright Copyright (c) 2011, Tela Botanica (accueil@tela-botanica.org)
|
694 |
jpm |
17 |
*/
|
|
|
18 |
class CelStatistiqueTxt extends Cel {
|
696 |
jpm |
19 |
|
694 |
jpm |
20 |
/**
|
|
|
21 |
* Méthode appelée avec une requête de type GET.
|
|
|
22 |
*/
|
696 |
jpm |
23 |
public function getElement($ressources) {
|
694 |
jpm |
24 |
$graph = null;
|
|
|
25 |
$serveur = '';
|
|
|
26 |
|
696 |
jpm |
27 |
if (isset($ressources[0])) {
|
|
|
28 |
$this->analyserParametresUrl();
|
|
|
29 |
$stat_demande = array_shift($ressources);
|
694 |
jpm |
30 |
$methode = 'get'.$stat_demande;
|
|
|
31 |
if (method_exists($this, $methode)) {
|
702 |
jpm |
32 |
$this->ressources = $ressources;
|
696 |
jpm |
33 |
$stats = $this->$methode($ressources);
|
694 |
jpm |
34 |
} else {
|
|
|
35 |
$this->messages[] = "Ce type de statistiques '$stat_demande' n'est pas disponible.";
|
|
|
36 |
}
|
|
|
37 |
} else {
|
696 |
jpm |
38 |
$this->messages[] = "La ressource du service CEL StatistiqueTxt doit indiquer le type de statistique. Ex. : .../CelStatistiqueTxt/Nombres";
|
694 |
jpm |
39 |
}
|
|
|
40 |
|
|
|
41 |
if (!is_null($stats)) {
|
|
|
42 |
$this->envoyerJson($stats);
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
696 |
jpm |
46 |
private function analyserParametresUrl() {
|
702 |
jpm |
47 |
$this->parametres['utilisateur'] = isset($_GET['utilisateur']) ? $this->bdd->quote($this->verifierSecuriteParametreUrl($_GET['utilisateur'])) : null;
|
|
|
48 |
$this->parametres['num_taxon'] = isset($_GET['num_taxon']) ? $this->bdd->quote($this->verifierSecuriteParametreUrl($_GET['num_taxon'])) : null;
|
|
|
49 |
$this->parametres['taxon'] = isset($_GET['taxon']) ? $this->bdd->quote($this->verifierSecuriteParametreUrl($_GET['taxon'].'%')) : null;
|
|
|
50 |
$this->parametres['start'] = isset($_GET['start']) ? $this->verifierSecuriteParametreUrl($_GET['start']) : null;
|
|
|
51 |
$this->parametres['limit'] = isset($_GET['limit']) ? $this->verifierSecuriteParametreUrl($_GET['limit']) : null;
|
696 |
jpm |
52 |
}
|
|
|
53 |
|
702 |
jpm |
54 |
private function getListeUtilisateursNbrePhotos() {
|
|
|
55 |
$requete = $this->construireRequeteListeUtilisateurNbrePhoto();
|
|
|
56 |
$resultats = $this->executerRequete($requete);
|
|
|
57 |
$liste = array();
|
|
|
58 |
if ($resultats != false) {
|
|
|
59 |
foreach ($resultats as $resultat) {
|
|
|
60 |
$liste[$resultat['identifiant']] = $resultat['nbre'];
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
return $liste;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
private function construireRequeteListeUtilisateurNbrePhoto() {
|
|
|
67 |
$select = 'SELECT identifiant, COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
68 |
$from = 'FROM cel_inventory '.
|
|
|
69 |
' LEFT JOIN cel_obs_images ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) '.
|
|
|
70 |
' LEFT JOIN cel_images ON (coi_ce_image = ci_id_image) ';
|
|
|
71 |
$where = 'WHERE transmission = 1 ';
|
|
|
72 |
$groupBy = 'GROUP BY identifiant ';
|
|
|
73 |
$orderBy = 'ORDER BY nbre DESC ';
|
|
|
74 |
$limitSql = 'LIMIT 0,150 ';
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
if (count($this->parametres) != 0) {
|
|
|
78 |
extract($this->parametres);
|
|
|
79 |
|
|
|
80 |
$filtres = array();
|
|
|
81 |
|
|
|
82 |
if (isset($utilisateur)) {
|
|
|
83 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
84 |
}
|
|
|
85 |
if (isset($num_taxon)) {
|
|
|
86 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
87 |
}
|
|
|
88 |
if (isset($taxon)) {
|
|
|
89 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
90 |
}
|
|
|
91 |
$where .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
92 |
|
|
|
93 |
if (isset($start)) {
|
|
|
94 |
$limitSql = str_replace('0,', "$start,", $limitSql);
|
|
|
95 |
}
|
|
|
96 |
if (isset($limit)) {
|
|
|
97 |
$limitSql = str_replace('150', $limit, $limitSql);
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
$requete = $select.$from.$where.$groupBy.$orderBy.$limitSql;
|
|
|
102 |
|
|
|
103 |
return $requete;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
private function getListeTaxonsNbrePhotos() {
|
|
|
107 |
$requete = $this->construireRequeteListeTaxonNbrePhoto();
|
|
|
108 |
$resultats = $this->executerRequete($requete);
|
|
|
109 |
$liste = array();
|
|
|
110 |
if ($resultats != false) {
|
|
|
111 |
foreach ($resultats as $resultat) {
|
|
|
112 |
$liste[$resultat['nom_ret']] = $resultat['nbre'];
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
return $liste;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
private function construireRequeteListeTaxonNbrePhoto() {
|
|
|
119 |
$select = 'SELECT nom_ret, COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
120 |
$from = 'FROM cel_inventory '.
|
|
|
121 |
' LEFT JOIN cel_obs_images ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) '.
|
|
|
122 |
' LEFT JOIN cel_images ON (coi_ce_image = ci_id_image) ';
|
|
|
123 |
$where = 'WHERE transmission = 1 '.
|
|
|
124 |
" AND nom_ret != '' ";
|
|
|
125 |
$groupBy = 'GROUP BY nom_ret ';
|
|
|
126 |
$orderBy = 'ORDER BY nbre DESC ';
|
|
|
127 |
$limitSql = 'LIMIT 0,150 ';
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
if (count($this->parametres) != 0) {
|
|
|
131 |
extract($this->parametres);
|
|
|
132 |
|
|
|
133 |
$filtres = array();
|
|
|
134 |
|
|
|
135 |
if (isset($utilisateur)) {
|
|
|
136 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
137 |
}
|
|
|
138 |
if (isset($num_taxon)) {
|
|
|
139 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
140 |
}
|
|
|
141 |
if (isset($taxon)) {
|
|
|
142 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
143 |
}
|
|
|
144 |
$where .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
145 |
|
|
|
146 |
if (isset($start)) {
|
|
|
147 |
$limitSql = str_replace('0,', "$start,", $limitSql);
|
|
|
148 |
}
|
|
|
149 |
if (isset($limit)) {
|
|
|
150 |
$limitSql = str_replace('150', $limit, $limitSql);
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
$requete = $select.$from.$where.$groupBy.$orderBy.$limitSql;
|
|
|
155 |
return $requete;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
private function getNombres() {
|
696 |
jpm |
159 |
|
|
|
160 |
$requete = $this->construireRequeteNbreObs();
|
|
|
161 |
$info['observations'] = (int) $this->executerRequete($requete, 'Column');
|
694 |
jpm |
162 |
|
696 |
jpm |
163 |
$requete = $this->construireRequeteNbreObsPubliques();
|
|
|
164 |
$info['observationsPubliques'] = (int) $this->executerRequete($requete, 'Column');
|
|
|
165 |
|
|
|
166 |
$requete = $this->construireRequeteNbreImg();
|
|
|
167 |
$info['images'] =(int) $this->executerRequete($requete, 'Column');
|
|
|
168 |
|
|
|
169 |
$requete = $this->construireRequeteNbreImgLiees();
|
|
|
170 |
$info['imagesLiees'] =(int) $this->executerRequete($requete, 'Column');
|
|
|
171 |
|
|
|
172 |
$requete = $this->construireRequeteNbreObsLiees();
|
|
|
173 |
$info['observationsLiees'] = (int) $this->executerRequete($requete, 'Column');
|
|
|
174 |
|
697 |
jpm |
175 |
$info['moyImagesParObs'] = ($info['observationsLiees'] > 0 ? round($info['imagesLiees']/$info['observationsLiees'], 2) : '');
|
696 |
jpm |
176 |
|
|
|
177 |
$requete = $this->construireRequeteNbreObsParCommune();
|
697 |
jpm |
178 |
$info['communes'] = ($resultats = $this->executerRequete($requete)) ? count($resultats) : '' ;
|
|
|
179 |
$info['observationsParCommunesMin'] = 1000;
|
|
|
180 |
$info['observationsParCommunesMax'] = 0;
|
|
|
181 |
$info['observationsParCommunesTotal'] = 0;
|
|
|
182 |
foreach ($resultats as $resultat) {
|
|
|
183 |
if ($resultat['nbre'] < $info['observationsParCommunesMin']) {
|
|
|
184 |
$info['observationsParCommunesMin'] = $resultat['nbre'];
|
|
|
185 |
}
|
|
|
186 |
if ($resultat['nbre'] > $info['observationsParCommunesMax']) {
|
|
|
187 |
$info['observationsParCommunesMax'] = $resultat['nbre'];
|
|
|
188 |
}
|
|
|
189 |
$info['observationsParCommunesTotal'] += $resultat['nbre'];
|
|
|
190 |
}
|
702 |
jpm |
191 |
$info['observationsParCommunesMoyenne'] = ($info['communes'] > 0 ) ? round($info['observationsParCommunesTotal'] / $info['communes'], 2) : 0;
|
696 |
jpm |
192 |
|
|
|
193 |
return $info;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
private function construireRequeteNbreObs() {
|
694 |
jpm |
197 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
696 |
jpm |
198 |
'FROM cel_inventory ';
|
|
|
199 |
|
|
|
200 |
if (count($this->parametres) != 0) {
|
|
|
201 |
$filtres = array();
|
|
|
202 |
extract($this->parametres);
|
|
|
203 |
|
|
|
204 |
if (isset($utilisateur)) {
|
|
|
205 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
206 |
}
|
|
|
207 |
if (isset($num_taxon)) {
|
|
|
208 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
209 |
}
|
702 |
jpm |
210 |
if (isset($taxon)) {
|
|
|
211 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
212 |
}
|
696 |
jpm |
213 |
|
|
|
214 |
$requete .= ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
return $requete;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
private function construireRequeteNbreObsPubliques() {
|
|
|
221 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
694 |
jpm |
222 |
'FROM cel_inventory '.
|
696 |
jpm |
223 |
"WHERE transmission = 1 ";
|
|
|
224 |
|
|
|
225 |
if (count($this->parametres) != 0) {
|
|
|
226 |
$filtres = array();
|
|
|
227 |
extract($this->parametres);
|
|
|
228 |
|
|
|
229 |
if (isset($utilisateur)) {
|
|
|
230 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
231 |
}
|
|
|
232 |
if (isset($num_taxon)) {
|
|
|
233 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
234 |
}
|
702 |
jpm |
235 |
if (isset($taxon)) {
|
|
|
236 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
237 |
}
|
696 |
jpm |
238 |
|
|
|
239 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
240 |
}
|
694 |
jpm |
241 |
|
696 |
jpm |
242 |
return $requete;
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
private function construireRequeteNbreObsParCommune() {
|
|
|
246 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
|
|
247 |
'FROM cel_inventory '.
|
|
|
248 |
"WHERE location != '000null' ".
|
|
|
249 |
" AND id_location != '000null' ";
|
|
|
250 |
$groupBy = 'GROUP BY location, id_location';
|
|
|
251 |
|
|
|
252 |
if (count($this->parametres) != 0) {
|
|
|
253 |
$filtres = array();
|
|
|
254 |
extract($this->parametres);
|
|
|
255 |
|
|
|
256 |
if (isset($utilisateur)) {
|
|
|
257 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
258 |
}
|
|
|
259 |
if (isset($num_taxon)) {
|
|
|
260 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
261 |
}
|
702 |
jpm |
262 |
if (isset($taxon)) {
|
|
|
263 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
264 |
}
|
696 |
jpm |
265 |
|
|
|
266 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
267 |
}
|
|
|
268 |
$requete .= $groupBy;
|
694 |
jpm |
269 |
|
696 |
jpm |
270 |
return $requete;
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
private function construireRequeteNbreImg() {
|
|
|
274 |
$select = 'SELECT COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
275 |
$from = 'FROM cel_images ';
|
694 |
jpm |
276 |
|
696 |
jpm |
277 |
if (count($this->parametres) != 0) {
|
|
|
278 |
$filtres = array();
|
|
|
279 |
|
|
|
280 |
extract($this->parametres);
|
|
|
281 |
|
|
|
282 |
if (isset($utilisateur)) {
|
|
|
283 |
$filtres[] = "ci_ce_utilisateur = $utilisateur ";
|
|
|
284 |
}
|
|
|
285 |
if (isset($num_taxon)) {
|
702 |
jpm |
286 |
|
696 |
jpm |
287 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
288 |
}
|
702 |
jpm |
289 |
if (isset($taxon)) {
|
|
|
290 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
291 |
}
|
|
|
292 |
if (isset($num_taxon) || isset($taxon)) {
|
|
|
293 |
$from .= 'LEFT JOIN cel_obs_images ON (coi_ce_image = ci_id_image) '.
|
|
|
294 |
'LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
295 |
}
|
696 |
jpm |
296 |
|
|
|
297 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
$requete = $select.$from.$where;
|
|
|
301 |
return $requete;
|
694 |
jpm |
302 |
}
|
696 |
jpm |
303 |
|
|
|
304 |
private function construireRequeteNbreImgLiees() {
|
|
|
305 |
$select = 'SELECT COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
306 |
$from = 'FROM cel_obs_images '.
|
|
|
307 |
' LEFT JOIN cel_images ON (coi_ce_image = ci_id_image) ';
|
|
|
308 |
|
|
|
309 |
if (count($this->parametres) != 0) {
|
|
|
310 |
$filtres = array();
|
|
|
311 |
|
|
|
312 |
extract($this->parametres);
|
|
|
313 |
|
|
|
314 |
if (isset($utilisateur)) {
|
|
|
315 |
$filtres[] = "coi_ce_utilisateur = $utilisateur ";
|
|
|
316 |
}
|
|
|
317 |
if (isset($num_taxon)) {
|
|
|
318 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
319 |
}
|
702 |
jpm |
320 |
if (isset($taxon)) {
|
|
|
321 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
322 |
}
|
696 |
jpm |
323 |
|
702 |
jpm |
324 |
if (isset($num_taxon) || isset($taxon)) {
|
|
|
325 |
$from .= 'LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
326 |
}
|
|
|
327 |
|
696 |
jpm |
328 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
$requete = $select.$from.$where;
|
|
|
332 |
return $requete;
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
private function construireRequeteNbreObsLiees() {
|
|
|
336 |
$select = 'SELECT COUNT(DISTINCT coi_ce_observation) AS nbre ';
|
|
|
337 |
$from = 'FROM cel_obs_images '.
|
|
|
338 |
' LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
339 |
|
|
|
340 |
if (count($this->parametres) != 0) {
|
|
|
341 |
$filtres = array();
|
|
|
342 |
|
|
|
343 |
extract($this->parametres);
|
|
|
344 |
|
|
|
345 |
if (isset($utilisateur)) {
|
|
|
346 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
347 |
}
|
|
|
348 |
if (isset($num_taxon)) {
|
|
|
349 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
350 |
}
|
702 |
jpm |
351 |
if (isset($taxon)) {
|
|
|
352 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
353 |
}
|
696 |
jpm |
354 |
|
|
|
355 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
$requete = $select.$from.$where;
|
|
|
359 |
|
|
|
360 |
return $requete;
|
|
|
361 |
}
|
694 |
jpm |
362 |
}
|
|
|
363 |
?>
|