Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 560 Rev 562
Line 4... Line 4...
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
 * Cas d'utilisation :
7
 * Cas d'utilisation :
8
 * /CelStatistique/TypeDeGraph : retourne le graphique demandé
8
 * /CelStatistique/TypeDeGraph : retourne le graphique demandé
-
 
9
 * Paramêtres :
9
 * /CelStatistique/TypeDeGraph/1 : retourne le graphique demandé sur le serveur 1 (voir http://code.google.com/intl/fr/apis/chart/docs/making_charts.html#enhancements)
10
 * serveur=[0-9] : retourne le graphique demandé sur le serveur numéro 0 à 9 (voir http://code.google.com/intl/fr/apis/chart/docs/making_charts.html#enhancements )
10
 *
11
 *
11
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @version $Id$
15
 * @version $Id$
Line 25... Line 26...
25
 
26
 
26
		if (isset($param[0])) {
27
		if (isset($param[0])) {
27
			$graph_demande = array_shift($param);
28
			$graph_demande = array_shift($param);
28
			$methode = 'get'.$graph_demande;
29
			$methode = 'get'.$graph_demande;
29
			if (method_exists($this, $methode)) {
-
 
30
				$serveur = isset($param[1]) ? array_shift($param).'.' : '';
30
			if (method_exists($this, $methode)) {
31
				$graph = $this->$methode($param);
31
				$graph = $this->$methode($param);
32
			} else {
32
			} else {
33
				$this->messages[] = "Ce type de graphique '$graph_demande' n'est pas disponible.";
33
				$this->messages[] = "Ce type de graphique '$graph_demande' n'est pas disponible.";
34
			}
34
			}
35
		} else {
35
		} else {
36
			$this->messages[] = "Le premier paramêtre du service CEL Statistique doit correspondre au type de graphique.";
36
			$this->messages[] = "Le premier paramêtre du service CEL Statistique doit correspondre au type de graphique.";
Line 37... Line 37...
37
		}
37
		}
-
 
38
 
38
 
39
		if (!is_null($graph)) {
39
		if (!is_null($graph)) {
40
			$serveur = (isset($_GET['serveur']) && preg_match('/^[0-9]$/', $_GET['serveur'])) ? $_GET['serveur'].'.' : '';
40
			$url = "http://{$serveur}chart.apis.google.com/chart";
41
			$url = "http://{$serveur}chart.apis.google.com/chart";
41
			$contexte = stream_context_create(
42
			$contexte = stream_context_create(
42
				array('http' => array(
43
				array('http' => array(
Line 50... Line 51...
50
		}
51
		}
51
	}
52
	}
Line 52... Line 53...
52
 
53
 
53
	private function getEvolImgLieesParMois($param) {
54
	private function getEvolImgLieesParMois($param) {
54
		// Récupération des données
-
 
55
 
55
		// Récupération des données
56
		$requete = 	"SELECT DATE_FORMAT(ci_meta_date_ajout, '%Y%m') AS periode, COUNT(ci_id_image) AS nbre ".
56
		$requete = 	"SELECT DATE_FORMAT(ci_meta_date_ajout, '%Y%m') AS periode, COUNT(ci_id_image) AS nbre ".
57
			"FROM cel_obs_images LEFT JOIN cel_images ON (coi_ce_image = ci_id_image) ".
57
			"FROM cel_obs_images LEFT JOIN cel_images ON (coi_ce_image = ci_id_image) ".
58
			"WHERE ci_meta_date_ajout != '0000-00-00 00:00:00' ".
58
			"WHERE ci_meta_date_ajout != '0000-00-00 00:00:00' ".
59
			'GROUP BY periode '.
59
			'GROUP BY periode '.
Line 118... Line 118...
118
		return $graph;
118
		return $graph;
119
	}
119
	}
Line 120... Line 120...
120
 
120
 
121
	private function getEvolImgParMois($param) {
121
	private function getEvolImgParMois($param) {
122
		// Récupération des données
-
 
123
 
122
		// Récupération des données
124
		$requete = 	"SELECT DATE_FORMAT(ci_meta_date_ajout, '%Y%m') AS periode, COUNT(ci_id_image) AS nbre ".
123
		$requete = 	"SELECT DATE_FORMAT(ci_meta_date_ajout, '%Y%m') AS periode, COUNT(ci_id_image) AS nbre ".
125
			"FROM cel_images ".
124
			"FROM cel_images ".
126
			"WHERE ci_meta_date_ajout != '0000-00-00 00:00:00' ".
125
			"WHERE ci_meta_date_ajout != '0000-00-00 00:00:00' ".
127
			'GROUP BY periode '.
126
			'GROUP BY periode '.
Line 508... Line 507...
508
			'chts'	=> '000000,12');
507
			'chts'	=> '000000,12');
509
		return $graph;
508
		return $graph;
510
	}
509
	}
Line 511... Line 510...
511
 
510
 
-
 
511
	private function getNbreObsAvecIndicationGeo($param) {
-
 
512
		$utilisateur = isset($_GET['utilisateur']) ? ' AND identifiant = '.$this->bdd->quote($_GET['utilisateur']) : '';
512
	private function getNbreObsAvecIndicationGeo($param) {
513
		
513
		// Récupération des données
514
		// Récupération des données
514
		$total = $this->executerRequeteNombre('cel_inventory', 'id');
515
		$total = $this->executerRequeteNombre('cel_inventory', 'id', $utilisateur);
-
 
516
		$where_commune = "location != '000null' AND location != '' AND location IS NOT NULL";
515
		$obs['commune'] = $this->executerRequeteNombre('cel_inventory', 'id', "location != '000null' AND location != '' AND location IS NOT NULL");
517
		$obs['commune'] = $this->executerRequeteNombre('cel_inventory', 'id', $where_commune);
516
		$obs['commune identifiée'] = $this->executerRequeteNombre('cel_inventory', 'id', "id_location != '000null' AND id_location != '' AND id_location IS NOT NULL");
518
		$obs['commune identifiée'] = $this->executerRequeteNombre('cel_inventory', 'id', "id_location != '000null' AND id_location != '' AND id_location IS NOT NULL");
517
		$obs['lieu-dit'] = $this->executerRequeteNombre('cel_inventory', 'id', "lieudit != '000null' AND lieudit != '' AND lieudit IS NOT NULL");
519
		$obs['lieu-dit'] = $this->executerRequeteNombre('cel_inventory', 'id', "lieudit != '000null' AND lieudit != '' AND lieudit IS NOT NULL");
518
		$obs['station'] = $this->executerRequeteNombre('cel_inventory', 'id', "station != '000null' AND station != '' AND station IS NOT NULL");
520
		$obs['station'] = $this->executerRequeteNombre('cel_inventory', 'id', "station != '000null' AND station != '' AND station IS NOT NULL");
519
		$obs['milieu'] = $this->executerRequeteNombre('cel_inventory', 'id', "milieu != '000null' AND milieu != '' AND milieu IS NOT NULL");
521
		$obs['milieu'] = $this->executerRequeteNombre('cel_inventory', 'id', "milieu != '000null' AND milieu != '' AND milieu IS NOT NULL");
Line 752... Line 754...
752
		//echo '<pre>'.print_r($graph,true).'</pre>';
754
		//echo '<pre>'.print_r($graph,true).'</pre>';
753
		return $graph;
755
		return $graph;
754
	}
756
	}
Line 755... Line 757...
755
 
757
 
-
 
758
	private function getNuagePointsObsParHeureEtJourSemaine($param) {
-
 
759
		$utilisateur = isset($_GET['utilisateur']) ? $this->bdd->quote($_GET['utilisateur']) : false;
756
	private function getNuagePointsObsParHeureEtJourSemaine($param) {
760
		
-
 
761
		// Récupération des données de la base
-
 
762
		$requete = 	'SELECT identifiant, DATE_FORMAT(date_creation, "%w-%H") AS periode, (ROUND(LOG10(COUNT(id))) + 1) AS nbre '.
-
 
763
					'FROM cel_inventory '.
-
 
764
					'WHERE date_creation != "0000-00-00 00:00:00" '.
-
 
765
					'	AND identifiant '.($utilisateur ? "= $utilisateur " : 'LIKE "%@%" ').
757
		// Récupération des données de la base
766
					'GROUP BY periode, identifiant ';
758
		$observations = $this->executerRequeteEvol('cel_inventory', 'id', '%w-%H', null, 'date_creation');
767
		$infos = $this->executerRequete($requete);
-
 
768
		
-
 
769
		// Traitement résulat requête
-
 
770
		$observations = array();
-
 
771
		foreach ($infos as $info) {
-
 
772
			if (isset($observations[$info['periode']])) {
-
 
773
				$observations[$info['periode']] += $info['nbre'];
-
 
774
			} else {
-
 
775
				$observations[$info['periode']] = $info['nbre'];
-
 
776
			}
-
 
777
		}
759
 
778
		
760
		// Postraitement des données
779
		// Postraitement des données
761
		// Jour de la semaine
780
		// Jour de la semaine
762
		$donnees['joursSemaine'] = array();
781
		$donnees['joursSemaine'] = array();
763
		for ($njs = 0; $njs < 7; $njs++) {
782
		for ($njs = 0; $njs < 7; $njs++) {
Line 883... Line 902...
883
		//echo '<pre>'.print_r($graph,true).'</pre>';
902
		//echo '<pre>'.print_r($graph,true).'</pre>';
884
		return $graph;
903
		return $graph;
885
	}
904
	}
Line 886... Line 905...
886
 
905
 
-
 
906
	private function executerRequeteEvol($table, $champ, $format_date = '%Y%m', $where = null, $champ_date = 'date_creation', $order_by = null, $limit = null) {
-
 
907
		$utilisateur = isset($_GET['utilisateur']) ? $this->bdd->quote($_GET['utilisateur']) : false;
887
	private function executerRequeteEvol($table, $champ, $format_date = '%Y%m', $where = null, $champ_date = 'date_creation', $order_by = null, $limit = null) {
908
		
888
		$requete = 	"SELECT DATE_FORMAT($champ_date, '$format_date') AS periode, COUNT($champ) AS nbre ".
909
		$requete = 	"SELECT DATE_FORMAT($champ_date, '$format_date') AS periode, COUNT($champ) AS nbre ".
889
					"FROM $table ".
910
					"FROM $table ".
-
 
911
					"WHERE $champ_date != '0000-00-00 00:00:00' ".
890
					"WHERE $champ_date != '0000-00-00 00:00:00' ".
912
					($utilisateur ? "	AND identifiant = $utilisateur " : '').
891
					((is_null($where)) ? '' : " AND $where ").
913
					((is_null($where)) ? '' : " AND $where ").
892
					'GROUP BY periode '.
914
					'GROUP BY periode '.
893
					((is_null($order_by)) ? '' : "ORDER BY $order_by ");
915
					((is_null($order_by)) ? '' : "ORDER BY $order_by ");
894
					((is_null($limit)) ? '' : "LIMIT $limit ");
916
					((is_null($limit)) ? '' : "LIMIT $limit ");