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 {
|
2143 |
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 |
}
|
2143 |
jpm |
45 |
|
696 |
jpm |
46 |
private function analyserParametresUrl() {
|
1765 |
raphael |
47 |
$this->parametres['utilisateur'] = isset($_GET['utilisateur']) ? Cel::db()->quote($this->verifierSecuriteParametreUrl($_GET['utilisateur'])) : null;
|
|
|
48 |
$this->parametres['num_taxon'] = isset($_GET['num_taxon']) ? Cel::db()->quote($this->verifierSecuriteParametreUrl($_GET['num_taxon'])) : null;
|
|
|
49 |
$this->parametres['taxon'] = isset($_GET['taxon']) ? Cel::db()->quote($this->verifierSecuriteParametreUrl($_GET['taxon'].'%')) : null;
|
707 |
jpm |
50 |
$this->parametres['tag'] = isset($_GET['tag']) ? $this->verifierSecuriteParametreUrl($_GET['tag']) : null;
|
702 |
jpm |
51 |
$this->parametres['start'] = isset($_GET['start']) ? $this->verifierSecuriteParametreUrl($_GET['start']) : null;
|
|
|
52 |
$this->parametres['limit'] = isset($_GET['limit']) ? $this->verifierSecuriteParametreUrl($_GET['limit']) : null;
|
696 |
jpm |
53 |
}
|
2143 |
jpm |
54 |
|
702 |
jpm |
55 |
private function getListeUtilisateursNbrePhotos() {
|
707 |
jpm |
56 |
$liste = array();
|
2143 |
jpm |
57 |
|
702 |
jpm |
58 |
$requete = $this->construireRequeteListeUtilisateurNbrePhoto();
|
707 |
jpm |
59 |
if ($requete != null) {
|
2143 |
jpm |
60 |
$resultats = Cel::db()->requeter($requete);
|
707 |
jpm |
61 |
if ($resultats != false) {
|
|
|
62 |
foreach ($resultats as $resultat) {
|
1359 |
aurelien |
63 |
$liste[$resultat['courriel_utilisateur']] = $resultat['nbre'];
|
707 |
jpm |
64 |
}
|
702 |
jpm |
65 |
}
|
|
|
66 |
}
|
|
|
67 |
return $liste;
|
|
|
68 |
}
|
2143 |
jpm |
69 |
|
702 |
jpm |
70 |
private function construireRequeteListeUtilisateurNbrePhoto() {
|
1359 |
aurelien |
71 |
$select = 'SELECT co.courriel_utilisateur, COUNT(DISTINCT ci.id_image) AS nbre ';
|
|
|
72 |
$from = 'FROM cel_obs co '.
|
|
|
73 |
' LEFT JOIN cel_obs_images coi ON (coi.id_observation = co.id_observation) '.
|
|
|
74 |
' LEFT JOIN cel_images ci ON (coi.id_image = ci.id_image) ';
|
702 |
jpm |
75 |
$where = 'WHERE transmission = 1 ';
|
1359 |
aurelien |
76 |
$groupBy = 'GROUP BY co.courriel_utilisateur ';
|
702 |
jpm |
77 |
$orderBy = 'ORDER BY nbre DESC ';
|
|
|
78 |
$limitSql = 'LIMIT 0,150 ';
|
2143 |
jpm |
79 |
|
707 |
jpm |
80 |
$zero_images = false;
|
702 |
jpm |
81 |
if (count($this->parametres) != 0) {
|
|
|
82 |
extract($this->parametres);
|
2143 |
jpm |
83 |
|
702 |
jpm |
84 |
$filtres = array();
|
2143 |
jpm |
85 |
|
702 |
jpm |
86 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
87 |
$filtres[] = "co.courriel_utilisateur = $utilisateur ";
|
702 |
jpm |
88 |
}
|
|
|
89 |
if (isset($num_taxon)) {
|
1359 |
aurelien |
90 |
$filtres[] = "nt = $num_taxon ";
|
702 |
jpm |
91 |
}
|
|
|
92 |
if (isset($taxon)) {
|
|
|
93 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
94 |
}
|
707 |
jpm |
95 |
if (isset($tag)) {
|
|
|
96 |
$limitation = $this->construireWhereTags();
|
|
|
97 |
if ($limitation != null) {
|
|
|
98 |
$filtres[] = $limitation;
|
|
|
99 |
} else {
|
|
|
100 |
$zero_images = true;
|
|
|
101 |
}
|
|
|
102 |
}
|
702 |
jpm |
103 |
$where .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
2143 |
jpm |
104 |
|
702 |
jpm |
105 |
if (isset($start)) {
|
|
|
106 |
$limitSql = str_replace('0,', "$start,", $limitSql);
|
|
|
107 |
}
|
|
|
108 |
if (isset($limit)) {
|
|
|
109 |
$limitSql = str_replace('150', $limit, $limitSql);
|
|
|
110 |
}
|
|
|
111 |
}
|
707 |
jpm |
112 |
if ($zero_images) {
|
|
|
113 |
$requete = null;
|
|
|
114 |
} else {
|
|
|
115 |
$requete = $select.$from.$where.$groupBy.$orderBy.$limitSql;
|
|
|
116 |
//echo $requete;
|
|
|
117 |
}
|
702 |
jpm |
118 |
return $requete;
|
|
|
119 |
}
|
2143 |
jpm |
120 |
|
707 |
jpm |
121 |
private function construireWhereTags() {
|
|
|
122 |
$where = null;
|
|
|
123 |
if (isset($this->parametres['tag'])) {
|
|
|
124 |
$tag = $this->parametres['tag'];
|
1765 |
raphael |
125 |
$tag_encode = Cel::db()->quote($this->encoderMotCle(trim($tag)));
|
707 |
jpm |
126 |
|
|
|
127 |
// Construction de la requête
|
|
|
128 |
$requete = 'SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire '.
|
|
|
129 |
'FROM cel_mots_cles_images '.
|
|
|
130 |
"WHERE cmc_id_mot_cle_general = $tag_encode ";
|
2143 |
jpm |
131 |
$elements = Cel::db()->requeter($requete);
|
|
|
132 |
|
707 |
jpm |
133 |
if ($elements != false && count($elements) > 0) {
|
|
|
134 |
// Pré-construction du where de la requête
|
|
|
135 |
$tpl_where = '(ci_meta_mots_cles LIKE "%%%s%%" AND ci_ce_utilisateur = %s )';
|
|
|
136 |
$requete_where = array();
|
|
|
137 |
foreach ($elements as $occurence) {
|
1765 |
raphael |
138 |
$requete_where[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], Cel::db()->quote($occurence['cmc_id_proprietaire']));
|
707 |
jpm |
139 |
}
|
|
|
140 |
$where = ' ('.implode(" \nOR ", $requete_where).') ';
|
|
|
141 |
} else {
|
|
|
142 |
$this->debug[] = "Aucune image ne correspond à ce mot clé.";
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
return $where;
|
|
|
146 |
}
|
2143 |
jpm |
147 |
|
702 |
jpm |
148 |
private function getListeTaxonsNbrePhotos() {
|
|
|
149 |
$requete = $this->construireRequeteListeTaxonNbrePhoto();
|
1359 |
aurelien |
150 |
|
2143 |
jpm |
151 |
$resultats = Cel::db()->requeter($requete);
|
702 |
jpm |
152 |
$liste = array();
|
|
|
153 |
if ($resultats != false) {
|
|
|
154 |
foreach ($resultats as $resultat) {
|
|
|
155 |
$liste[$resultat['nom_ret']] = $resultat['nbre'];
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
return $liste;
|
|
|
159 |
}
|
2143 |
jpm |
160 |
|
702 |
jpm |
161 |
private function construireRequeteListeTaxonNbrePhoto() {
|
1359 |
aurelien |
162 |
$select = 'SELECT nom_ret, COUNT(DISTINCT ci.id_image) AS nbre ';
|
|
|
163 |
$from = 'FROM cel_obs co '.
|
|
|
164 |
' LEFT JOIN cel_obs_images coi ON (coi.id_observation = co.id_observation) '.
|
|
|
165 |
' LEFT JOIN cel_images ci ON (coi.id_image = ci.id_image) ';
|
702 |
jpm |
166 |
$where = 'WHERE transmission = 1 '.
|
|
|
167 |
" AND nom_ret != '' ";
|
|
|
168 |
$groupBy = 'GROUP BY nom_ret ';
|
|
|
169 |
$orderBy = 'ORDER BY nbre DESC ';
|
|
|
170 |
$limitSql = 'LIMIT 0,150 ';
|
2143 |
jpm |
171 |
|
|
|
172 |
|
702 |
jpm |
173 |
if (count($this->parametres) != 0) {
|
|
|
174 |
extract($this->parametres);
|
2143 |
jpm |
175 |
|
702 |
jpm |
176 |
$filtres = array();
|
2143 |
jpm |
177 |
|
702 |
jpm |
178 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
179 |
$filtres[] = "co.courriel_utilisateur = $utilisateur ";
|
702 |
jpm |
180 |
}
|
|
|
181 |
if (isset($num_taxon)) {
|
1359 |
aurelien |
182 |
$filtres[] = "nt = $num_taxon ";
|
702 |
jpm |
183 |
}
|
|
|
184 |
if (isset($taxon)) {
|
|
|
185 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
186 |
}
|
|
|
187 |
$where .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
2143 |
jpm |
188 |
|
702 |
jpm |
189 |
if (isset($start)) {
|
|
|
190 |
$limitSql = str_replace('0,', "$start,", $limitSql);
|
|
|
191 |
}
|
|
|
192 |
if (isset($limit)) {
|
|
|
193 |
$limitSql = str_replace('150', $limit, $limitSql);
|
|
|
194 |
}
|
|
|
195 |
}
|
2143 |
jpm |
196 |
|
702 |
jpm |
197 |
$requete = $select.$from.$where.$groupBy.$orderBy.$limitSql;
|
1359 |
aurelien |
198 |
|
702 |
jpm |
199 |
return $requete;
|
|
|
200 |
}
|
2143 |
jpm |
201 |
|
702 |
jpm |
202 |
private function getNombres() {
|
696 |
jpm |
203 |
|
2143 |
jpm |
204 |
$requete = $this->construireRequeteNbreObs();
|
|
|
205 |
$info['observations'] = (int) Cel::db()->requeterValeurUnique($requete);
|
|
|
206 |
|
|
|
207 |
$requete = $this->construireRequeteNbreObsPubliques();
|
|
|
208 |
$info['observationsPubliques'] = (int) Cel::db()->requeterValeurUnique($requete);
|
|
|
209 |
|
696 |
jpm |
210 |
$requete = $this->construireRequeteNbreImg();
|
2143 |
jpm |
211 |
$info['images'] =(int) Cel::db()->requeterValeurUnique($requete);
|
|
|
212 |
|
696 |
jpm |
213 |
$requete = $this->construireRequeteNbreImgLiees();
|
2143 |
jpm |
214 |
$info['imagesLiees'] =(int) Cel::db()->requeterValeurUnique($requete);
|
|
|
215 |
|
696 |
jpm |
216 |
$requete = $this->construireRequeteNbreObsLiees();
|
2143 |
jpm |
217 |
$info['observationsLiees'] = (int) Cel::db()->requeterValeurUnique($requete);
|
|
|
218 |
|
697 |
jpm |
219 |
$info['moyImagesParObs'] = ($info['observationsLiees'] > 0 ? round($info['imagesLiees']/$info['observationsLiees'], 2) : '');
|
2143 |
jpm |
220 |
|
696 |
jpm |
221 |
$requete = $this->construireRequeteNbreObsParCommune();
|
2143 |
jpm |
222 |
$info['communes'] = ($resultats = Cel::db()->requeter($requete)) ? count($resultats) : '' ;
|
697 |
jpm |
223 |
$info['observationsParCommunesMin'] = 1000;
|
|
|
224 |
$info['observationsParCommunesMax'] = 0;
|
|
|
225 |
$info['observationsParCommunesTotal'] = 0;
|
|
|
226 |
foreach ($resultats as $resultat) {
|
|
|
227 |
if ($resultat['nbre'] < $info['observationsParCommunesMin']) {
|
|
|
228 |
$info['observationsParCommunesMin'] = $resultat['nbre'];
|
|
|
229 |
}
|
|
|
230 |
if ($resultat['nbre'] > $info['observationsParCommunesMax']) {
|
|
|
231 |
$info['observationsParCommunesMax'] = $resultat['nbre'];
|
|
|
232 |
}
|
|
|
233 |
$info['observationsParCommunesTotal'] += $resultat['nbre'];
|
|
|
234 |
}
|
702 |
jpm |
235 |
$info['observationsParCommunesMoyenne'] = ($info['communes'] > 0 ) ? round($info['observationsParCommunesTotal'] / $info['communes'], 2) : 0;
|
2143 |
jpm |
236 |
|
|
|
237 |
return $info;
|
696 |
jpm |
238 |
}
|
2143 |
jpm |
239 |
|
696 |
jpm |
240 |
private function construireRequeteNbreObs() {
|
1359 |
aurelien |
241 |
$requete = 'SELECT COUNT(id_observation) AS nbre '.
|
|
|
242 |
'FROM cel_obs ';
|
696 |
jpm |
243 |
|
|
|
244 |
if (count($this->parametres) != 0) {
|
|
|
245 |
$filtres = array();
|
|
|
246 |
extract($this->parametres);
|
2143 |
jpm |
247 |
|
696 |
jpm |
248 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
249 |
$filtres[] = "courriel_utilisateur = $utilisateur ";
|
696 |
jpm |
250 |
}
|
|
|
251 |
if (isset($num_taxon)) {
|
|
|
252 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
253 |
}
|
702 |
jpm |
254 |
if (isset($taxon)) {
|
|
|
255 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
256 |
}
|
2143 |
jpm |
257 |
|
696 |
jpm |
258 |
$requete .= ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
259 |
}
|
1359 |
aurelien |
260 |
|
696 |
jpm |
261 |
return $requete;
|
|
|
262 |
}
|
2143 |
jpm |
263 |
|
696 |
jpm |
264 |
private function construireRequeteNbreObsPubliques() {
|
1359 |
aurelien |
265 |
$requete = 'SELECT COUNT(id_observation) AS nbre '.
|
|
|
266 |
'FROM cel_obs '.
|
696 |
jpm |
267 |
"WHERE transmission = 1 ";
|
|
|
268 |
|
|
|
269 |
if (count($this->parametres) != 0) {
|
|
|
270 |
$filtres = array();
|
|
|
271 |
extract($this->parametres);
|
2143 |
jpm |
272 |
|
696 |
jpm |
273 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
274 |
$filtres[] = "courriel_utilisateur = $utilisateur ";
|
696 |
jpm |
275 |
}
|
|
|
276 |
if (isset($num_taxon)) {
|
|
|
277 |
$filtres[] = "num_taxon = $num_taxon ";
|
|
|
278 |
}
|
702 |
jpm |
279 |
if (isset($taxon)) {
|
|
|
280 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
281 |
}
|
2143 |
jpm |
282 |
|
696 |
jpm |
283 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
284 |
}
|
2143 |
jpm |
285 |
|
696 |
jpm |
286 |
return $requete;
|
|
|
287 |
}
|
2143 |
jpm |
288 |
|
696 |
jpm |
289 |
private function construireRequeteNbreObsParCommune() {
|
1359 |
aurelien |
290 |
$requete = 'SELECT COUNT(id_observation) AS nbre '.
|
|
|
291 |
'FROM cel_obs '.
|
|
|
292 |
"WHERE zone_geo IS NOT NULL ".
|
|
|
293 |
" AND ce_zone_geo IS NOT NULL ";
|
|
|
294 |
$groupBy = 'GROUP BY zone_geo, ce_zone_geo';
|
696 |
jpm |
295 |
|
|
|
296 |
if (count($this->parametres) != 0) {
|
|
|
297 |
$filtres = array();
|
|
|
298 |
extract($this->parametres);
|
2143 |
jpm |
299 |
|
696 |
jpm |
300 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
301 |
$filtres[] = "courriel_utilisateur = $utilisateur ";
|
696 |
jpm |
302 |
}
|
|
|
303 |
if (isset($num_taxon)) {
|
1359 |
aurelien |
304 |
$filtres[] = "nt = $num_taxon ";
|
696 |
jpm |
305 |
}
|
702 |
jpm |
306 |
if (isset($taxon)) {
|
|
|
307 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
308 |
}
|
2143 |
jpm |
309 |
|
696 |
jpm |
310 |
$requete .= ((count($filtres) > 0) ? 'AND '.implode(' AND ', $filtres) : '');
|
|
|
311 |
}
|
|
|
312 |
$requete .= $groupBy;
|
2143 |
jpm |
313 |
|
696 |
jpm |
314 |
return $requete;
|
|
|
315 |
}
|
2143 |
jpm |
316 |
|
696 |
jpm |
317 |
private function construireRequeteNbreImg() {
|
1359 |
aurelien |
318 |
$select = 'SELECT COUNT(DISTINCT ci.id_image) AS nbre ';
|
|
|
319 |
$from = 'FROM cel_images ci ';
|
2143 |
jpm |
320 |
|
696 |
jpm |
321 |
if (count($this->parametres) != 0) {
|
|
|
322 |
$filtres = array();
|
2143 |
jpm |
323 |
|
696 |
jpm |
324 |
extract($this->parametres);
|
2143 |
jpm |
325 |
|
696 |
jpm |
326 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
327 |
$filtres[] = "courriel_utilisateur = $utilisateur ";
|
696 |
jpm |
328 |
}
|
|
|
329 |
if (isset($num_taxon)) {
|
2143 |
jpm |
330 |
|
1359 |
aurelien |
331 |
$filtres[] = "nt = $num_taxon ";
|
696 |
jpm |
332 |
}
|
702 |
jpm |
333 |
if (isset($taxon)) {
|
|
|
334 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
335 |
}
|
|
|
336 |
if (isset($num_taxon) || isset($taxon)) {
|
1359 |
aurelien |
337 |
$from .= 'LEFT JOIN cel_obs_images coi ON (coi.id_image = ci.id_image) '.
|
|
|
338 |
'LEFT JOIN cel_obs co ON (coi.id_observation = co.id_observation) ';
|
702 |
jpm |
339 |
}
|
2143 |
jpm |
340 |
|
696 |
jpm |
341 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
342 |
}
|
|
|
343 |
$requete = $select.$from.$where;
|
1359 |
aurelien |
344 |
|
696 |
jpm |
345 |
return $requete;
|
694 |
jpm |
346 |
}
|
2143 |
jpm |
347 |
|
696 |
jpm |
348 |
private function construireRequeteNbreImgLiees() {
|
1359 |
aurelien |
349 |
$select = 'SELECT COUNT(DISTINCT ci.id_image) AS nbre ';
|
|
|
350 |
$from = 'FROM cel_obs_images coi '.
|
|
|
351 |
' LEFT JOIN cel_images ci ON (coi.id_image = ci.id_image) ';
|
2143 |
jpm |
352 |
|
696 |
jpm |
353 |
if (count($this->parametres) != 0) {
|
|
|
354 |
$filtres = array();
|
2143 |
jpm |
355 |
|
696 |
jpm |
356 |
extract($this->parametres);
|
2143 |
jpm |
357 |
|
696 |
jpm |
358 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
359 |
$filtres[] = "ci.courriel_utilisateur = $utilisateur ";
|
696 |
jpm |
360 |
}
|
|
|
361 |
if (isset($num_taxon)) {
|
1359 |
aurelien |
362 |
$filtres[] = "nt = $num_taxon ";
|
696 |
jpm |
363 |
}
|
702 |
jpm |
364 |
if (isset($taxon)) {
|
|
|
365 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
366 |
}
|
2143 |
jpm |
367 |
|
702 |
jpm |
368 |
if (isset($num_taxon) || isset($taxon)) {
|
1359 |
aurelien |
369 |
$from .= 'LEFT JOIN cel_obs ON (coi.id_observation = co.id_observation) ';
|
702 |
jpm |
370 |
}
|
2143 |
jpm |
371 |
|
696 |
jpm |
372 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
373 |
}
|
2143 |
jpm |
374 |
|
696 |
jpm |
375 |
$requete = $select.$from.$where;
|
|
|
376 |
return $requete;
|
|
|
377 |
}
|
2143 |
jpm |
378 |
|
696 |
jpm |
379 |
private function construireRequeteNbreObsLiees() {
|
1359 |
aurelien |
380 |
$select = 'SELECT COUNT(DISTINCT coi.id_observation) AS nbre ';
|
|
|
381 |
$from = 'FROM cel_obs_images coi '.
|
|
|
382 |
' LEFT JOIN cel_obs co ON (coi.id_observation = co.id_observation) ';
|
2143 |
jpm |
383 |
|
696 |
jpm |
384 |
if (count($this->parametres) != 0) {
|
|
|
385 |
$filtres = array();
|
2143 |
jpm |
386 |
|
696 |
jpm |
387 |
extract($this->parametres);
|
2143 |
jpm |
388 |
|
696 |
jpm |
389 |
if (isset($utilisateur)) {
|
1359 |
aurelien |
390 |
$filtres[] = "courriel_utilisateur = $utilisateur ";
|
696 |
jpm |
391 |
}
|
|
|
392 |
if (isset($num_taxon)) {
|
1359 |
aurelien |
393 |
$filtres[] = "nt = $num_taxon ";
|
696 |
jpm |
394 |
}
|
702 |
jpm |
395 |
if (isset($taxon)) {
|
|
|
396 |
$filtres[] = "nom_ret LIKE $taxon ";
|
|
|
397 |
}
|
2143 |
jpm |
398 |
|
696 |
jpm |
399 |
$where = ((count($filtres) > 0) ? 'WHERE '.implode(' AND ', $filtres) : '');
|
|
|
400 |
}
|
2143 |
jpm |
401 |
|
696 |
jpm |
402 |
$requete = $select.$from.$where;
|
2143 |
jpm |
403 |
|
696 |
jpm |
404 |
return $requete;
|
|
|
405 |
}
|
2175 |
mathias |
406 |
|
|
|
407 |
|
|
|
408 |
/**
|
|
|
409 |
* Retourne les n principaux contributeurs depuis x jours,
|
|
|
410 |
* en termes d'observations ajoutées, d'images ajoutées, ou les deux
|
|
|
411 |
* Paramètres : "jours" (int), "nombre" (int), "critere" ("obs" ou "img" ou "")
|
|
|
412 |
* @return array
|
|
|
413 |
*/
|
|
|
414 |
private function getGrandsContributeurs() {
|
|
|
415 |
|
|
|
416 |
$nombre = 10; // les $nombre plus importants contributeurs
|
|
|
417 |
$jours = 7; // depuis $jours jours
|
|
|
418 |
$critere = null; // "obs", "img" ou null (les deux)
|
|
|
419 |
|
|
|
420 |
if (isset($this->parametres['nombre'])) {
|
|
|
421 |
$nombre = $this->parametres['nombre'];
|
|
|
422 |
}
|
|
|
423 |
if (isset($this->parametres['jours'])) {
|
|
|
424 |
$jours = $this->parametres['jours'];
|
|
|
425 |
}
|
|
|
426 |
if (isset($this->parametres['critere'])) {
|
|
|
427 |
$critere = $this->parametres['critere'];
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
$requete = $this->construireRequeteGrandsContributeurs($nombre, $jours, $critere);
|
|
|
431 |
$resultats = Cel::db()->requeter($requete);
|
|
|
432 |
|
2177 |
mathias |
433 |
$retour = array(
|
|
|
434 |
'entete' => array(
|
2180 |
mathias |
435 |
'nombre' => intval($nombre),
|
|
|
436 |
'jours' => intval($jours),
|
2177 |
mathias |
437 |
'critere' => $critere
|
|
|
438 |
),
|
|
|
439 |
'resultats' => array()
|
|
|
440 |
);
|
2175 |
mathias |
441 |
$liste = array();
|
|
|
442 |
if ($resultats != false) {
|
|
|
443 |
foreach ($resultats as $resultat) {
|
2180 |
mathias |
444 |
// essayons de faire du JSON propre
|
|
|
445 |
$resultat['nombreImg'] = intval($resultat['nombreImg']);
|
|
|
446 |
$resultat['nombreObs'] = intval($resultat['nombreObs']);
|
|
|
447 |
$resultat['somme'] = intval($resultat['somme']);
|
2176 |
mathias |
448 |
$liste[] = $resultat; // pas de clefs afin de renvoyer une "liste" JSON, qui sera interprétée en conservant l'ordre
|
2175 |
mathias |
449 |
}
|
2177 |
mathias |
450 |
$retour['resultats'] = $liste;
|
2175 |
mathias |
451 |
}
|
2177 |
mathias |
452 |
return $retour;
|
2175 |
mathias |
453 |
}
|
|
|
454 |
|
|
|
455 |
private function construireRequeteGrandsContributeurs($nombre = 10, $jours = 7, $critere = null) {
|
|
|
456 |
$req = "";
|
|
|
457 |
switch ($critere) {
|
|
|
458 |
case "obs":
|
|
|
459 |
$req = "SELECT ce_utilisateur , prenom_utilisateur , nom_utilisateur , courriel_utilisateur , count(*) as nombre" .
|
|
|
460 |
" FROM cel_obs" .
|
|
|
461 |
" WHERE transmission = 1" .
|
|
|
462 |
" AND TO_DAYS(NOW()) - TO_DAYS(date_transmission) <= $jours" .
|
|
|
463 |
" GROUP BY courriel_utilisateur ORDER BY nombre DESC LIMIT $nombre;";
|
|
|
464 |
break;
|
|
|
465 |
case "img":
|
|
|
466 |
$req = "SELECT co.ce_utilisateur , co.prenom_utilisateur , co.nom_utilisateur , co.courriel_utilisateur , count(DISTINCT ci.id_image) as nombre" .
|
|
|
467 |
" FROM cel_images ci" .
|
|
|
468 |
" RIGHT JOIN cel_obs_images coi ON coi.id_image = ci.id_image" .
|
|
|
469 |
" LEFT JOIN cel_obs co ON coi.id_observation = co.id_observation" .
|
|
|
470 |
" WHERE co.transmission = 1" .
|
|
|
471 |
" AND TO_DAYS(NOW()) - TO_DAYS(co.date_transmission) <= $jours" .
|
|
|
472 |
" GROUP BY co.courriel_utilisateur ORDER BY nombre DESC LIMIT $nombre;";
|
|
|
473 |
break;
|
|
|
474 |
default:
|
|
|
475 |
$req = "SELECT co.ce_utilisateur , co.prenom_utilisateur , co.nom_utilisateur , co.courriel_utilisateur ," .
|
|
|
476 |
" count(DISTINCT ci.id_image) as nombreImg, count(DISTINCT co.id_observation) as nombreObs," .
|
|
|
477 |
" count(DISTINCT ci.id_image) + count(DISTINCT co.id_observation) as somme" .
|
|
|
478 |
" FROM cel_images ci" .
|
|
|
479 |
" RIGHT JOIN cel_obs_images coi ON coi.id_image = ci.id_image" .
|
|
|
480 |
" LEFT JOIN cel_obs co ON coi.id_observation = co.id_observation" .
|
|
|
481 |
" WHERE co.transmission = 1" .
|
|
|
482 |
" AND TO_DAYS(NOW()) - TO_DAYS(co.date_transmission) <= $jours" .
|
|
|
483 |
" GROUP BY co.courriel_utilisateur" .
|
|
|
484 |
" ORDER BY somme DESC LIMIT $nombre;";
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
return $req;
|
|
|
488 |
}
|
694 |
jpm |
489 |
}
|
|
|
490 |
?>
|