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