Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1388 Rev 1389
Line 31... Line 31...
31
error_reporting(E_ALL);
31
error_reporting(E_ALL);
Line 32... Line 32...
32
 
32
 
Line 33... Line 33...
33
class ListeObservations2 {
33
class ListeObservations2 {
34
 
-
 
35
	private $conteneur;
-
 
36
	private $navigation;
34
 
37
	private $masque;
35
	private $conteneur;
38
	private $gestionBdd;
36
	private $gestionBdd;
39
	private $bdd;
37
	private $bdd;
40
	private $parametres = array();
-
 
41
	private $ressources = array();
-
 
Line 42... Line 38...
42
	private $tri = 'date_transmission';
38
	private $parametres = array();
43
	private $directionTri = 'desc';
39
	private $ressources = array();
44
 
40
 
45
	static $tris_possibles = array('date_observation');
41
	static $tris_possibles = array('date_observation');
Line 135... Line 131...
135
		$req['groupby'][] = 'dob.id_observation';
131
		$req['groupby'][] = 'dob.id_observation';
Line 136... Line 132...
136
 
132
 
Line 137... Line 133...
137
		$db = $this->bdd;
133
		$db = $this->bdd;
138
 
134
 
139
		// filtrage de l'INPUT
135
		// filtrage de l'INPUT
140
		$params = self::requestFilterParams($parametres, $this->conteneur);
136
		$params = self::requestFilterParams($parametres, self::$parametres_autorises, $this->conteneur);
Line 141... Line 137...
141
		// création des contraintes (masques)
137
		// création des contraintes (masques)
142
		self::sqlAddConstraint($params, $db, $req, $this->conteneur);
138
		self::sqlAddConstraint($params, $db, $req, $this->conteneur);
Line 167... Line 163...
167
			$total = 0;
163
			$total = 0;
168
		}
164
		}
Line 169... Line 165...
169
 
165
 
170
		// 6) JSON output
166
		// 6) JSON output
171
		$resultat = new ResultatService();
-
 
172
 
-
 
173
		$prev_url = $next_url = NULL;
-
 
174
 
-
 
175
		$next_offset = $params['navigation.depart'] + $params['navigation.limite'];
-
 
176
		if($next_offset < $total) {
-
 
177
			$next_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : Config::get('url_service'),
-
 
178
								http_build_query(array_merge($params, array('navigation.depart' => $next_offset))));
-
 
179
		}
-
 
180
		$prev_offset = $params['navigation.depart'] - $params['navigation.limite'];
-
 
181
		if($prev_offset > 0) {
167
		$resultat = new ResultatService();
182
			$prev_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : Config::get('url_service'),
-
 
183
								http_build_query(array_merge($params, array('navigation.depart' => $prev_offset))));
-
 
184
		}
-
 
185
 
-
 
186
		$resultat->corps = array('entete' => array(
-
 
187
			'masque' => http_build_query(array_diff_key($params, array_flip(array('navigation.depart', 'navigation.limite', 'tri', 'ordre')))),
-
 
188
			'total' => $total,
-
 
189
			'depart' => $params['navigation.depart'],
-
 
190
			'limite' => $params['navigation.limite'],
-
 
191
			'href.precedent' => $prev_url,
-
 
192
			'href.suivant' => $next_url
-
 
193
		),
168
		$resultat->corps = array('entete' => self::makeJSONHeader($total, $params, Config::get('url_service')),
Line 194... Line 169...
194
								 'resultats' => $observations);
169
								 'resultats' => $observations);
195
		
170
		
Line 340... Line 315...
340
		}
315
		}
341
		if(!empty($p['masque.ns'])) {
316
		if(!empty($p['masque.ns'])) {
342
			$req['where'][] = 'dob.nom_sel LIKE '.$db->proteger($p['masque.ns'].'%');
317
			$req['where'][] = 'dob.nom_sel LIKE '.$db->proteger($p['masque.ns'].'%');
343
		}
318
		}
344
		if(!empty($p['masque.nn'])) {
319
		if(!empty($p['masque.nn'])) {
345
			$req['where'][] = sprintf('dob.nom_sel_nn = %d', $p['masque.nn']);
320
			$req['where'][] = sprintf('dob.nom_sel_nn = %1$d OR dob.nom_ret_nn = %1$d', $p['masque.nn']);
346
		}
321
		}
347
		if(!empty($p['masque.referentiel'])) {
322
		if(!empty($p['masque.referentiel'])) {
348
			$req['where'][] = sprintf('dob.nom_referentiel = %s', $db->proteger($p['masque.referentiel']));
323
			$req['where'][] = sprintf('dob.nom_referentiel = %s', $db->proteger($p['masque.referentiel']));
349
		}
324
		}
350
		if(!empty($p['masque.commune'])) {
325
		if(!empty($p['masque.commune'])) {
Line 373... Line 348...
373
							   'masque.ns' => $p['masque'],
348
							   'masque.ns' => $p['masque'],
374
							   'masque.famille' => $p['masque'],
349
							   'masque.famille' => $p['masque'],
375
							   'masque.date' => $p['masque'],
350
							   'masque.date' => $p['masque'],
376
							   'masque.genre' => $p['masque'],
351
							   'masque.genre' => $p['masque'],
377
							   /* milieu: TODO */ );
352
							   /* milieu: TODO */ );
378
			$or_masque = self::requestFilterParams($or_params, $c);
353
			$or_masque = self::requestFilterParams($or_params, array_keys($or_params), $c);
379
			// $or_req = array('select' => array(), 'join' => array(), 'where' => array(), 'groupby' => array(), 'having' => array());
354
			// $or_req = array('select' => array(), 'join' => array(), 'where' => array(), 'groupby' => array(), 'having' => array());
380
			$or_req = array('join' => array(), 'where' => array());
355
			$or_req = array('join' => array(), 'where' => array());
381
			self::sqlAddConstraint($or_masque, $db, $or_req);
356
			self::sqlAddConstraint($or_masque, $db, $or_req);
Line 382... Line 357...
382
 
357
 
Line 564... Line 539...
564
	}
539
	}
Line 565... Line 540...
565
 
540
 
566
 
541
 
567
	/* filtre et valide les paramètres reconnus.
542
	/* filtre et valide les paramètres reconnus.
568
	   Effectue *toute* la sanitization *sauf* l'escape-string */
543
	   Effectue *toute* la sanitization *sauf* l'escape-string */
Line 569... Line 544...
569
	static function requestFilterParams(Array $params, Conteneur $c = NULL /* pour la récup des départements */ ) {
544
	static function requestFilterParams(Array $params, $parametres_autorises, Conteneur $c = NULL /* pour la récup des départements */ ) {
570
		$params = array_intersect_key($params, array_flip(self::$parametres_autorises));
545
		$params = array_intersect_key($params, array_flip($parametres_autorises));
571
 
546
 
Line 687... Line 662...
687
		$p = array_merge(self::$default_params, $p);
662
		$p = array_merge(self::$default_params, $p);
Line 688... Line 663...
688
 
663
 
689
		return $p;
664
		return $p;
Line -... Line 665...
-
 
665
	}
-
 
666
 
-
 
667
	static function makeJSONHeader($total, $params, $url_service) {
-
 
668
		$prev_url = $next_url = NULL;
-
 
669
 
-
 
670
		$next_offset = $params['navigation.depart'] + $params['navigation.limite'];
-
 
671
		if($next_offset < $total) {
-
 
672
			$next_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $url_service,
-
 
673
								http_build_query(array_merge($params, array('navigation.depart' => $next_offset))));
-
 
674
		}
-
 
675
 
-
 
676
		$prev_offset = $params['navigation.depart'] - $params['navigation.limite'];
-
 
677
		if($prev_offset > 0) {
-
 
678
			$prev_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $url_service,
-
 
679
								http_build_query(array_merge($params, array('navigation.depart' => $prev_offset))));
-
 
680
		}
-
 
681
 
-
 
682
		return array(
-
 
683
			'masque' => http_build_query(array_diff_key($params, array_flip(array('navigation.depart', 'navigation.limite', 'tri', 'ordre')))),
-
 
684
			'total' => $total,
-
 
685
			'depart' => $params['navigation.depart'],
-
 
686
			'limite' => $params['navigation.limite'],
-
 
687
			'href.precedent' => $prev_url,
-
 
688
			'href.suivant' => $next_url
690
	}
689
		);