1 |
<?php
|
1 |
<?php
|
2 |
/**
|
2 |
/**
|
3 |
* Widget fournissant des stats graphiques du CEL.
|
3 |
* Widget fournissant des stats graphiques du CEL.
|
4 |
* Encodage en entrée : utf8
|
4 |
* Encodage en entrée : utf8
|
5 |
* Encodage en sortie : utf8
|
5 |
* Encodage en sortie : utf8
|
6 |
*
|
6 |
*
|
7 |
* @author Jean-Pascal MILCENT <jpm@clapas.org>
|
7 |
* @author Jean-Pascal MILCENT <jpm@clapas.org>
|
8 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
8 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
9 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
9 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
10 |
* @version $Id$
|
10 |
* @version $Id$
|
11 |
* @copyright © 2010, Jean-Pascal MILCENT
|
11 |
* @copyright © 2010, Jean-Pascal MILCENT
|
12 |
*/
|
12 |
*/
|
13 |
class Stats extends WidgetCommun {
|
13 |
class Stats extends WidgetCommun {
|
14 |
const PAGE_DEFAUT = 'defaut';
|
14 |
const PAGE_DEFAUT = 'defaut';
|
15 |
const MODE_DEFAUT = 'defaut';
|
15 |
const MODE_DEFAUT = 'defaut';
|
16 |
const MODE_UTILISATEUR = 'utilisateur';
|
16 |
const MODE_UTILISATEUR = 'utilisateur';
|
17 |
private $page;
|
17 |
private $page;
|
18 |
private $mode;
|
18 |
private $mode;
|
19 |
|
19 |
|
20 |
/**
|
20 |
/**
|
21 |
* Méthode appelée avec une requête de type GET.
|
21 |
* Méthode appelée avec une requête de type GET.
|
22 |
*/
|
22 |
*/
|
23 |
public function executer() {
|
23 |
public function executer() {
|
24 |
$retour = null;
|
24 |
$retour = null;
|
25 |
|
25 |
|
26 |
extract($this->parametres);
|
26 |
extract($this->parametres);
|
27 |
$this->mode = (isset($mode)) ? $mode : self::MODE_DEFAUT;
|
27 |
$this->mode = (isset($mode)) ? $mode : self::MODE_DEFAUT;
|
28 |
$this->page = (isset($page)) ? $page : self::PAGE_DEFAUT;
|
28 |
$this->page = (isset($page)) ? $page : self::PAGE_DEFAUT;
|
29 |
|
29 |
|
30 |
$methode = $this->traiterNomMethodeExecuter($this->page);
|
30 |
$methode = $this->traiterNomMethodeExecuter($this->page);
|
31 |
if (method_exists($this, $methode)) {
|
31 |
if (method_exists($this, $methode)) {
|
32 |
$retour = $this->$methode();
|
32 |
$retour = $this->$methode();
|
33 |
} else {
|
33 |
} else {
|
34 |
$this->messages[] = "Ce type de carte '$methode' n'est pas disponible.";
|
34 |
$this->messages[] = "Ce type de carte '$methode' n'est pas disponible.";
|
35 |
}
|
35 |
}
|
36 |
|
36 |
|
37 |
if (is_null($retour)) {
|
37 |
if (is_null($retour)) {
|
38 |
$info = 'Un problème est survenu : '.print_r($this->messages, true);
|
38 |
$info = 'Un problème est survenu : '.print_r($this->messages, true);
|
39 |
$this->envoyer($info);
|
39 |
$this->envoyer($info);
|
40 |
} else {
|
40 |
} else {
|
41 |
$squelette = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR.$retour['squelette'].'.tpl.html';
|
41 |
$squelette = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR.$retour['squelette'].'.tpl.html';
|
42 |
$html = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
42 |
$html = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
43 |
$this->envoyer($html);
|
43 |
$this->envoyer($html);
|
44 |
}
|
44 |
}
|
45 |
}
|
45 |
}
|
46 |
|
46 |
|
47 |
/**
|
47 |
/**
|
48 |
* Stats par défaut
|
48 |
* Stats par défaut
|
49 |
*/
|
49 |
*/
|
50 |
public function executerDefaut() {
|
50 |
public function executerDefaut() {
|
51 |
$widget = null;
|
51 |
$widget = null;
|
52 |
|
52 |
|
53 |
switch ($this->mode) {
|
53 |
switch ($this->mode) {
|
54 |
case self::MODE_DEFAUT :
|
54 |
case self::MODE_DEFAUT :
|
55 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
55 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
56 |
$widget['squelette'] = 'stats';
|
56 |
$widget['squelette'] = 'stats';
|
57 |
break;
|
57 |
break;
|
58 |
case self::MODE_UTILISATEUR :
|
58 |
case self::MODE_UTILISATEUR :
|
59 |
if ($this->authentifierUtilisateur()) {
|
59 |
if ($this->authentifierUtilisateur()) {
|
60 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
60 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
61 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
61 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
62 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
62 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
63 |
$widget['squelette'] = 'stats_utilisateur';
|
63 |
$widget['squelette'] = 'stats_utilisateur';
|
64 |
}
|
64 |
}
|
65 |
break;
|
65 |
break;
|
66 |
default :
|
66 |
default :
|
67 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
67 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
68 |
}
|
68 |
}
|
69 |
|
69 |
|
70 |
if (!is_null($widget)) {
|
70 |
if (!is_null($widget)) {
|
71 |
$widget['donnees']['url_service'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelStatistique');
|
71 |
$widget['donnees']['url_service'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelStatistique');
|
72 |
$widget['donnees']['filtres'] = $this->parametres;
|
72 |
$widget['donnees']['filtres'] = $this->parametres;
|
73 |
}
|
73 |
}
|
74 |
return $widget;
|
74 |
return $widget;
|
75 |
}
|
75 |
}
|
76 |
|
76 |
|
77 |
private function recupererPrenomNomIdentifie() {
|
77 |
private function recupererPrenomNomIdentifie() {
|
78 |
$nom = '';
|
78 |
$nom = '';
|
79 |
if ($this->getAuthIdentifiant() != null) {
|
79 |
if ($this->getAuthIdentifiant() != null) {
|
80 |
$infos_utilisateur = $this->recupererUtilisateursNomPrenom(array($this->getAuthIdentifiant()));
|
80 |
$infos_utilisateur = $this->recupererUtilisateursNomPrenom(array($this->getAuthIdentifiant()));
|
81 |
if (array_key_exists($this->getAuthIdentifiant(), $infos_utilisateur)) {
|
81 |
if (array_key_exists($this->getAuthIdentifiant(), $infos_utilisateur)) {
|
82 |
$utilisateur = (array) $infos_utilisateur[$this->getAuthIdentifiant()];
|
82 |
$utilisateur = (array) $infos_utilisateur[$this->getAuthIdentifiant()];
|
83 |
$nom = $utilisateur['prenom'].' '.$utilisateur['nom'];
|
83 |
$nom = $utilisateur['prenom'].' '.$utilisateur['nom'];
|
84 |
} else {
|
84 |
} else {
|
85 |
$nom = $this->getAuthIdentifiant();
|
85 |
$nom = $this->getAuthIdentifiant();
|
86 |
}
|
86 |
}
|
87 |
}
|
87 |
}
|
88 |
return $nom;
|
88 |
return $nom;
|
89 |
}
|
89 |
}
|
90 |
|
90 |
|
91 |
public function executerNombres() {
|
91 |
public function executerNombres() {
|
92 |
$widget = null;
|
92 |
$widget = null;
|
93 |
|
93 |
|
94 |
switch ($this->mode) {
|
94 |
switch ($this->mode) {
|
95 |
case self::MODE_DEFAUT :
|
95 |
case self::MODE_DEFAUT :
|
96 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
96 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
97 |
break;
|
97 |
break;
|
98 |
case self::MODE_UTILISATEUR :
|
98 |
case self::MODE_UTILISATEUR :
|
99 |
if ($this->authentifierUtilisateur()) {
|
99 |
if ($this->authentifierUtilisateur()) {
|
100 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
100 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
101 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
101 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
102 |
}
|
102 |
}
|
103 |
break;
|
103 |
break;
|
104 |
default:
|
104 |
default:
|
105 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
105 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
106 |
}
|
106 |
}
|
107 |
|
107 |
|
108 |
if (!is_null($widget)) {
|
108 |
if (!is_null($widget)) {
|
109 |
$widget['squelette'] = 'stats_nbres';
|
109 |
$widget['squelette'] = 'stats_nbres';
|
110 |
$widget['donnees']['filtres'] = $this->parametres;
|
110 |
$widget['donnees']['filtres'] = $this->parametres;
|
111 |
}
|
111 |
}
|
112 |
|
112 |
|
113 |
return $widget;
|
113 |
return $widget;
|
114 |
}
|
114 |
}
|
115 |
|
115 |
|
116 |
private function recupererStatsTxtNombres() {
|
116 |
private function recupererStatsTxtNombres() {
|
117 |
// Récupération des données au format Json
|
117 |
// Récupération des données au format Json
|
118 |
$service = "CelStatistiqueTxt/Nombres";
|
118 |
$service = "CelStatistiqueTxt/Nombres";
|
119 |
|
119 |
|
120 |
$parametres = array();
|
120 |
$parametres = array();
|
121 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
121 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
122 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
122 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
123 |
}
|
123 |
}
|
124 |
if (isset($this->parametres['num_taxon'])) {
|
124 |
if (isset($this->parametres['num_taxon'])) {
|
125 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
125 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
126 |
}
|
126 |
}
|
127 |
if (isset($this->parametres['taxon'])) {
|
127 |
if (isset($this->parametres['taxon'])) {
|
128 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
128 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
129 |
}
|
129 |
}
|
130 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
130 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
131 |
|
131 |
|
132 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
132 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
133 |
$json = $this->getDao()->consulter($url);
|
133 |
$json = $this->getDao()->consulter($url);
|
134 |
return (array) json_decode($json);
|
134 |
return (array) json_decode($json);
|
135 |
}
|
135 |
}
|
136 |
|
136 |
|
137 |
public function executerListeTaxonsNbrePhotos() {
|
137 |
public function executerListeTaxonsNbrePhotos() {
|
138 |
$widget = null;
|
138 |
$widget = null;
|
139 |
$widget['donnees']['taxons'] = $this->recupererStatsTxtListeTaxonsNbrePhotos();
|
139 |
$widget['donnees']['taxons'] = $this->recupererStatsTxtListeTaxonsNbrePhotos();
|
140 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
140 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
141 |
$widget['donnees']['filtres'] = $this->parametres;
|
141 |
$widget['donnees']['filtres'] = $this->parametres;
|
142 |
$widget['squelette'] = 'liste_taxons_nbre_photos';
|
142 |
$widget['squelette'] = 'liste_taxons_nbre_photos';
|
143 |
return $widget;
|
143 |
return $widget;
|
144 |
}
|
144 |
}
|
145 |
|
145 |
|
146 |
private function recupererStatsTxtListeTaxonsNbrePhotos() {
|
146 |
private function recupererStatsTxtListeTaxonsNbrePhotos() {
|
147 |
// Récupération des données au format Json
|
147 |
// Récupération des données au format Json
|
148 |
$service = "CelStatistiqueTxt/ListeTaxonsNbrePhotos";
|
148 |
$service = "CelStatistiqueTxt/ListeTaxonsNbrePhotos";
|
149 |
|
149 |
|
150 |
$parametres = array();
|
150 |
$parametres = array();
|
151 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
151 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
152 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
152 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
153 |
}
|
153 |
}
|
154 |
if (isset($this->parametres['num_taxon'])) {
|
154 |
if (isset($this->parametres['num_taxon'])) {
|
155 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
155 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
156 |
}
|
156 |
}
|
157 |
if (isset($this->parametres['taxon'])) {
|
157 |
if (isset($this->parametres['taxon'])) {
|
158 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
158 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
159 |
}
|
159 |
}
|
160 |
if (isset($this->parametres['start'])) {
|
160 |
if (isset($this->parametres['start'])) {
|
161 |
$parametres[] = 'start='.$this->parametres['start'];
|
161 |
$parametres[] = 'start='.$this->parametres['start'];
|
162 |
}
|
162 |
}
|
163 |
if (isset($this->parametres['limit'])) {
|
163 |
if (isset($this->parametres['limit'])) {
|
164 |
$parametres[] = 'limit='.$this->parametres['limit'];
|
164 |
$parametres[] = 'limit='.$this->parametres['limit'];
|
165 |
}
|
165 |
}
|
166 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
166 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
167 |
|
167 |
|
168 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
168 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
169 |
$json = $this->getDao()->consulter($url);
|
169 |
$json = $this->getDao()->consulter($url);
|
170 |
return (array) json_decode($json);
|
170 |
return (array) json_decode($json);
|
171 |
}
|
171 |
}
|
172 |
|
172 |
|
173 |
public function executerListeUtilisateursNbrePhotos() {
|
173 |
public function executerListeUtilisateursNbrePhotos() {
|
174 |
$widget = null;
|
174 |
$widget = null;
|
175 |
$utilisateurs = $this->recupererStatsTxtListeUtilisateursNbrePhotos();
|
175 |
$utilisateurs = $this->recupererStatsTxtListeUtilisateursNbrePhotos();
|
- |
|
176 |
if (isset($utilisateurs)) {
|
176 |
$noms = $this->recupererUtilisateursNomPrenom(array_keys($utilisateurs));
|
177 |
$noms = $this->recupererUtilisateursNomPrenom(array_keys($utilisateurs));
|
177 |
foreach ($utilisateurs as $courriel => $infos) {
|
178 |
foreach ($utilisateurs as $courriel => $infos) {
|
178 |
if (array_key_exists($courriel, $noms)) {
|
179 |
if (array_key_exists($courriel, $noms)) {
|
179 |
$nom_infos = (array) $noms[$courriel];
|
180 |
$nom_infos = (array) $noms[$courriel];
|
180 |
$nom_fmt = $nom_infos['prenom'].' '.$nom_infos['nom'];
|
181 |
$nom_fmt = $nom_infos['prenom'].' '.$nom_infos['nom'];
|
181 |
$widget['donnees']['utilisateurs'][$nom_fmt] = $infos;
|
182 |
$widget['donnees']['utilisateurs'][$nom_fmt] = $infos;
|
- |
|
183 |
}
|
182 |
}
|
184 |
}
|
183 |
}
|
185 |
}
|
184 |
$widget['donnees']['filtres'] = $this->parametres;
|
186 |
$widget['donnees']['filtres'] = $this->parametres;
|
185 |
$widget['squelette'] = 'liste_utilisateurs_nbre_photos';
|
187 |
$widget['squelette'] = 'liste_utilisateurs_nbre_photos';
|
186 |
return $widget;
|
188 |
return $widget;
|
187 |
}
|
189 |
}
|
188 |
|
190 |
|
189 |
private function recupererStatsTxtListeUtilisateursNbrePhotos() {
|
191 |
private function recupererStatsTxtListeUtilisateursNbrePhotos() {
|
190 |
// Récupération des données au format Json
|
192 |
// Récupération des données au format Json
|
191 |
$service = "CelStatistiqueTxt/ListeUtilisateursNbrePhotos";
|
193 |
$service = "CelStatistiqueTxt/ListeUtilisateursNbrePhotos";
|
192 |
|
- |
|
193 |
$parametres = array();
|
194 |
|
194 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
195 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
195 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
196 |
$this->getDao()->ajouterParametre('utilisateur', $this->getAuthIdentifiant());
|
196 |
}
|
197 |
}
|
197 |
if (isset($this->parametres['num_taxon'])) {
|
198 |
if (isset($this->parametres['num_taxon'])) {
|
198 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
199 |
$this->getDao()->ajouterParametre('num_taxon', $this->parametres['num_taxon']);
|
199 |
}
|
200 |
}
|
200 |
if (isset($this->parametres['taxon'])) {
|
201 |
if (isset($this->parametres['taxon'])) {
|
201 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
202 |
$this->getDao()->ajouterParametre('taxon', $this->parametres['taxon']);
|
202 |
}
|
203 |
}
|
203 |
if (isset($this->parametres['start'])) {
|
204 |
if (isset($this->parametres['start'])) {
|
204 |
$parametres[] = 'start='.$this->parametres['start'];
|
205 |
$this->getDao()->ajouterParametre('start', $this->parametres['start']);
|
205 |
}
|
206 |
}
|
206 |
if (isset($this->parametres['limit'])) {
|
207 |
if (isset($this->parametres['limit'])) {
|
- |
|
208 |
$this->getDao()->ajouterParametre('limit', $this->parametres['limit']);
|
- |
|
209 |
}
|
- |
|
210 |
if (isset($this->parametres['tag'])) {
|
207 |
$parametres[] = 'limit='.$this->parametres['limit'];
|
211 |
$this->getDao()->ajouterParametre('tag', $this->parametres['tag']);
|
208 |
}
|
- |
|
209 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
212 |
}
|
- |
|
213 |
|
210 |
|
214 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
211 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
215 |
|
212 |
$json = $this->getDao()->consulter($url);
|
216 |
$json = $this->getDao()->consulter($url);
|
213 |
return (array) json_decode($json);
|
217 |
return (array) json_decode($json);
|
214 |
}
|
218 |
}
|
215 |
|
219 |
|
216 |
private function recupererUtilisateursNomPrenom($courriels) {
|
220 |
private function recupererUtilisateursNomPrenom($courriels) {
|
217 |
// Récupération des données au format Json
|
221 |
// Récupération des données au format Json
|
218 |
$service = "utilisateur/prenom-nom-par-courriel/".implode(',', $courriels);
|
222 |
$service = "utilisateur/prenom-nom-par-courriel/".implode(',', $courriels);
|
219 |
$url = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], $service);
|
223 |
$url = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], $service);
|
220 |
$json = $this->getDao()->consulter($url);
|
224 |
$json = $this->getDao()->consulter($url);
|
221 |
return (array) json_decode($json);
|
225 |
return (array) json_decode($json);
|
222 |
}
|
226 |
}
|
223 |
}
|
227 |
}
|