Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 657 Rev 667
Line 47... Line 47...
47
					$this->ajouterFiltreMasque('nom_sci', $val);
47
					$this->ajouterFiltreMasque('nom_sci', $val);
48
					break;
48
					break;
49
				case 'masque.sg' :
49
				case 'masque.sg' :
50
					$this->ajouterFiltreMasque('nom_supra_generique', $val);
50
					$this->ajouterFiltreMasque('nom_supra_generique', $val);
51
					break;
51
					break;
52
		        case 'masque.gen' :
52
				case 'masque.gen' :
53
		        	$this->ajouterFiltreMasque('genre', $val);
53
					$this->ajouterFiltreMasque('genre', $val);
54
		        	break;
54
					break;
55
		        case 'masque.sp' :
55
				case 'masque.sp' :
56
		        	$this->ajouterFiltreMasque('epithete_sp', $val);
56
					$this->ajouterFiltreMasque('epithete_sp', $val);
57
		        	break;
57
					break;
58
		        case 'masque.ssp' :
58
				case 'masque.ssp' :
59
		        	$this->ajouterFiltreMasque('epithete_infra_sp',$val);
59
					$this->ajouterFiltreMasque('epithete_infra_sp',$val);
60
		        	break;
60
					break;
61
		        case 'masque.au' :
61
				case 'masque.au' :
62
		        	$this->ajouterFiltreMasque('auteur', $val);
62
					$this->ajouterFiltreMasque('auteur', $val);
63
		        	break;
63
					break;
64
		        case 'masque.an' :
64
				case 'masque.an' :
65
		        	$this->ajouterFiltreMasque('annee', $val);
65
					$this->ajouterFiltreMasque('annee', $val);
66
					break;
66
					break;
67
		        case 'masque.bib' :
67
				case 'masque.bib' :
68
		        	$this->ajouterFiltreMasque('biblio_origine',$val);
68
					$this->ajouterFiltreMasque('biblio_origine',$val);
69
		        	break;
69
					break;
70
		        case 'masque.ad' :
70
				case 'masque.ad' :
71
		        	$this->ajouterFiltreMasque('nom_addendum', $val);
71
					$this->ajouterFiltreMasque('nom_addendum', $val);
72
		        	break;
72
					break;
73
		        case 'masque.nn' :
73
				case 'masque.nn' :
74
		        	$this->requete_condition []= 'num_nom IN ('.$val.')';
74
					$this->requete_condition []= 'num_nom IN ('.$val.')';
75
		        	$this->masque['num_nom'] = "num_nom=$val";
75
					$this->masque['num_nom'] = "num_nom=$val";
76
		        	break;
76
					break;
77
		        case 'masque.nt' :
77
				case 'masque.nt' :
78
		        	$this->requete_condition []= 'num_tax IN ('.$val.')';
78
					$this->requete_condition []= 'num_tax IN ('.$val.')';
79
		        	$this->masque['num_tax'] = "num_tax=$val";
79
					$this->masque['num_tax'] = "num_tax=$val";
80
		        	break;
80
					break;
81
		        case 'masque.rg' :
81
				case 'masque.rg' :
82
		        	$this->ajouterFiltreMasque('rang', $val);
82
					$this->ajouterFiltreMasque('rang', $val);
83
		        	break;
83
					break;
84
		        case 'retour.champs' :
84
				case 'retour.champs' :
85
		        	$this->verifierParamChamps($param, $val);
85
					$this->verifierParamChamps($param, $val);
86
		        	break;
86
					break;
87
		        case 'distinct' :
87
				case 'distinct' :
88
		        	$this->ajouterNomDistinct($val);
88
					$this->ajouterNomDistinct($val);
89
		        	break;
89
					break;
90
		        case 'masque.fam' :
90
				case 'masque.fam' :
91
		        	$this->ajouterFiltreMasque('famille', $val);
91
					$this->ajouterFiltreMasque('famille', $val);
92
		        	break;
92
					break;
93
		        case 'masque.sto' :
93
				case 'masque.sto' :
94
		        	$this->ajouterFiltreMasque('statut_origine', $val);
94
					$this->ajouterFiltreMasque('statut_origine', $val);
95
		        	break;
95
					break;
96
		        case 'masque.sti' :
96
				case 'masque.sti' :
97
		        	$this->ajouterFiltreMasque('statut_introduction', $val);
97
					$this->ajouterFiltreMasque('statut_introduction', $val);
98
		        	break;
98
					break;
99
		        case 'masque.stc' :
99
				case 'masque.stc' :
100
		        	$this->ajouterFiltreMasque('statut_culture', $val);
100
					$this->ajouterFiltreMasque('statut_culture', $val);
101
		        	break;
101
					break;
102
		        case 'masque.and' :
102
				case 'masque.and' :
103
		        	$this->requete_condition []= " annee >= ".$this->getBdd()->proteger($val);
103
					$this->requete_condition []= " annee >= ".$this->getBdd()->proteger($val);
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
 
-
 
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
		}
Line -... Line 301...
-
 
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
			}
-
 
601
		}
644
		}
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() {