Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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