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