Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 578 Rev 613
Line 15... Line 15...
15
// TODO : Config et Outils sont des classes statiques qui doivent poser des pb pour les tests...
15
// TODO : Config et Outils sont des classes statiques qui doivent poser des pb pour les tests...
16
class Statuts extends Commun {
16
class Statuts extends Commun {
Line 17... Line 17...
17
 
17
 
18
	protected $parametres = array();
18
	protected $parametres = array();
-
 
19
	protected $ressources = array();
19
	protected $ressources = array();
20
	
-
 
21
	private $bdd;
-
 
22
	private $retour_format = 'complet';
-
 
23
	private $retours_formats_autorises = array('complet','zone_geo');
-
 
24
	protected $table_version = null;
Line 20... Line 25...
20
	private $bdd;
25
	
21
 
26
 
22
	public function __construct($config = null) {
27
	public function __construct($config = null) {
-
 
28
		$this->config = $config;
23
		$this->config = $config;
29
		$this->bdd = $this->getBdd();
Line 24... Line 30...
24
		$this->bdd = $this->getBdd();
30
		$this->table_version = Config::get('table_version');
Line 25... Line 31...
25
	}
31
	}
26
	
32
	
Line -... Line 33...
-
 
33
	public function consulter($ressources, $parametres) {
27
	public function consulter($ressources, $parametres) {
34
 
Line 28... Line 35...
28
 
35
		$this->parametres = $parametres;
29
		$this->parametres = $parametres;
36
		$this->ressources = $ressources;
Line 30... Line 37...
30
		$this->ressources = $ressources;
37
 
31
 
38
		$this->affecterParametresParDefaut();
32
		$this->verifierParametres();
39
		$this->verifierParametres();
Line -... Line 40...
-
 
40
 
-
 
41
		$resultat = new ResultatService();
-
 
42
		$resultat->corps = $this->obtenirStatuts();
-
 
43
 
33
 
44
		return $resultat;
34
		$resultat = new ResultatService();
45
	}
Line 35... Line 46...
35
		$resultat->corps = $this->obtenirStatuts();
46
//+---------------------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+
36
 
47
 
Line 47... Line 58...
47
		
58
		
48
		if(!is_numeric($this->parametres['masque.nn'])) {
59
		if(!is_numeric($this->parametres['masque.nn'])) {
49
			$erreurs[] = 'la valeur pour masque.nn doit ĂȘtre un entier';
60
			$erreurs[] = 'la valeur pour masque.nn doit ĂȘtre un entier';
Line -... Line 61...
-
 
61
		}
-
 
62
		
-
 
63
		if(!in_array($this->retour_format, $this->retours_formats_autorises)) {
-
 
64
			$erreurs[] = 'la valeur '.$this->retour_format.' est inconnue';
50
		}
65
		}
51
		
66
		
52
		if (count($erreurs) > 0) {
67
		if (count($erreurs) > 0) {
53
			$message = implode('<br />', $erreurs);
68
			$message = implode('<br />', $erreurs);
54
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
69
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
Line 58... Line 73...
58
	
73
	
Line 59... Line 74...
59
//+---------------------------FONCTIONS DE REQUETE---------------------------------------------------------+
74
//+---------------------------FONCTIONS DE REQUETE---------------------------------------------------------+
60
 
75
 
61
	private function obtenirLois(Array $id_lois) {
76
	private function obtenirLois(Array $id_lois) {
62
		$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
77
		$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
63
		$requete = "SELECT * FROM sptb_lois_v2012 ".
78
		$requete = "SELECT * FROM sptb_lois_v".$this->table_version.' '.
64
		           "WHERE id IN (".implode(',',$id_lois).") ";   
79
		           "WHERE id IN (".implode(',',$id_lois).") ";   
Line -... Line 80...
-
 
80
		return $this->bdd->recupererTous($requete);
-
 
81
	}
-
 
82
	
-
 
83
	private function obtenirLoisZoneGeo(Array $id_lois) {
-
 
84
		$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
-
 
85
		$requete = "SELECT DISTINCT zone_application, code_zone_application FROM sptb_lois_v".$this->table_version.' '.
-
 
86
			           "WHERE id IN (".implode(',',$id_lois).") ";   
65
		return $this->bdd->recupererTous($requete);
87
		return $this->bdd->recupererTous($requete);
66
	}
88
	}
67
	
89
	
68
	private function obtenirStatuts() {		
90
	private function obtenirStatuts() {		
Line 69... Line 91...
69
		$requete = "SELECT * FROM sptb_especes_v2012 ".
91
		$requete = "SELECT * FROM sptb_especes_v".$this->table_version.' '.
70
		           "WHERE ".
92
		           "WHERE ".
71
		           "num_nom = ".$this->bdd->proteger($this->parametres['masque.nn'])."";
93
		           "num_nom = ".$this->bdd->proteger($this->parametres['masque.nn'])."";
72
		
94
		
Line 73... Line 95...
73
		$statuts = $this->bdd->recuperer($requete);
95
		$statuts = $this->bdd->recuperer($requete);
-
 
96
		$statuts = $this->formaterRetour($statuts);
-
 
97
		return $statuts;           
-
 
98
	}
-
 
99
	
-
 
100
//+---------------------------FONCTIONS DE FORMATAGE---------------------------------------------------------+
-
 
101
 
-
 
102
	private function formaterRetour($statuts_taxon) {
-
 
103
		switch($this->retour_format) {
-
 
104
			case 'zone_geo':
-
 
105
				$retour = $this->formaterStatutsTaxonZoneGeo($statuts_taxon);
-
 
106
			break;
-
 
107
					
-
 
108
			case 'complet':
-
 
109
				$retour = $this->formaterStatutsTaxon($statuts_taxon);
-
 
110
			break;
-
 
111
					
-
 
112
			default:
-
 
113
				$retour = $this->formaterStatutsTaxon();
-
 
114
			break;
-
 
115
		}
-
 
116
		return $retour;
-
 
117
	}
-
 
118
	
-
 
119
	private function formaterStatutsTaxonZoneGeo($statuts_taxon) {
-
 
120
		$lois_statuts = array();
-
 
121
		foreach ($statuts_taxon as $champ => $statut) {
-
 
122
			if($statut == "1") {
-
 
123
				$lois_statuts[] = $champ;
-
 
124
			}			
-
 
125
		}
-
 
126
		
74
		$statuts = $this->formaterStatutsTaxon($statuts);
127
		$zones_geo_lois = (!empty($lois_statuts)) ? $this->obtenirLoisZoneGeo($lois_statuts) : array();
75
		return $statuts;           
128
		
76
	}
129
		return $zones_geo_lois;
77
	
130
	}
78
//+---------------------------FONCTIONS DE FORMATAGE---------------------------------------------------------+
131
	
79
	private function formaterStatutsTaxon($statuts_taxon) {
132
	private function formaterStatutsTaxon($statuts_taxon) {
80
		$statuts_formates = array();
133
		$statuts_formates = array();
81
		unset($statuts_taxon['num_nom']);
134
		unset($statuts_taxon['num_nom']);
82
		unset($statuts_taxon['nom_sci']);
135
		unset($statuts_taxon['nom_sci']);
83
		$lois_statuts = array();
136
		$lois_statuts = array();
84
		foreach ($statuts_taxon as $champ => $statut) {
137
		foreach ($statuts_taxon as $champ => $statut) {
85
			if($statut == "1") {
138
			if($statut == "1") {
86
				$lois_statuts[] = $champ;
139
				$lois_statuts[] = $champ;
87
			}			
140
			}
88
		}
141
		}
89
		
142
	
90
		$statuts_formates = (!empty($lois_statuts)) ? $this->obtenirLois($lois_statuts) : array();
143
		$statuts_formates = (!empty($lois_statuts)) ? $this->obtenirLois($lois_statuts) : array();
91
		
144