Subversion Repositories eFlore/Applications.cel

Rev

Rev 695 | Rev 703 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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