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 |
|
|
|
67 |
$info['moyImagesParObs'] = ($info['observationsLiees'] > 0 ? round($info['imagesLiees']/$info['observationsLiees'], 4) : '');
|
|
|
68 |
|
|
|
69 |
$requete = $this->construireRequeteNbreObsParCommune();
|
|
|
70 |
$info['communes'] = ($resultat = $this->executerRequete($requete)) ? count($resultat) : '' ;
|
|
|
71 |
|
|
|
72 |
return $info;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
private function construireRequeteNbreObs() {
|
694 |
jpm |
76 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
696 |
jpm |
77 |
'FROM cel_inventory ';
|
|
|
78 |
|
|
|
79 |
if (count($this->parametres) != 0) {
|
|
|
80 |
$filtres = array();
|
|
|
81 |
extract($this->parametres);
|
|
|
82 |
|
|
|
83 |
if (isset($utilisateur)) {
|
|
|
84 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
85 |
}
|
|
|
86 |
if (isset($num_taxon)) {
|
|
|
87 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
$requete .= ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
return $requete;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
private function construireRequeteNbreObsPubliques() {
|
|
|
97 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
694 |
jpm |
98 |
'FROM cel_inventory '.
|
696 |
jpm |
99 |
"WHERE transmission = 1 ";
|
|
|
100 |
|
|
|
101 |
if (count($this->parametres) != 0) {
|
|
|
102 |
$filtres = array();
|
|
|
103 |
extract($this->parametres);
|
|
|
104 |
|
|
|
105 |
if (isset($utilisateur)) {
|
|
|
106 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
107 |
}
|
|
|
108 |
if (isset($num_taxon)) {
|
|
|
109 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
113 |
}
|
694 |
jpm |
114 |
|
696 |
jpm |
115 |
return $requete;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
private function construireRequeteNbreObsParCommune() {
|
|
|
119 |
$requete = 'SELECT COUNT(id) AS nbre '.
|
|
|
120 |
'FROM cel_inventory '.
|
|
|
121 |
"WHERE location != '000null' ".
|
|
|
122 |
" AND id_location != '000null' ";
|
|
|
123 |
$groupBy = 'GROUP BY location, id_location';
|
|
|
124 |
|
|
|
125 |
if (count($this->parametres) != 0) {
|
|
|
126 |
$filtres = array();
|
|
|
127 |
extract($this->parametres);
|
|
|
128 |
|
|
|
129 |
if (isset($utilisateur)) {
|
|
|
130 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
131 |
}
|
|
|
132 |
if (isset($num_taxon)) {
|
|
|
133 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
137 |
}
|
|
|
138 |
$requete .= $groupBy;
|
694 |
jpm |
139 |
|
696 |
jpm |
140 |
return $requete;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
private function construireRequeteNbreImg() {
|
|
|
144 |
$select = 'SELECT COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
145 |
$from = 'FROM cel_images ';
|
694 |
jpm |
146 |
|
696 |
jpm |
147 |
if (count($this->parametres) != 0) {
|
|
|
148 |
$filtres = array();
|
|
|
149 |
|
|
|
150 |
extract($this->parametres);
|
|
|
151 |
|
|
|
152 |
if (isset($utilisateur)) {
|
|
|
153 |
$filtres[] = "ci_ce_utilisateur = $utilisateur ";
|
|
|
154 |
}
|
|
|
155 |
if (isset($num_taxon)) {
|
|
|
156 |
$from .= 'LEFT JOIN cel_obs_images ON (coi_ce_image = ci_id_image) '.
|
|
|
157 |
'LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
158 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
$requete = $select.$from.$where;
|
|
|
165 |
return $requete;
|
694 |
jpm |
166 |
}
|
696 |
jpm |
167 |
|
|
|
168 |
private function construireRequeteNbreImgLiees() {
|
|
|
169 |
$select = 'SELECT COUNT(DISTINCT ci_id_image) AS nbre ';
|
|
|
170 |
$from = 'FROM cel_obs_images '.
|
|
|
171 |
' LEFT JOIN cel_images ON (coi_ce_image = ci_id_image) ';
|
|
|
172 |
|
|
|
173 |
if (count($this->parametres) != 0) {
|
|
|
174 |
$filtres = array();
|
|
|
175 |
|
|
|
176 |
extract($this->parametres);
|
|
|
177 |
|
|
|
178 |
if (isset($utilisateur)) {
|
|
|
179 |
$filtres[] = "coi_ce_utilisateur = $utilisateur ";
|
|
|
180 |
}
|
|
|
181 |
if (isset($num_taxon)) {
|
|
|
182 |
$from .= 'LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
183 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
$requete = $select.$from.$where;
|
|
|
190 |
return $requete;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
private function construireRequeteNbreObsLiees() {
|
|
|
194 |
$select = 'SELECT COUNT(DISTINCT coi_ce_observation) AS nbre ';
|
|
|
195 |
$from = 'FROM cel_obs_images '.
|
|
|
196 |
' LEFT JOIN cel_inventory ON (coi_ce_observation = ordre AND coi_ce_utilisateur = identifiant) ';
|
|
|
197 |
|
|
|
198 |
if (count($this->parametres) != 0) {
|
|
|
199 |
$filtres = array();
|
|
|
200 |
|
|
|
201 |
extract($this->parametres);
|
|
|
202 |
|
|
|
203 |
if (isset($utilisateur)) {
|
|
|
204 |
$filtres[] = "identifiant = $utilisateur ";
|
|
|
205 |
}
|
|
|
206 |
if (isset($num_taxon)) {
|
|
|
207 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
$requete = $select.$from.$where;
|
|
|
214 |
|
|
|
215 |
return $requete;
|
|
|
216 |
}
|
694 |
jpm |
217 |
}
|
|
|
218 |
?>
|