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 |
if ($this->mode == self::MODE_DEFAUT) {
|
52 |
if ($this->mode == self::MODE_DEFAUT) {
|
53 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
- |
|
54 |
$widget['donnees']['url_service'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelStatistique');
|
- |
|
55 |
$widget['squelette'] = 'stats';
|
53 |
$widget['squelette'] = 'stats';
|
56 |
} else if ($this->mode == self::MODE_UTILISATEUR) {
|
54 |
} else if ($this->mode == self::MODE_UTILISATEUR) {
|
57 |
if ($this->authentifierUtilisateur()) {
|
55 |
if ($this->authentifierUtilisateur()) {
|
58 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
- |
|
59 |
$widget['donnees']['url_service'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelStatistique');
|
- |
|
60 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
56 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
61 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
57 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
62 |
$widget['squelette'] = 'stats_utilisateur';
|
58 |
$widget['squelette'] = 'stats_utilisateur';
|
63 |
}
|
59 |
}
|
64 |
} else {
|
60 |
} else {
|
65 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
61 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
66 |
}
|
62 |
}
|
- |
|
63 |
|
- |
|
64 |
if (!is_null($widget)) {
|
- |
|
65 |
$widget['donnees'] = (array) $this->recupererStatsTxtNombres();
|
- |
|
66 |
$widget['donnees']['url_service'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelStatistique');
|
- |
|
67 |
$widget['donnees']['filtres'] = $this->parametres;
|
- |
|
68 |
}
|
67 |
return $widget;
|
69 |
return $widget;
|
68 |
}
|
70 |
}
|
69 |
|
71 |
|
70 |
private function recupererPrenomNomIdentifie() {
|
72 |
private function recupererPrenomNomIdentifie() {
|
71 |
$nom = '';
|
73 |
$nom = '';
|
72 |
if ($this->getAuthIdentifiant() != null) {
|
74 |
if ($this->getAuthIdentifiant() != null) {
|
73 |
$infos_utilisateur = $this->recupererUtilisateursNomPrenom(array($this->getAuthIdentifiant()));
|
75 |
$infos_utilisateur = $this->recupererUtilisateursNomPrenom(array($this->getAuthIdentifiant()));
|
74 |
if (array_key_exists($this->getAuthIdentifiant(), $infos_utilisateur)) {
|
76 |
if (array_key_exists($this->getAuthIdentifiant(), $infos_utilisateur)) {
|
75 |
$utilisateur = (array) $infos_utilisateur[$this->getAuthIdentifiant()];
|
77 |
$utilisateur = (array) $infos_utilisateur[$this->getAuthIdentifiant()];
|
76 |
$nom = $utilisateur['prenom'].' '.$utilisateur['nom'];
|
78 |
$nom = $utilisateur['prenom'].' '.$utilisateur['nom'];
|
77 |
} else {
|
79 |
} else {
|
78 |
$nom = $this->getAuthIdentifiant();
|
80 |
$nom = $this->getAuthIdentifiant();
|
79 |
}
|
81 |
}
|
80 |
}
|
82 |
}
|
81 |
return $nom;
|
83 |
return $nom;
|
82 |
}
|
84 |
}
|
83 |
|
85 |
|
84 |
public function executerNombres() {
|
86 |
public function executerNombres() {
|
85 |
$widget = null;
|
87 |
$widget = null;
|
86 |
|
88 |
|
87 |
if ($this->mode == self::MODE_DEFAUT) {
|
89 |
if ($this->mode == self::MODE_DEFAUT) {
|
88 |
$widget['donnees'] = $this->recupererStatsTxtNombres();
|
90 |
$widget['donnees'] = '';
|
89 |
} else if ($this->mode == self::MODE_UTILISATEUR) {
|
91 |
} else if ($this->mode == self::MODE_UTILISATEUR) {
|
90 |
if ($this->authentifierUtilisateur()) {
|
92 |
if ($this->authentifierUtilisateur()) {
|
91 |
$widget['donnees'] = $this->recupererStatsTxtNombres();
|
- |
|
92 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
93 |
$widget['donnees']['utilisateur_nom_prenom'] = $this->recupererPrenomNomIdentifie();
|
93 |
}
|
94 |
}
|
94 |
} else {
|
95 |
} else {
|
95 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
96 |
$this->messages[] = "Le mode '{$this->mode}' est inconnu.";
|
96 |
}
|
97 |
}
|
97 |
|
98 |
|
98 |
if (!is_null($widget)) {
|
99 |
if (!is_null($widget)) {
|
- |
|
100 |
$widget['donnees'] = $this->recupererStatsTxtNombres();
|
99 |
$widget['squelette'] = 'stats_nbres';
|
101 |
$widget['squelette'] = 'stats_nbres';
|
100 |
if (array_key_exists('taxon', $this->parametres)) {
|
- |
|
101 |
$widget['donnees']['taxon'] = trim($this->parametres['taxon'], "'");
|
102 |
$widget['donnees']['filtres'] = $this->parametres;
|
102 |
}
|
- |
|
103 |
}
|
103 |
}
|
104 |
|
104 |
|
105 |
return $widget;
|
105 |
return $widget;
|
106 |
}
|
106 |
}
|
107 |
|
107 |
|
108 |
private function recupererStatsTxtNombres() {
|
108 |
private function recupererStatsTxtNombres() {
|
109 |
// Récupération des données au format Json
|
109 |
// Récupération des données au format Json
|
110 |
$service = "CelStatistiqueTxt/Nombres";
|
110 |
$service = "CelStatistiqueTxt/Nombres";
|
111 |
|
111 |
|
112 |
$parametres = array();
|
112 |
$parametres = array();
|
113 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
113 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
114 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
114 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
115 |
}
|
115 |
}
|
116 |
if (isset($this->parametres['num_taxon'])) {
|
116 |
if (isset($this->parametres['num_taxon'])) {
|
117 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
117 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
118 |
}
|
118 |
}
|
119 |
if (isset($this->parametres['taxon'])) {
|
119 |
if (isset($this->parametres['taxon'])) {
|
120 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
120 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
121 |
}
|
121 |
}
|
122 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
122 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
123 |
|
123 |
|
124 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
124 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
125 |
$json = $this->getDao()->consulter($url);
|
125 |
$json = $this->getDao()->consulter($url);
|
126 |
return (array) json_decode($json);
|
126 |
return (array) json_decode($json);
|
127 |
}
|
127 |
}
|
128 |
|
128 |
|
129 |
public function executerListeTaxonsNbrePhotos() {
|
129 |
public function executerListeTaxonsNbrePhotos() {
|
130 |
$widget = null;
|
130 |
$widget = null;
|
131 |
$widget['donnees']['taxons'] = $this->recupererStatsTxtListeTaxonsNbrePhotos();
|
131 |
$widget['donnees']['taxons'] = $this->recupererStatsTxtListeTaxonsNbrePhotos();
|
132 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
132 |
$widget['donnees']['utilisateur'] = $this->getAuthIdentifiant();
|
133 |
if (array_key_exists('taxon', $this->parametres)) {
|
- |
|
134 |
$widget['donnees']['taxon'] = trim($this->parametres['taxon'], "'");
|
133 |
$widget['donnees']['filtres'] = $this->parametres;
|
135 |
}
|
- |
|
136 |
$widget['squelette'] = 'liste_taxons_nbre_photos';
|
134 |
$widget['squelette'] = 'liste_taxons_nbre_photos';
|
137 |
return $widget;
|
135 |
return $widget;
|
138 |
}
|
136 |
}
|
139 |
|
137 |
|
140 |
private function recupererStatsTxtListeTaxonsNbrePhotos() {
|
138 |
private function recupererStatsTxtListeTaxonsNbrePhotos() {
|
141 |
// Récupération des données au format Json
|
139 |
// Récupération des données au format Json
|
142 |
$service = "CelStatistiqueTxt/ListeTaxonsNbrePhotos";
|
140 |
$service = "CelStatistiqueTxt/ListeTaxonsNbrePhotos";
|
143 |
|
141 |
|
144 |
$parametres = array();
|
142 |
$parametres = array();
|
145 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
143 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
146 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
144 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
147 |
}
|
145 |
}
|
148 |
if (isset($this->parametres['num_taxon'])) {
|
146 |
if (isset($this->parametres['num_taxon'])) {
|
149 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
147 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
150 |
}
|
148 |
}
|
151 |
if (isset($this->parametres['taxon'])) {
|
149 |
if (isset($this->parametres['taxon'])) {
|
152 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
150 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
153 |
}
|
151 |
}
|
154 |
if (isset($this->parametres['start'])) {
|
152 |
if (isset($this->parametres['start'])) {
|
155 |
$parametres[] = 'start='.$this->parametres['start'];
|
153 |
$parametres[] = 'start='.$this->parametres['start'];
|
156 |
}
|
154 |
}
|
157 |
if (isset($this->parametres['limit'])) {
|
155 |
if (isset($this->parametres['limit'])) {
|
158 |
$parametres[] = 'limit='.$this->parametres['limit'];
|
156 |
$parametres[] = 'limit='.$this->parametres['limit'];
|
159 |
}
|
157 |
}
|
160 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
158 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
161 |
|
159 |
|
162 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
160 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
163 |
$json = $this->getDao()->consulter($url);
|
161 |
$json = $this->getDao()->consulter($url);
|
164 |
return (array) json_decode($json);
|
162 |
return (array) json_decode($json);
|
165 |
}
|
163 |
}
|
166 |
|
164 |
|
167 |
public function executerListeUtilisateursNbrePhotos() {
|
165 |
public function executerListeUtilisateursNbrePhotos() {
|
168 |
$widget = null;
|
166 |
$widget = null;
|
169 |
$utilisateurs = $this->recupererStatsTxtListeUtilisateursNbrePhotos();
|
167 |
$utilisateurs = $this->recupererStatsTxtListeUtilisateursNbrePhotos();
|
170 |
$noms = $this->recupererUtilisateursNomPrenom(array_keys($utilisateurs));
|
168 |
$noms = $this->recupererUtilisateursNomPrenom(array_keys($utilisateurs));
|
171 |
foreach ($utilisateurs as $courriel => $infos) {
|
169 |
foreach ($utilisateurs as $courriel => $infos) {
|
172 |
if (array_key_exists($courriel, $noms)) {
|
170 |
if (array_key_exists($courriel, $noms)) {
|
173 |
$nom_infos = (array) $noms[$courriel];
|
171 |
$nom_infos = (array) $noms[$courriel];
|
174 |
$nom_fmt = $nom_infos['prenom'].' '.$nom_infos['nom'];
|
172 |
$nom_fmt = $nom_infos['prenom'].' '.$nom_infos['nom'];
|
175 |
$widget['donnees']['utilisateurs'][$nom_fmt] = $infos;
|
173 |
$widget['donnees']['utilisateurs'][$nom_fmt] = $infos;
|
176 |
}
|
174 |
}
|
177 |
}
|
175 |
}
|
178 |
if (array_key_exists('taxon', $this->parametres)) {
|
- |
|
179 |
$widget['donnees']['taxon'] = trim($this->parametres['taxon'], "'");
|
176 |
$widget['donnees']['filtres'] = $this->parametres;
|
180 |
}
|
- |
|
181 |
$widget['squelette'] = 'liste_utilisateurs_nbre_photos';
|
177 |
$widget['squelette'] = 'liste_utilisateurs_nbre_photos';
|
182 |
return $widget;
|
178 |
return $widget;
|
183 |
}
|
179 |
}
|
184 |
|
180 |
|
185 |
private function recupererStatsTxtListeUtilisateursNbrePhotos() {
|
181 |
private function recupererStatsTxtListeUtilisateursNbrePhotos() {
|
186 |
// Récupération des données au format Json
|
182 |
// Récupération des données au format Json
|
187 |
$service = "CelStatistiqueTxt/ListeUtilisateursNbrePhotos";
|
183 |
$service = "CelStatistiqueTxt/ListeUtilisateursNbrePhotos";
|
188 |
|
184 |
|
189 |
$parametres = array();
|
185 |
$parametres = array();
|
190 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
186 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == self::MODE_UTILISATEUR && $this->getAuthIdentifiant() != null) {
|
191 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
187 |
$parametres[] = 'utilisateur='.$this->getAuthIdentifiant();
|
192 |
}
|
188 |
}
|
193 |
if (isset($this->parametres['num_taxon'])) {
|
189 |
if (isset($this->parametres['num_taxon'])) {
|
194 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
190 |
$parametres[] = 'num_taxon='.$this->parametres['num_taxon'];
|
195 |
}
|
191 |
}
|
196 |
if (isset($this->parametres['taxon'])) {
|
192 |
if (isset($this->parametres['taxon'])) {
|
197 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
193 |
$parametres[] = 'taxon='.$this->parametres['taxon'];
|
198 |
}
|
194 |
}
|
199 |
if (isset($this->parametres['start'])) {
|
195 |
if (isset($this->parametres['start'])) {
|
200 |
$parametres[] = 'start='.$this->parametres['start'];
|
196 |
$parametres[] = 'start='.$this->parametres['start'];
|
201 |
}
|
197 |
}
|
202 |
if (isset($this->parametres['limit'])) {
|
198 |
if (isset($this->parametres['limit'])) {
|
203 |
$parametres[] = 'limit='.$this->parametres['limit'];
|
199 |
$parametres[] = 'limit='.$this->parametres['limit'];
|
204 |
}
|
200 |
}
|
205 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
201 |
$service .= (count($parametres) > 0) ? '?'.implode('&', $parametres) : '';
|
206 |
|
202 |
|
207 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
203 |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
|
208 |
$json = $this->getDao()->consulter($url);
|
204 |
$json = $this->getDao()->consulter($url);
|
209 |
return (array) json_decode($json);
|
205 |
return (array) json_decode($json);
|
210 |
}
|
206 |
}
|
211 |
|
207 |
|
212 |
private function recupererUtilisateursNomPrenom($courriels) {
|
208 |
private function recupererUtilisateursNomPrenom($courriels) {
|
213 |
// Récupération des données au format Json
|
209 |
// Récupération des données au format Json
|
214 |
$service = "utilisateur/prenom-nom-par-courriel/".implode(',', $courriels);
|
210 |
$service = "utilisateur/prenom-nom-par-courriel/".implode(',', $courriels);
|
215 |
$url = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], $service);
|
211 |
$url = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], $service);
|
216 |
$json = $this->getDao()->consulter($url);
|
212 |
$json = $this->getDao()->consulter($url);
|
217 |
return (array) json_decode($json);
|
213 |
return (array) json_decode($json);
|
218 |
}
|
214 |
}
|
219 |
}
|
215 |
}
|