Subversion Repositories eFlore/Applications.moissonnage

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
19 delphine 1
<?php
2
 
3
 
4
define("RANG_FAMILLE", 180);
5
 
6
 
7
 
8
class Referentiel {
9
 
10
	private $nomComplet;
11
	private $nomCourt;
12
 
13
	private $taxon = null;
14
	private $bdd = null;
15
 
16
 
17
 
18
	public function __construct($nomReferentiel) {
19
		$this->nomComplet = $nomReferentiel;
20
		$this->nomCourt = current(explode('_', $nomReferentiel));
21
	}
22
 
23
 
24
 
25
	public function getReferentiel() {
26
		return $this->nomComplet;
27
	}
28
 
29
	public function getTaxon() {
30
		return $this->taxon;
31
	}
32
 
33
	public function setTaxon($taxon) {
34
		$this->taxon = $taxon;
35
	}
36
 
37
 
38
	public function recupererTaxon($numTaxon) {
39
		if (is_null($numTaxon) || $numTaxon == 0) {
40
			return null;
41
		}
42
 
43
		$methodeChamps = 'nomsChamps' . ucfirst($this->nomCourt);
44
		extract($this->$methodeChamps());
45
		// requete SQL a executer
46
		$requete = "SELECT {$nn} AS nn, {$nt} AS nt, {$ns} AS nom, rang FROM {$this->nomComplet}"
47
			. " WHERE {$nt}={$numTaxon} AND num_nom={$nn} ORDER BY rang, If(num_nom={$nn},0,1) LIMIT 0,1";
48
		$taxon = $this->getBdd()->recuperer($requete);
49
		return ($taxon == false ? null : $taxon);
50
	}
51
 
52
 
53
	public function recupererSousTaxons($listeNn = null) {
54
		if ($this->taxon['rang'] < RANG_FAMILLE) {
55
			// recherche de sous taxons seulement si le rang du taxon precedemment recupere
56
			// est du niveau de la famille ou inferieur (genre, espece)
57
			return array();
58
		}
59
 
60
		$methodeChamps = 'nomsChamps' . ucfirst($this->nomCourt);
61
		extract($this->$methodeChamps());
62
		if (is_null($listeNn)) {
63
			$listeNn = $this->taxon['nn'];
64
		}
65
		$requete = "SELECT {$nn} AS nn, {$nt} As nt, {$ns} AS nom FROM {$this->nomComplet} WHERE"
66
			. " num_tax_sup IN ({$listeNn}) AND num_nom={$nn}";
67
		$sousTaxons = $this->getBdd()->recupererTous($requete);
68
 
69
		$listeComplete = array();
70
		$nouvelleListeNn = '';
71
		foreach ($sousTaxons as $sousTaxon) {
72
			$listeComplete[] = $sousTaxon;
73
			$nouvelleListeNn .= (strlen($nouvelleListeNn) == 0 ? '' : ',') . $sousTaxon['nn'];
74
		}
75
		// recherche de sous taxons au niveau inferieur (parcours recursif de la methode)
76
		if (count($listeComplete) > 0) {
77
			$listeComplete = array_merge($listeComplete, $this->recupererSousTaxons($nouvelleListeNn));
78
		}
79
 
80
		return $listeComplete;
81
	}
82
 
83
 
84
	private function getBdd() {
85
		if (is_null($this->bdd)) {
86
			$this->bdd = new Bdd();
87
		}
88
		$this->bdd->requeter("USE tb_eflore");
89
		return $this->bdd;
90
	}
91
 
92
	private function nomsChampsBdtfx() {
93
		return array('nn' => 'num_nom_retenu', 'nt' => 'num_taxonomique', 'ns' => 'nom_sci');
94
	}
95
 
96
	private function nomsChampsBdtxa() {
97
		return array('nn' => 'num_nom_retenu', 'nt' => 'num_tax', 'ns' => 'nom_sci');
98
	}
99
 
100
 
101
 
102
	public static function listeReferentielsDisponibles() {
103
		$tableau = array();
104
		$tableauPartiel = explode(',', Config::get('referentielsDispo'));
105
		$tableauPartiel = array_map('trim', $tableauPartiel);
106
		foreach ($tableauPartiel as $champ) {
107
			if (strpos($champ, '=') === false) {
108
				$tableau[] = $champ;
109
			} else {
110
				list($cle, $val) = explode('=', $champ);
111
				$clePropre = trim($cle);
112
				$valeurPropre = trim($val);
113
				$tableau[$clePropre] = $valeurPropre;
114
			}
115
		}
116
		return $tableau;
117
	}
118
 
119
}
120
 
121
/*$nombreCriteres = 0;
122
 foreach ($masques as $masque => $valeur) {
123
if ($masque == 'masque.nt') {
124
$requete .= ($nombreCriteres == 0 ? '' : " AND ") . "";
125
$nombreCriteres ++;
126
} elseif ($masque == 'masque.nn') {
127
$requete .= ($nombreCriteres == 0 ? '' : " AND ") . "num_nom = (SELECT num_nom_retenu"
128
		. " FROM {$this->nomComplet} WHERE num_nom={$valeur})";
129
$nombreCriteres ++;
130
}  elseif ($masque == 'masque.ns') {
131
$requete .= ($nombreCriteres == 0 ? '' : " AND ") . "({$ns} LIKE '{$valeur}%'"
132
		. " OR num_nom=(SELECT {$nn} FROM {$this->nomComplet} WHERE {$ns} LIKE '{$valeur}%'"
133
				. " ORDER BY rang LIMIT 0, 1))";
134
$nombreCriteres ++;
135
}
136
}
137
$requete .=  " ";*/
138
 
139
?>