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