Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 1111 Rev 1185
Line 93... Line 93...
93
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
93
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
94
			throw new Exception($message, $code);
94
			throw new Exception($message, $code);
95
		}
95
		}
96
	}
96
	}
Line 97... Line 97...
97
 
97
 
98
	private function obtenirLois(Array $id_lois) {
98
	private function obtenirLois(Array $id_lois) { 
99
		$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
99
		$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
100
		$requete = "SELECT * FROM ".Config::get('bdd_table_lois').' '.
100
		$requete = "SELECT * FROM ".Config::get('bdd_table_lois').' '.
101
		           "WHERE id IN (".implode(',',$id_lois).") ";   
101
		           "WHERE id IN (".implode(',',$id_lois).") ORDER BY zone_application ASC";
-
 
102
		$lois = $this->bdd->recupererTous($requete, 'ASSOC');
-
 
103
		foreach ($lois as $loi) {
-
 
104
			$retour[$loi['id']] = $loi;
-
 
105
		}
102
		return $this->bdd->recupererTous($requete);
106
		return $retour;
Line 103... Line 107...
103
	}
107
	}
104
	
108
	
105
	private function obtenirLoisZoneGeo(Array $id_lois) {
109
	private function obtenirLoisZoneGeo(Array $id_lois) {
106
		$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
110
		$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
107
		$requete = "SELECT DISTINCT zone_application, code_zone_application FROM ".Config::get('bdd_table_lois').' '.
111
		$requete = "SELECT DISTINCT zone_application, code_zone_application FROM ".Config::get('bdd_table_lois').' '.
108
			           "WHERE id IN (".implode(',',$id_lois).") ";   
112
			           "WHERE id IN (".implode(',',$id_lois).") ORDER BY zone_application ASC";   
Line 109... Line 113...
109
		return $this->bdd->recupererTous($requete);
113
		return $this->bdd->recupererTous($requete);
110
	}
114
	}
111
	
115
	
112
	private function obtenirStatuts() {
116
	private function obtenirStatuts() {
113
		if ($this->nn_demande != null) {
117
		if ($this->nn_demande != null) {
114
			$conditions_taxons = array();
118
			$conditions_taxons = array();
Line 115... Line 119...
115
			$conditions_taxons = $this->obtenirNumNomTaxonsSuperieurs(Config::get('referentiel'), $this->nn_demande);
119
			$conditions_taxons = $this->obtenirNumNomTaxonsSuperieurs(Config::get('referentiel'), $this->nn_demande);
116
			$conditions_taxons[] = $this->bdd->proteger($this->nn_demande);
120
			$conditions_taxons[] = $this->nn_demande;
117
		}
121
		}
Line 124... Line 128...
124
		// pagination
128
		// pagination
125
		$requete .= " LIMIT " . $this->navigation_depart . ", " . $this->navigation_limite;
129
		$requete .= " LIMIT " . $this->navigation_depart . ", " . $this->navigation_limite;
126
		$requete .= ' -- ' . __FILE__ . ':' . __LINE__;
130
		$requete .= ' -- ' . __FILE__ . ':' . __LINE__;
127
		//echo "REQ: $requete\n";
131
		//echo "REQ: $requete\n";
Line 128... Line 132...
128
				
132
				
129
		$statuts = $this->bdd->recuperer($requete);
133
		$statuts = $this->bdd->recupererTous($requete, 'ASSOC');
130
		//echo "STATUTS: " . print_r($statuts, true) . "\n";
134
		//echo "STATUTS: " . print_r($statuts, true) . "\n";
131
		//echo "CPT: " . count($statuts) . "\n";
135
		//echo "CPT: " . count($statuts) . "\n";
132
		$statuts = $this->formaterRetour($statuts);
136
		$statuts = $this->formaterRetour($statuts);
133
		return $statuts;           
137
		return $statuts;           
134
	}	
138
	}	
Line 135... Line 139...
135
//+---------------------------FONCTIONS DE FORMATAGE---------------------------------------------------------+
139
//+---------------------------FONCTIONS DE FORMATAGE---------------------------------------------------------+
-
 
140
 
-
 
141
	private function formaterRetour($statuts_taxon) {
-
 
142
		$retour = "";
-
 
143
		if ($statuts_taxon) {
-
 
144
			foreach ($statuts_taxon as $nom) {				
-
 
145
				$f[$nom['cd_protection']][$nom['num_nom']] = $nom['nom_sci'];
136
 
146
				$lois_statuts[] = $nom['cd_protection'];
137
	private function formaterRetour($statuts_taxon) {
147
			}
138
		switch($this->retour_format) {
148
			switch($this->retour_format) {
139
			case 'zone_geo':
149
				case 'zone_geo':
-
 
150
					$retour = $this->obtenirLoisZoneGeo($lois_statuts);
-
 
151
				break;
-
 
152
						
-
 
153
				case 'nom':
-
 
154
					$lois = $this->obtenirLois($lois_statuts);
-
 
155
					foreach ($statuts_taxon as $nom) {
-
 
156
						$retour[$nom['num_nom']]['num_nom'] = $nom['num_nom'];
Line -... Line 157...
-
 
157
						$retour[$nom['num_nom']]['nom_sci'] = $nom['nom_sci'];
-
 
158
						$retour[$nom['num_nom']]['lois'][$nom['cd_protection']] = $lois[$nom['cd_protection']];
140
				$retour = $this->formaterStatutsTaxonZoneGeo($statuts_taxon);
159
					
-
 
160
					}
-
 
161
				break;
-
 
162
				case 'complet':
-
 
163
					$lois = $this->obtenirLois($lois_statuts);
-
 
164
					foreach ($lois as $id => $loi) {
-
 
165
						$retour[$loi['zone_application']][$id] = $loi;
-
 
166
						foreach ($f[$id] as $num_nom => $nom_sci) {
-
 
167
							$retour[$loi['zone_application']][$id]['nom_sci'][$num_nom] = $nom_sci;
-
 
168
						}
-
 
169
							
-
 
170
					}
141
			break;
171
					break;
142
					
172
						
-
 
173
				default:
Line 143... Line -...
143
			case 'complet':
-
 
144
				$retour = $this->formaterStatutsTaxon($statuts_taxon);
-
 
145
			break;
-
 
146
					
174
					$retour = $this->formaterStatutsTaxon();
-
 
175
				break;
147
			default:
176
			}
148
				$retour = $this->formaterStatutsTaxon();
177
					
Line 149... Line -...
149
			break;
-
 
150
		}
-
 
151
		return $retour;
-
 
152
	}
-
 
Line 153... Line -...
153
	
-
 
154
	private function formaterStatutsTaxonZoneGeo($statuts_taxon) {
-
 
155
		$lois_statuts = array();
-
 
156
		// cas ou la requĂȘte (obtenirStatuts()) ne retourne rien
-
 
157
		if(!$statuts_taxon) return array();
-
 
158
 
-
 
159
		foreach ($statuts_taxon as $champ => $statut) {
-
 
160
			if($statut == "1") {
-
 
161
				$lois_statuts[] = $champ;
-
 
162
			}			
-
 
163
		}
-
 
164
		
-
 
165
		$zones_geo_lois = (!empty($lois_statuts)) ? $this->obtenirLoisZoneGeo($lois_statuts) : array();
-
 
166
		
-
 
167
		return $zones_geo_lois;
-
 
168
	}
-
 
169
	
-
 
170
	private function formaterStatutsTaxon($statuts_taxon) {
-
 
171
		$statuts_formates = array();
-
 
172
		$lois_statuts = array();
-
 
173
		
-
 
174
		if(is_array($statuts_taxon)) {
-
 
175
			unset($statuts_taxon['num_nom']);
-
 
176
			unset($statuts_taxon['num_nom_retenu']);
-
 
177
			unset($statuts_taxon['nom_sci']);
-
 
178
			foreach ($statuts_taxon as $champ => $statut) {
-
 
179
				if($statut == "1") {
-
 
180
					$lois_statuts[] = $champ;
-
 
181
				}
-
 
182
			}
-
 
183
		}
178
		}
184
	
179
		
185
		$statuts_formates = (!empty($lois_statuts)) ? $this->obtenirLois($lois_statuts) : array();
180
		return $retour;