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)) {
|
696 |
jpm |
32 |
$stats = $this->$methode($ressources);
|
694 |
jpm |
33 |
} else {
|
|
|
34 |
$this->messages[] = "Ce type de statistiques '$stat_demande' n'est pas disponible.";
|
|
|
35 |
}
|
|
|
36 |
} else {
|
696 |
jpm |
37 |
$this->messages[] = "La ressource du service CEL StatistiqueTxt doit indiquer le type de statistique. Ex. : .../CelStatistiqueTxt/Nombres";
|
694 |
jpm |
38 |
}
|
|
|
39 |
|
|
|
40 |
if (!is_null($stats)) {
|
|
|
41 |
$this->envoyerJson($stats);
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
696 |
jpm |
45 |
private function analyserParametresUrl() {
|
|
|
46 |
$this->parametres['utilisateur'] = isset($_GET['utilisateur']) ? $this->bdd->quote($_GET['utilisateur']) : null;
|
|
|
47 |
$this->parametres['num_taxon'] = isset($_GET['num_taxon']) ? $this->bdd->quote($_GET['num_taxon']) : null;
|
|
|
48 |
}
|
|
|
49 |
|
694 |
jpm |
50 |
private function getNombres($param) {
|
696 |
jpm |
51 |
|
|
|
52 |
$requete = $this->construireRequeteNbreObs();
|
|
|
53 |
$info['observations'] = (int) $this->executerRequete($requete, 'Column');
|
694 |
jpm |
54 |
|
696 |
jpm |
55 |
$requete = $this->construireRequeteNbreObsPubliques();
|
|
|
56 |
$info['observationsPubliques'] = (int) $this->executerRequete($requete, 'Column');
|
|
|
57 |
|
|
|
58 |
$requete = $this->construireRequeteNbreImg();
|
|
|
59 |
$info['images'] =(int) $this->executerRequete($requete, 'Column');
|
|
|
60 |
|
|
|
61 |
$requete = $this->construireRequeteNbreImgLiees();
|
|
|
62 |
$info['imagesLiees'] =(int) $this->executerRequete($requete, 'Column');
|
|
|
63 |
|
|
|
64 |
$requete = $this->construireRequeteNbreObsLiees();
|
|
|
65 |
$info['observationsLiees'] = (int) $this->executerRequete($requete, 'Column');
|
|
|
66 |
|
697 |
jpm |
67 |
$info['moyImagesParObs'] = ($info['observationsLiees'] > 0 ? round($info['imagesLiees']/$info['observationsLiees'], 2) : '');
|
696 |
jpm |
68 |
|
|
|
69 |
$requete = $this->construireRequeteNbreObsParCommune();
|
697 |
jpm |
70 |
$info['communes'] = ($resultats = $this->executerRequete($requete)) ? count($resultats) : '' ;
|
|
|
71 |
$info['observationsParCommunesMin'] = 1000;
|
|
|
72 |
$info['observationsParCommunesMax'] = 0;
|
|
|
73 |
$info['observationsParCommunesTotal'] = 0;
|
|
|
74 |
foreach ($resultats as $resultat) {
|
|
|
75 |
if ($resultat['nbre'] < $info['observationsParCommunesMin']) {
|
|
|
76 |
$info['observationsParCommunesMin'] = $resultat['nbre'];
|
|
|
77 |
}
|
|
|
78 |
if ($resultat['nbre'] > $info['observationsParCommunesMax']) {
|
|
|
79 |
$info['observationsParCommunesMax'] = $resultat['nbre'];
|
|
|
80 |
}
|
|
|
81 |
$info['observationsParCommunesTotal'] += $resultat['nbre'];
|
|
|
82 |
}
|
|
|
83 |
$info['observationsParCommunesMoyenne'] = round($info['observationsParCommunesTotal'] / $info['communes'], 2);
|
696 |
jpm |
84 |
|
|
|
85 |
return $info;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
private function construireRequeteNbreObs() {
|
694 |
jpm |
89 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
696 |
jpm |
90 |
'FROM cel_inventory ';
|
|
|
91 |
|
|
|
92 |
if (count($this->parametres) != 0) {
|
|
|
93 |
$filtres = array();
|
|
|
94 |
extract($this->parametres);
|
|
|
95 |
|
|
|
96 |
if (isset($utilisateur)) {
|
|
|
97 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
98 |
}
|
|
|
99 |
if (isset($num_taxon)) {
|
|
|
100 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
$requete .= ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
return $requete;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
private function construireRequeteNbreObsPubliques() {
|
|
|
110 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
694 |
jpm |
111 |
'FROM cel_inventory '.
|
696 |
jpm |
112 |
"WHERE transmission = 1 ";
|
|
|
113 |
|
|
|
114 |
if (count($this->parametres) != 0) {
|
|
|
115 |
$filtres = array();
|
|
|
116 |
extract($this->parametres);
|
|
|
117 |
|
|
|
118 |
if (isset($utilisateur)) {
|
|
|
119 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
120 |
}
|
|
|
121 |
if (isset($num_taxon)) {
|
|
|
122 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
126 |
}
|
694 |
jpm |
127 |
|
696 |
jpm |
128 |
return $requete;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
private function construireRequeteNbreObsParCommune() {
|
|
|
132 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
|
|
133 |
'FROM cel_inventory '.
|
|
|
134 |
"WHERE location != '000null' ".
|
|
|
135 |
" AND id_location != '000null' ";
|
|
|
136 |
$groupBy = 'GROUP BY location, id_location';
|
|
|
137 |
|
|
|
138 |
if (count($this->parametres) != 0) {
|
|
|
139 |
$filtres = array();
|
|
|
140 |
extract($this->parametres);
|
|
|
141 |
|
|
|
142 |
if (isset($utilisateur)) {
|
|
|
143 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
144 |
}
|
|
|
145 |
if (isset($num_taxon)) {
|
|
|
146 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
150 |
}
|
|
|
151 |
$requete .= $groupBy;
|
694 |
jpm |
152 |
|
696 |
jpm |
153 |
return $requete;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
private function construireRequeteNbreImg() {
|
|
|
157 |
$select = 'SELECT COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
158 |
$from = 'FROM cel_images ';
|
694 |
jpm |
159 |
|
696 |
jpm |
160 |
if (count($this->parametres) != 0) {
|
|
|
161 |
$filtres = array();
|
|
|
162 |
|
|
|
163 |
extract($this->parametres);
|
|
|
164 |
|
|
|
165 |
if (isset($utilisateur)) {
|
|
|
166 |
$filtres[] = "ci_ce_utilisateur = $utilisateur ";
|
|
|
167 |
}
|
|
|
168 |
if (isset($num_taxon)) {
|
|
|
169 |
$from .= 'LEFT JOIN cel_obs_images ON (coi_ce_image = ci_id_image) '.
|
|
|
170 |
'LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
171 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
$requete = $select.$from.$where;
|
|
|
178 |
return $requete;
|
694 |
jpm |
179 |
}
|
696 |
jpm |
180 |
|
|
|
181 |
private function construireRequeteNbreImgLiees() {
|
|
|
182 |
$select = 'SELECT COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
183 |
$from = 'FROM cel_obs_images '.
|
|
|
184 |
' LEFT JOIN cel_images ON (coi_ce_image = ci_id_image) ';
|
|
|
185 |
|
|
|
186 |
if (count($this->parametres) != 0) {
|
|
|
187 |
$filtres = array();
|
|
|
188 |
|
|
|
189 |
extract($this->parametres);
|
|
|
190 |
|
|
|
191 |
if (isset($utilisateur)) {
|
|
|
192 |
$filtres[] = "coi_ce_utilisateur = $utilisateur ";
|
|
|
193 |
}
|
|
|
194 |
if (isset($num_taxon)) {
|
|
|
195 |
$from .= 'LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
196 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
$requete = $select.$from.$where;
|
|
|
203 |
return $requete;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
private function construireRequeteNbreObsLiees() {
|
|
|
207 |
$select = 'SELECT COUNT(DISTINCT coi_ce_observation) AS nbre ';
|
|
|
208 |
$from = 'FROM cel_obs_images '.
|
|
|
209 |
' LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
210 |
|
|
|
211 |
if (count($this->parametres) != 0) {
|
|
|
212 |
$filtres = array();
|
|
|
213 |
|
|
|
214 |
extract($this->parametres);
|
|
|
215 |
|
|
|
216 |
if (isset($utilisateur)) {
|
|
|
217 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
218 |
}
|
|
|
219 |
if (isset($num_taxon)) {
|
|
|
220 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
$requete = $select.$from.$where;
|
|
|
227 |
|
|
|
228 |
return $requete;
|
|
|
229 |
}
|
694 |
jpm |
230 |
}
|
|
|
231 |
?>
|