7 |
jpm |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class Fragmenteur {
|
|
|
4 |
const PAGER_MODE = 'Sliding';
|
|
|
5 |
const PAGE_DELTA = 2;
|
131 |
jpm |
6 |
const PAGE_SEPARATEUR = '<span class="frag_separateur">-</span>';
|
7 |
jpm |
7 |
const SQUELETTE = 'defaut';
|
|
|
8 |
const DONNEES_PAR_PAGE_CHOIX = '10,20,50,100';
|
|
|
9 |
const DONNEES_PAR_PAGE_DEFAUT = 10;
|
8 |
jpm |
10 |
const ALPHABET_AFFICHAGE_DEFAUT = false;
|
|
|
11 |
const ALPHABET_LETTRE_DEFAUT = 'A';
|
131 |
jpm |
12 |
const CSS_CLASS_PAGE_COURRANTE = 'frag_page_courrante frag_boite';
|
|
|
13 |
const PAGE_SEPARATEUR_ESPACE = 0;
|
7 |
jpm |
14 |
|
|
|
15 |
private $pager_mode;
|
|
|
16 |
private $pager;
|
|
|
17 |
private $url;
|
143 |
jpm |
18 |
private $parametres_url = null;
|
7 |
jpm |
19 |
private $lettre;
|
|
|
20 |
private $page_delta;
|
|
|
21 |
private $page_separateur;
|
|
|
22 |
private $donnees_total;
|
|
|
23 |
private $donnees_par_page;
|
43 |
jpm |
24 |
private $donnees_par_page_choix;
|
7 |
jpm |
25 |
private $url_var;
|
|
|
26 |
private $squelette;
|
|
|
27 |
private $chemin_squelette;
|
8 |
jpm |
28 |
private $squelette_donnees = array();
|
7 |
jpm |
29 |
|
|
|
30 |
public function __construct($options) {
|
|
|
31 |
// Gestion de l'url
|
|
|
32 |
if (isset($options['url'])) {
|
|
|
33 |
if ($options['url'] instanceof Url) {
|
|
|
34 |
$this->url = $options['url'];
|
143 |
jpm |
35 |
$this->parametres_url = $this->url->getVariablesRequete();
|
7 |
jpm |
36 |
} else {
|
|
|
37 |
$msg = "Fragmenteur nécessite nécessite un objet Url du Framework de Tela Botanica pour fonctionner.";
|
|
|
38 |
trigger_error($msg, E_USER_ERROR);
|
|
|
39 |
}
|
|
|
40 |
} else {
|
43 |
jpm |
41 |
$msg = "Fragmenteur nécessite de renseigner dans le tableau d'options l'url pour la clé 'url'".
|
7 |
jpm |
42 |
trigger_error($msg, E_USER_ERROR);
|
|
|
43 |
}
|
|
|
44 |
|
8 |
jpm |
45 |
// Gestion de la liste alphabétique
|
|
|
46 |
$this->alphabet_affichage = (isset($options['alphabet_affichage']) ? $options['alphabet_affichage'] : self::ALPHABET_AFFICHAGE_DEFAUT);
|
|
|
47 |
if ($this->alphabet_affichage == true) {
|
|
|
48 |
$lettre = (isset($options['lettre']) ? $options['lettre'] : self::ALPHABET_LETTRE_DEFAUT);
|
|
|
49 |
$this->setLettre($lettre);
|
|
|
50 |
if (isset($_GET['lettre'])) {
|
|
|
51 |
$this->setLettre(urldecode($_GET['lettre']));
|
|
|
52 |
}
|
7 |
jpm |
53 |
}
|
8 |
jpm |
54 |
|
7 |
jpm |
55 |
// Gestion des infos pour le pager
|
|
|
56 |
$this->squelette = (isset($options['squelette']) ? $options['squelette'] : self::SQUELETTE).'.tpl.html';
|
|
|
57 |
$this->chemin_squelette = dirname(__FILE__).DS.'squelettes'.DS.$this->squelette;
|
|
|
58 |
$this->pager_mode = (isset($options['pager_mode']) ? $options['pager_mode'] : self::PAGER_MODE);
|
|
|
59 |
$this->page_delta = (isset($options['page_delta']) ? $options['page_delta'] : self::PAGE_DELTA);
|
|
|
60 |
$this->page_separateur = (isset($options['page_separateur']) ? $options['page_separateur'] : self::PAGE_SEPARATEUR);
|
272 |
mathias |
61 |
$this->url_var = (isset($options['url_var']) ? $options['url_var'] : Config::get('parametre_url_page'));
|
7 |
jpm |
62 |
$this->donnees_par_page = (isset($options['donnees_par_page']) ? $options['donnees_par_page'] : self::DONNEES_PAR_PAGE_DEFAUT);
|
43 |
jpm |
63 |
$this->donnees_par_page_choix = (isset($options['donnees_par_page_choix']) ? $options['donnees_par_page_choix'] : self::DONNEES_PAR_PAGE_CHOIX);
|
7 |
jpm |
64 |
$this->donnees_total = (isset($options['donnees_total']) ? $options['donnees_total'] : 0);
|
|
|
65 |
|
|
|
66 |
// Gestion du nombre de données à afficher par page.
|
|
|
67 |
if (isset($_GET['frag_nbre'])) {
|
|
|
68 |
if ($_GET['frag_nbre'] == '*') {
|
272 |
mathias |
69 |
$_GET[$this->url_var] = 1;
|
7 |
jpm |
70 |
}
|
|
|
71 |
$_SESSION['fragmenteur']['donnees_par_page'] = $_GET['frag_nbre'];
|
|
|
72 |
} else {
|
|
|
73 |
$_SESSION['fragmenteur']['donnees_par_page'] = $this->donnees_par_page;
|
|
|
74 |
}
|
|
|
75 |
$this->donnees_par_page = $_SESSION['fragmenteur']['donnees_par_page'];
|
|
|
76 |
if ($this->donnees_par_page == '*') {
|
|
|
77 |
$this->donnees_par_page = $this->donnees_total;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
// Gestion du Fragmenteur (basé sur le Pager de Pear)
|
|
|
81 |
$pager_options = array( 'mode' => $this->pager_mode,
|
131 |
jpm |
82 |
'perPage' => $this->donnees_par_page,
|
|
|
83 |
'delta' => $this->page_delta,
|
|
|
84 |
'totalItems' => $this->donnees_total,
|
272 |
mathias |
85 |
'path' => Config::get('url_base'),
|
131 |
jpm |
86 |
'urlVar' => $this->url_var,
|
|
|
87 |
'separator' => $this->page_separateur,
|
|
|
88 |
'curPageLinkClassName' => self::CSS_CLASS_PAGE_COURRANTE,
|
|
|
89 |
'spacesBeforeSeparator' => self::PAGE_SEPARATEUR_ESPACE,
|
|
|
90 |
'spacesAfterSeparator' => self::PAGE_SEPARATEUR_ESPACE,
|
|
|
91 |
);
|
7 |
jpm |
92 |
$this->pager = Pager::factory($pager_options);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public function getDonneesParPage() {
|
|
|
96 |
return $this->donnees_par_page;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
public function getDeplacementParPageId() {
|
|
|
100 |
return $this->pager->getOffsetByPageId();
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
public function getLettre() {
|
|
|
104 |
return $this->lettre;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public function setLettre($l) {
|
|
|
108 |
$this->lettre = $l;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
public function getDonneesTotal() {
|
|
|
112 |
return $this->donnees_total;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public function setDonneesTotal($dt) {
|
|
|
116 |
$this->donnees_total = $dt;
|
|
|
117 |
}
|
8 |
jpm |
118 |
|
|
|
119 |
private function getSqueletteDonnees() {
|
|
|
120 |
return $this->squelette_donnees;
|
|
|
121 |
}
|
7 |
jpm |
122 |
|
8 |
jpm |
123 |
private function setSqueletteDonnees($cle, $valeur) {
|
|
|
124 |
$this->squelette_donnees[$cle] = $valeur;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
|
7 |
jpm |
128 |
public function executer() {
|
|
|
129 |
// Gestion de la liste alphabétique
|
8 |
jpm |
130 |
if ($this->alphabet_affichage == true) {
|
|
|
131 |
$alphabet = array();
|
|
|
132 |
$this->url->setVariableRequete('lettre', '*');
|
143 |
jpm |
133 |
$alphabet['*'] = array('url' => $this->url->getURL(),
|
|
|
134 |
'lettre' => 'tous');
|
7 |
jpm |
135 |
$this->url->unsetVariableRequete('lettre');
|
8 |
jpm |
136 |
for ($i = 65; $i <= 90; $i++){
|
|
|
137 |
$this->url->setVariableRequete('lettre', chr($i));
|
|
|
138 |
$alphabet[chr($i)] = array('url' => $this->url->getURL(),
|
143 |
jpm |
139 |
'lettre' => chr($i));
|
8 |
jpm |
140 |
$this->url->unsetVariableRequete('lettre');
|
|
|
141 |
}
|
|
|
142 |
$this->setSqueletteDonnees('alphabet', $alphabet);
|
|
|
143 |
|
|
|
144 |
// Gestion de la lettre
|
|
|
145 |
$this->setSqueletteDonnees('lettre_selected', $this->getLettre());
|
|
|
146 |
|
|
|
147 |
// Gestion de l'url
|
|
|
148 |
$this->url->setVariableRequete('lettre', $this->getLettre());
|
|
|
149 |
}
|
|
|
150 |
|
7 |
jpm |
151 |
// Gestion des urls
|
272 |
mathias |
152 |
$this->url->setVariableRequete($this->url_var, $this->pager->getCurrentPageID());
|
8 |
jpm |
153 |
$this->setSqueletteDonnees('url', $this->url->getURL());
|
7 |
jpm |
154 |
|
|
|
155 |
// Gestion du fragmenteur
|
8 |
jpm |
156 |
$this->setSqueletteDonnees('frag_donnee_total', $this->donnees_total);
|
7 |
jpm |
157 |
$page_id_x_saut = ($this->pager->getCurrentPageID() * $this->donnees_par_page);
|
8 |
jpm |
158 |
$this->setSqueletteDonnees('frag_donnee_debut', (($page_id_x_saut - $this->donnees_par_page) > 0 ? ($page_id_x_saut - $this->donnees_par_page) : 0));
|
|
|
159 |
$this->setSqueletteDonnees('frag_donnee_fin', ($page_id_x_saut >= $this->donnees_total ? $this->donnees_total : $page_id_x_saut));
|
43 |
jpm |
160 |
$this->setSqueletteDonnees('par_page', explode(',', $this->donnees_par_page_choix));
|
8 |
jpm |
161 |
$this->setSqueletteDonnees('par_page_selected', $_SESSION['fragmenteur']['donnees_par_page']);
|
|
|
162 |
$this->setSqueletteDonnees('pager_links', $this->pager->getLinks());
|
7 |
jpm |
163 |
|
|
|
164 |
// Gestion des paramêtres pour le formulaire du Fragmenteur
|
8 |
jpm |
165 |
$form_get_url_chp_hidden = array();
|
143 |
jpm |
166 |
foreach ($this->parametres_url as $cle => $valeur) {
|
8 |
jpm |
167 |
$form_get_url_chp_hidden[$cle] = $valeur;
|
7 |
jpm |
168 |
}
|
8 |
jpm |
169 |
$this->setSqueletteDonnees('form_get_url_chp_hidden', $form_get_url_chp_hidden);
|
7 |
jpm |
170 |
|
8 |
jpm |
171 |
// Création du rendu à partir du squelette et de ses données
|
|
|
172 |
$sortie = SquelettePhp::analyser($this->chemin_squelette, $this->getSqueletteDonnees());
|
7 |
jpm |
173 |
return $sortie;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
}
|
|
|
177 |
?>
|