Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1103 | Rev 1106 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1103 Rev 1105
1
<?php
1
<?php
2
/**
2
/**
3
* Description :
-
 
4
* Retourne la liste des taxons répertoriés par le projet chorodep
3
* Retourne la liste des noms répertoriés par le projet chorodep
5
* 
4
* 
6
* @package chorodep
5
* @package chorodep
7
* @author Tela Botanica <equipe-dev@tela-botanica.org>
6
* @author Tela Botanica <equipe-dev@tela-botanica.org>
8
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
7
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
9
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
8
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
10
* @version 1.0
9
* @version 1.0
11
* @copyright 1999-2014 Tela Botanica (accueil@tela-botanica.org)
10
* @copyright 1999-2014 Tela Botanica (accueil@tela-botanica.org)
12
*/
11
*/
13
 
12
 
14
class Noms extends Commun {
13
class Noms extends Commun {
15
 
14
 
16
	protected $serviceNom = 'noms';
15
	protected $serviceNom = 'noms';
17
	protected $table;
16
	protected $table;
18
	protected $masque;
17
	protected $masque;
19
	protected $depart;
18
	protected $depart;
20
	protected $limite;
19
	protected $limite;
21
	protected $tri;
20
	protected $tri;
22
	protected $tri_dir;
21
	protected $tri_dir;
23
 
22
 
24
	public function __construct($config = null) {
23
	public function __construct($config = null) {
25
		parent::__construct($config);
24
		parent::__construct($config);
26
		$this->masque = array();
25
		$this->masque = array();
27
		$this->depart = 0;
26
		$this->depart = 0;
28
		$this->limite = 20;
27
		$this->limite = 20;
29
		$this->tri = 'nom_sci';
28
		$this->tri = 'nom_sci';
30
		$this->tri_dir = 'ASC';
29
		$this->tri_dir = 'ASC';
31
		$this->init();
30
		$this->init();
32
	}
31
	}
33
 
32
 
34
	protected function init() {
33
	protected function init() {
35
		$this->traiterVersionProjet();
34
		$this->traiterVersionProjet();
36
		$this->table = $this->table_version[0];
35
		$this->table = $this->table_version[0];
37
	}
36
	}
38
 
37
 
39
	/**
38
	/**
40
	 * Récupère les paramètres de navigation
39
	 * Récupère les paramètres de navigation
41
	 * @param type $parametres
40
	 * @param type $parametres
42
	 */
41
	 */
43
	protected function setDepartLimite($parametres) {
42
	protected function setDepartLimite($parametres) {
44
		if(isset($parametres['navigation.depart']) && $parametres['navigation.depart'] != '') {
43
		if(isset($parametres['navigation.depart']) && $parametres['navigation.depart'] != '') {
45
			$this->depart = max(0, intval($parametres['navigation.depart']));
44
			$this->depart = max(0, intval($parametres['navigation.depart']));
46
		}
45
		}
47
		if(isset($parametres['navigation.limite']) && $parametres['navigation.limite'] != '') {
46
		if(isset($parametres['navigation.limite']) && $parametres['navigation.limite'] != '') {
48
			$this->limite = max(0, intval($parametres['navigation.limite']));
47
			$this->limite = max(0, intval($parametres['navigation.limite']));
49
		}
48
		}
50
	}
49
	}
51
 
50
 
52
	/**
51
	/**
53
	 * Récupère les paramètres de filtrage
52
	 * Récupère les paramètres de filtrage
54
	 * @param type $parametres
53
	 * @param type $parametres
55
	 */
54
	 */
56
	protected function setMasque($parametres) {
55
	protected function setMasque($parametres) {
57
		if(isset($parametres['masque.nom']) && $parametres['masque.nom'] != '') {
56
		if(isset($parametres['masque.nom']) && $parametres['masque.nom'] != '') {
58
			$this->masque['nom'] = $parametres['masque.nom'];
57
			$this->masque['nom'] = $parametres['masque.nom'];
59
		}
58
		}
60
		if(isset($parametres['masque.zone-geo']) && $parametres['masque.zone-geo'] != '') {
59
		if(isset($parametres['masque.zone-geo']) && $parametres['masque.zone-geo'] != '') {
61
			$this->masque['zone-geo'] = $parametres['masque.zone-geo'];
60
			$zg = $parametres['masque.zone-geo'];
-
 
61
			// Tango Corse
-
 
62
			if ($zg == '2A' || $zg == '2B') {
-
 
63
				$zg = '20';
-
 
64
			}
-
 
65
			$this->masque['zone-geo'] = $zg;
62
		}
66
		}
63
	}
67
	}
64
 
68
 
65
	/**
69
	/**
66
	 * Récupère les paramètres de tri
70
	 * Récupère les paramètres de tri
67
	 * @param type $parametres
71
	 * @param type $parametres
68
	 */
72
	 */
69
	protected function setTri($parametres) {
73
	protected function setTri($parametres) {
70
		if(isset($parametres['retour.tri']) && $parametres['retour.tri'] != '') {
74
		if(isset($parametres['retour.tri']) && $parametres['retour.tri'] != '') {
71
			$this->tri = $parametres['retour.tri'];
75
			$this->tri = $parametres['retour.tri'];
72
		}
76
		}
73
		if(isset($parametres['retour.ordre']) && in_array($parametres['retour.ordre'], array('ASC', 'DESC'))) {
77
		if(isset($parametres['retour.ordre']) && in_array($parametres['retour.ordre'], array('ASC', 'DESC'))) {
74
			$this->tri_dir = $parametres['retour.ordre'];
78
			$this->tri_dir = $parametres['retour.ordre'];
75
		}
79
		}
76
	}
80
	}
77
 
81
 
78
	public function consulter($ressources, $parametres) {
82
	public function consulter($ressources, $parametres) {
79
		$donnees = array();
83
		$donnees = array();
80
 
84
 
81
		$this->setDepartLimite($parametres);
85
		$this->setDepartLimite($parametres);
82
		$this->setMasque($parametres);
86
		$this->setMasque($parametres);
83
		$this->setTri($parametres);
87
		$this->setTri($parametres);
84
		$noms = $this->listeNoms();
88
		$noms = $this->listeNoms();
85
		$total = $this->compterNoms();
89
		$total = $this->compterNoms();
86
 
90
 
87
		$url_base = Config::get('url_service');
91
		$url_base = Config::get('url_service');
88
 
92
 
89
		$masqueEnParams = array();
93
		$masqueEnParams = array();
90
		foreach ($this->masque as $k => $v) {
94
		foreach ($this->masque as $k => $v) {
91
			$masqueEnParams[] = 'masque.' . $k . '=' . $v;
95
			$masqueEnParams[] = 'masque.' . $k . '=' . $v;
92
		}
96
		}
93
		$masqueEnParams = implode('&', $masqueEnParams);
97
		$masqueEnParams = implode('&', $masqueEnParams);
94
 
98
 
95
		$donnees['entete'] = array(
99
		$donnees['entete'] = array(
96
			'masque' => $masqueEnParams,
100
			'masque' => $masqueEnParams,
97
			'total' => $total,
101
			'total' => $total,
98
			'depart' => $this->depart,
102
			'depart' => $this->depart,
99
			'limite' => $this->limite
103
			'limite' => $this->limite
100
		);
104
		);
101
		if ($this->depart > 0) {
105
		if ($this->depart > 0) {
102
			$donnees['entete']['href.precedent'] = $url_base . '/' . $this->serviceNom . '?'
106
			$donnees['entete']['href.precedent'] = $url_base . '/' . $this->serviceNom . '?'
103
					. 'navigation.depart=' . max(0, ($this->depart - $this->limite)) . '&navigation.limite=' . $this->limite
107
					. 'navigation.depart=' . max(0, ($this->depart - $this->limite)) . '&navigation.limite=' . $this->limite
104
					. '&retour.tri=' . $this->tri . '&retour.ordre=' . $this->tri_dir
108
					. '&retour.tri=' . $this->tri . '&retour.ordre=' . $this->tri_dir
105
					. '&' . $masqueEnParams;
109
					. '&' . $masqueEnParams;
106
		}
110
		}
107
		if (($this->depart + $this->limite) < $total ) {
111
		if (($this->depart + $this->limite) < $total ) {
108
			$donnees['entete']['href.suivant'] = $url_base . '/' . $this->serviceNom . '?'
112
			$donnees['entete']['href.suivant'] = $url_base . '/' . $this->serviceNom . '?'
109
					. 'navigation.depart=' . ($this->depart + $this->limite) . '&navigation.limite=' . $this->limite
113
					. 'navigation.depart=' . ($this->depart + $this->limite) . '&navigation.limite=' . $this->limite
110
					. '&retour.tri=' . $this->tri . '&retour.ordre=' . $this->tri_dir
114
					. '&retour.tri=' . $this->tri . '&retour.ordre=' . $this->tri_dir
111
					. '&' . $masqueEnParams;
115
					. '&' . $masqueEnParams;
112
		}
116
		}
113
		$donnees['resultat'] = $noms;
117
		$donnees['resultat'] = $noms;
114
 
118
 
115
		return $donnees;
119
		return $donnees;
116
	}
120
	}
-
 
121
 
-
 
122
	/**
-
 
123
	 * Renvoie la liste des noms répertoriés par chorodep; si un masque a été
-
 
124
	 * défini sur une zone géographique, retourne aussi la présence sur cette zone
117
 
125
	 */
118
	protected function listeNoms() {
126
	protected function listeNoms() {
-
 
127
		$req = "SELECT DISTINCT num_nom, nom_sci";
-
 
128
		if (isset($this->masque['zone-geo']) && $this->masque['zone-geo'] != null) {
-
 
129
			$req .= ", `" . $this->masque['zone-geo'] . "` as presence";
-
 
130
		}
119
		$req = "SELECT DISTINCT num_nom, nom_sci FROM " . $this->table;
131
		$req .= " FROM " . $this->table;
120
		$req .= $this->construireWhere();
132
		$req .= $this->construireWhere();
121
		$req .= " ORDER BY ".$this->tri." ".$this->tri_dir." ";
133
		$req .= " ORDER BY ".$this->tri." ".$this->tri_dir." ";
122
		$req .= " LIMIT " . $this->depart . ", " . $this->limite;
134
		$req .= " LIMIT " . $this->depart . ", " . $this->limite;
123
 
135
 
124
		$resultat = $this->getBdd()->recupererTous($req);
136
		$resultat = $this->getBdd()->recupererTous($req);
125
 
137
 
126
		return $resultat;
138
		return $resultat;
127
	}
139
	}
128
 
140
 
129
	protected function compterNoms() {
141
	protected function compterNoms() {
130
		$req = "SELECT count(DISTINCT num_nom, nom_sci) AS compte FROM " . $this->table;
142
		$req = "SELECT count(DISTINCT num_nom, nom_sci) AS compte FROM " . $this->table;
131
		$req .= $this->construireWhere();
143
		$req .= $this->construireWhere();
132
		$resultat = $this->getBdd()->recuperer($req);
144
		$resultat = $this->getBdd()->recuperer($req);
133
 
145
 
134
		return $resultat['compte'];
146
		return $resultat['compte'];
135
	}
147
	}
136
 
148
 
137
	protected function construireWhere() {
149
	protected function construireWhere() {
138
		$where = "";
150
		$where = "";
139
		$conditions = array();
151
		$conditions = array();
140
		if(!empty($this->masque)) {
152
		if(!empty($this->masque)) {
141
			if(isset($this->masque['nom'])) {
153
			if(isset($this->masque['nom'])) {
142
				$masqueNom = $this->getBdd()->proteger($this->masque['nom']);
154
				$masqueNom = $this->getBdd()->proteger($this->masque['nom']);
143
				$conditions[] = "nom_sci LIKE $masqueNom";
155
				$conditions[] = "nom_sci LIKE $masqueNom";
144
			}
156
			}
145
			if(isset($this->masque['zone-geo'])) {
157
			if(isset($this->masque['zone-geo'])) {
146
				$masqueZg = $this->getBdd()->proteger($this->masque['zone-geo']);
158
				$masqueZg = $this->masque['zone-geo'];
147
				//$conditions[] = "code_insee = $masqueZg";
159
				$conditions[] = "`$masqueZg` in ('1', '1?')";
148
			}
160
			}
149
			$where = " WHERE ".implode(' AND ', $conditions);
161
			$where = " WHERE ".implode(' AND ', $conditions);
150
		}
162
		}
151
		return $where;
163
		return $where;
152
	}
164
	}
153
}
165
}
154
?>
166
?>