Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 657 | Rev 671 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 657 Rev 667
Line 104... Line 104...
104
		        	break;
104
					break;
105
		        case 'masque.anf' :
105
				case 'masque.anf' :
106
		        	$this->requete_condition []= " annee <= ".$this->getBdd()->proteger($val);
106
					$this->requete_condition []= " annee <= ".$this->getBdd()->proteger($val);
107
		        	break;
107
					break;
108
			}
108
			}
109
 
-
 
110
		}
109
		}
111
	}
110
	}
Line 112... Line -...
112
 
-
 
113
 
-
 
114
 
-
 
115
 
-
 
116
 
111
 
117
	public function verifierParamChamps($param, $val) {
112
	public function verifierParamChamps($param, $val) {
118
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
113
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
119
		$champs_demandes = explode(',', $val);
114
		$champs_demandes = explode(',', $val);
120
		$champs_verifies = array();
115
		$champs_verifies = array();
Line 259... Line 254...
259
		$this->format_reponse .= '/initiales';
254
		$this->format_reponse .= '/initiales';
260
		$this->requete_champ   = 'count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre ';
255
		$this->requete_champ   = 'count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre ';
261
		$this->requete_group_by  = ' GROUP BY rang, left(nom_sci, 2)';
256
		$this->requete_group_by  = ' GROUP BY rang, left(nom_sci, 2)';
262
	}
257
	}
Line 263... Line -...
263
 
-
 
264
 
-
 
265
 
258
 
Line 266... Line 259...
266
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
259
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
267
 
260
 
268
	public function assemblerLaRequete() {
261
	public function assemblerLaRequete() {
269
		if ( strrpos($this->format_reponse, 'noms/stats/') === false ) {
262
		if ( strrpos($this->format_reponse, 'noms/stats/') === false ) {
270
			$this->mettreAuFormat(); //Ds CommunNomsTaxons.php
263
			$this->mettreAuFormat(); //Ds CommunNomsTaxons.php
271
		}
264
		}
272
		$requete = 	' SELECT '.$this->distinct.' '.$this->requete_champ.
265
		$requete = 'SELECT '.$this->retournerChamps().' '.
273
      				' FROM '.$this->table
266
			"FROM {$this->table} ".
-
 
267
			$this->retournerRequeteCondition().' '.
274
      				.$this->retournerRequeteCondition()
268
			$this->requete_group_by.' '.
275
      				.$this->requete_group_by
269
			$this->retournerOrderBy().' '.
-
 
270
			$this->formerRequeteLimite();
-
 
271
		return $requete;
-
 
272
	}
-
 
273
 
-
 
274
	public function retournerChamps() {
-
 
275
		$sql = '';
-
 
276
		if ($this->distinct) {
-
 
277
			$sql .= $this->distinct.' ';
-
 
278
		}
-
 
279
		if ($this->requete_champ) {
-
 
280
			$sql .= $this->requete_champ.' ';
-
 
281
		}
-
 
282
 
-
 
283
		// Champs "virtuels" pour tier sur l'ensemble des résultats
-
 
284
		if (isset($this->parametres['retour.tri'])) {
-
 
285
			list($champ, $ordre) = $this->decouperParametreRetourTri();
-
 
286
			if ($champ == 'retenu') {
-
 
287
				$sql .= ", IF(num_nom = num_nom_retenu, '0', '1') AS nom_retenu_tri ";
-
 
288
			}
-
 
289
		}
-
 
290
 
Line -... Line 291...
-
 
291
		return $sql;
-
 
292
	}
-
 
293
 
-
 
294
	public function decouperParametreRetourTri() {
-
 
295
		$tri = array('', '');
-
 
296
		if (isset($this->parametres['retour.tri'])) {
-
 
297
			if (preg_match('/^(retenu)(?:,(ASC|DESC)|)$/', $this->parametres['retour.tri'], $match))
-
 
298
				$tri[0] = $match[1];
-
 
299
			$tri[1] = isset($match[2]) ? $match[2] : '';
-
 
300
		}
-
 
301
		return $tri;
-
 
302
	}
-
 
303
 
-
 
304
	public function retournerRequeteCondition() {
-
 
305
		$condition = '';
-
 
306
		if ($this->requete_condition) {
-
 
307
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
-
 
308
		}
-
 
309
		return $condition;
-
 
310
	}
-
 
311
 
-
 
312
	public function retournerOrderBy() {
-
 
313
		$orderBy = array();
-
 
314
 
-
 
315
		// Tri sur l'ensemble des résultats
-
 
316
		if (isset($this->parametres['retour.tri'])) {
-
 
317
			list($champ, $ordre) = $this->decouperParametreRetourTri();
-
 
318
			if ($champ == 'retenu') {
-
 
319
				$orderBy[] = "nom_retenu_tri $ordre";
-
 
320
			}
-
 
321
		}
-
 
322
		// Tri par défaut
-
 
323
		if ($this->format_reponse == 'noms') {
-
 
324
			$orderBy[] = 'nom_sci ASC';
-
 
325
		}
-
 
326
 
-
 
327
		$sql = '';
-
 
328
		if (count($orderBy > 0)) {
276
      				.$this->formerRequeteLimite();
329
			$sql = 'ORDER BY '.implode(', ', $orderBy).' ';
Line 277... Line 330...
277
      	return $requete;
330
		}
278
 
331
		return $sql;
279
	}
332
	}
Line 290... Line 343...
290
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
343
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
291
		}
344
		}
292
		return $this->requete_limite;
345
		return $this->requete_limite;
293
	}
346
	}
Line 294... Line -...
294
 
-
 
295
	public function retournerRequeteCondition() {
-
 
296
		$condition = '';
-
 
297
		if ($this->requete_condition) {
-
 
298
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
-
 
299
		}
-
 
300
		return $condition;
-
 
301
	}
-
 
302
 
-
 
303
 
347
 
304
	/** Recupere le nombre total de résultat d'une requete lancée. */
348
	/** Recupere le nombre total de résultat d'une requete lancée. */
305
	public function recupererTotalResultat() {
349
	public function recupererTotalResultat() {
306
		$total = null;
350
		$total = null;
307
		$requete = 'SELECT count(*) as nombre FROM '.$this->table.$this->retournerRequeteCondition().$this->requete_group_by;
351
		$requete = 'SELECT count(*) as nombre FROM '.$this->table.$this->retournerRequeteCondition().$this->requete_group_by;
Line 399... Line 443...
399
	public function ajouterRelations($relation) {
443
	public function ajouterRelations($relation) {
400
		$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
444
		$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
401
		$res = null;
445
		$res = null;
402
		$parametres_url = '';
446
		$parametres_url = '';
403
		if ($this->parametres != array()) $parametres_url = '?'.http_build_query($this->parametres, '', '&');
447
		if ($this->parametres != array()) $parametres_url = '?'.http_build_query($this->parametres, '', '&');
404
		$url = Config::get('url_service').'/'.$this->service.'/'
448
		$url = Config::get('url_service').'/'.$this->service.'/'.
405
									.$this->ressources[0].'/relations/'
449
			$this->ressources[0].'/relations/'.
406
									.$relation.$parametres_url;	Debug::printr($url);
450
			$relation.$parametres_url;
Line 407... Line 451...
407
 
451
 
Line 408... Line 452...
408
		$relation = $this->consulterHref($url);
452
		$relation = $this->consulterHref($url);
409
 
453
 
Line 562... Line 606...
562
		return $reponse;
606
		return $reponse;
563
	}
607
	}
Line 564... Line 608...
564
 
608
 
565
	public function formaterEnJsonMax($resultat) {
609
	public function formaterEnJsonMax($resultat) {
-
 
610
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
-
 
611
 
-
 
612
		// TODO : améliorer le trie des résultats
566
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
613
		// ATTENTION : ce comportement est étrange
567
		$masque = $this->recupererMasquePrincipal();
614
		$masque = $this->recupererMasquePrincipal();
568
		if (isset($masque)) {
615
		if (isset($masque)) {
569
			$resultat = $this->trierRechercheFloue($this->parametres[$masque[0]], $resultat, $masque[1]);
616
			$resultat = $this->trierRechercheFloue($this->parametres[$masque[0]], $resultat, $masque[1]);
-
 
617
		}
570
		}
618
 
571
		$table_retour_json['entete'] = $this->remplirJsonEntete();
619
		$table_retour_json['entete'] = $this->remplirJsonEntete();
572
		$table_retour_json['resultat'] = $this->remplirJsonResultat($resultat);
620
		$table_retour_json['resultat'] = $this->remplirJsonResultat($resultat);
573
		return $table_retour_json;
621
		return $table_retour_json;
Line 574... Line 622...
574
	}
622
	}
575
 
623
 
576
	public function remplirJsonResultat($resultat) {
624
	public function remplirJsonResultat($resultat) {
577
		$champs = null;
625
		$champs = null;
578
		if (array_key_exists('retour.champs', $this->parametres)) {
626
		if (array_key_exists('retour.champs', $this->parametres)) {
-
 
627
			$champs = explode(',', $this->parametres['retour.champs']);
579
			$champs = explode(',', $this->parametres['retour.champs']);
628
		}
580
		}
-
 
581
		$noms = array();
629
 
582
		$nomsRetenus = array();
630
		$noms = array();
583
		foreach ($resultat as $tab) {
631
		foreach ($resultat as $tab) {
584
			$this->table_retour = array();
632
			$this->table_retour = array();
585
			$num = $tab['num_nom'];
633
			$num = $tab['num_nom'];
Line 590... Line 638...
590
				$reponse_id = $this->formaterId($tab);
638
				$reponse_id = $this->formaterId($tab);
591
				$this->table_retour = array();
639
				$this->table_retour = array();
592
				$this->ajouterChampsPersonnalises($champs, $reponse_id);
640
				$this->ajouterChampsPersonnalises($champs, $reponse_id);
593
				$retour = array_merge($retour, $this->table_retour);
641
				$retour = array_merge($retour, $this->table_retour);
594
			}
642
			}
595
			// Sépare les noms retenus des autres noms
-
 
596
			if (isset($retour['retenu']) && $retour['retenu'] == 'true') {
-
 
597
				$nomsRetenus[$num] = $retour;
-
 
598
			} else {
-
 
599
				$noms[$num] = $retour;
643
			$noms[$num] = $retour;
600
			}
644
		}
601
		}
-
 
602
		// Trie par ordre alphabétique de nom_sci
-
 
603
		$nomsRetenus = Tableau::trierMD($nomsRetenus, array('nom_sci' => SORT_ASC));
-
 
604
		$noms = Tableau::trierMD($noms, array('nom_sci' => SORT_ASC));
-
 
605
 
-
 
606
		// Rassemble la liste des noms avec les noms retenus en premier
-
 
607
		$nomsRetour = array();
-
 
608
		Tableau::etendre($nomsRetour, $nomsRetenus);
-
 
609
		Tableau::etendre($nomsRetour, $noms);
-
 
Line 610... Line 645...
610
 
645
 
611
		return  $nomsRetour;
646
		return $noms;
Line 612... Line 647...
612
	}
647
	}
613
 
648
 
614
	public function remplirJsonEntete() {
649
	public function remplirJsonEntete() {