Subversion Repositories eFlore/Applications.del

Rev

Rev 1293 | Rev 1794 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
723 gduche 1
<?php
2
/**
1793 jpm 3
 * Navigation gère les url de navigation en fonction d'un départ et d'une limite
4
 *
5
 * @category DEL
6
 * @package Services
7
 * @subpackage Bibliotheque
8
 * @version 0.1
9
 * @author Mathias CHOUET <mathias@tela-botanica.org>
10
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
12
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
723 gduche 15
*/
16
class Navigation {
1293 jpm 17
 
723 gduche 18
	private $parametres;
19
	private $urlNavigation;
20
	private $total;
1293 jpm 21
 
723 gduche 22
	/**
23
	 * Constructeur de la classe Navigation
24
	 * @param Array $parametres (optionnel) la liste des paramètre issus du Conteneur
25
	 * */
26
	public function __construct($parametres = null) {
27
		$this->parametres = $parametres;
28
	}
1293 jpm 29
 
723 gduche 30
	/**
31
	 * Obtenir la valeur courante de départ
32
	 * */
33
	public function getDepart() {
34
		return isset($this->parametres['navigation.depart']) ? $this->parametres['navigation.depart'] : 0;
35
	}
1293 jpm 36
 
723 gduche 37
	/**
38
	 * Obtenir la limite courante
39
	 * */
40
	public function getLimite() {
1293 jpm 41
		$limite = 10;
42
		if (isset($this->parametres['navigation.limite']) && is_numeric($this->parametres['navigation.limite'])) {
43
			$limite = $this->parametres['navigation.limite'];
44
			$limite = ($limite < 1000) ? $limite : 1000;// Pour éviter les abus !
45
		}
46
		return $limite;
723 gduche 47
	}
1293 jpm 48
 
723 gduche 49
	/**
50
	 * Configurer l'Url de navigation en fonction du fichier de configuration
51
	 * */
52
	public function chargerUrl() {
53
		$this->urlNavigation = new Url(Config::get('url_service'));
54
		$this->urlNavigation->setOption(Url::OPTION_ENCODER_VALEURS, true);
55
	}
1293 jpm 56
 
723 gduche 57
	/**
58
	 * Obtenir l'url en fonction d'un départ et d'une limite donnée
59
	 * @param int $depart l'entier de départ
60
	 * @param int $limite le nombre d'éléments limite
61
	 * */
62
	public function getUrl($depart = null, $limite = null) {
63
		if ($depart == null && $limite == null) {
64
			return $this->urlNavigation;
65
		} else {
66
			return $this->obtenirUrlNavigation($depart, $limite);
67
		}
68
	}
1293 jpm 69
 
723 gduche 70
	/**
71
	* Récupérer l'url de navigation en concaténant d'éventuels paramètres
72
	* @param $depart l'entier de départ de la recherche
73
	* @param $limite le nombre de résultats à retourner
74
	* @param $parametresAdditionnels le tableau contenant les parametres => valeurs additionnels
75
	* */
76
	private function obtenirUrlNavigation($depart, $limite) {
1793 jpm 77
		$parametres = $this->parametres;
78
		$parametres['navigation.depart'] = $depart;
79
		$parametres['navigation.limite'] = $limite;
1293 jpm 80
 
1793 jpm 81
		$this->urlNavigation->setRequete($parametres);
82
		$url = $this->urlNavigation->getURL();
83
		return $url;
723 gduche 84
	}
1293 jpm 85
 
723 gduche 86
	/**
87
	* Récupérer le lien pour afficher les images précédentes en fonction des paramètres
88
	* */
89
	public function recupererHrefPrecedent() {
90
		$departActuel = $this->getDepart();
91
		$limite = $this->getLimite();
92
		$departPrecedent = $departActuel - $limite;
1293 jpm 93
 
723 gduche 94
		$url = null;
1293 jpm 95
 
723 gduche 96
		if ($departActuel > 0) {
97
			$url = $this->getUrl($departPrecedent, $limite);
98
		}
99
		return $url;
100
	}
1293 jpm 101
 
723 gduche 102
	/**
103
	 * Récupérer le lien pour afficher les images suivantes en fonction des paramètres
104
	 * */
105
	public function recupererHrefSuivant() {
106
		$departActuel = $this->getDepart();
107
		$limite = $this->getLimite();
108
		$departSuivant = $departActuel + $limite;
109
		$url = null;
110
		if ($departSuivant < $this->total) {
111
			$url = $this->getUrl($departSuivant, $limite);
112
		}
113
		return $url;
114
	}
1293 jpm 115
 
723 gduche 116
	/**
117
	 * Retourner le nombre total d'éléments
118
	 * */
119
	public function getTotal() {
120
		return $this->total;
121
	}
1293 jpm 122
 
723 gduche 123
	/**
124
	 * Enregistrer le nombre total d'éléments
125
	 * @param int $total le nombre d'éléments
126
	 * */
127
	public function setTotal($total) {
128
		$this->total = $total;
129
	}
1793 jpm 130
}