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