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