3 define ('PAG_VAR', 'pag');
4 define ('PAG_COUNT', 4);//
5 define ('PAG_ORDER', 'o');
7 * @desc Decorator class for tdoAbstract
11 public $start, $count, $page, $order;
17 public function __construct () {
18 $this->getPaginationVariables ();
20 public function __destruct () {}
22 public function getTotal () {
23 // getting the number of elements
24 if (empty ($this->total
)) {
25 // $this->tdo->limit = null;
26 // $this->total = $this->tdo->getCount ();
27 // $this->tdo->reset ();
33 public function addObject (&$object) {
34 if (!($object instanceof tdoAbstract
))
36 // add the pagination shit
37 $this->tdo
= &$object;
40 protected function getStart ($pageNo) {
41 if ((int)$pageNo <= 0)
43 // calculate the limit based on $total count of items and the pagination
44 return $this->count
* ($pageNo-1) +
1;
47 public function getPaginationVariables () {
48 // get the page variables: URL?p=?
49 $this->count
= PAG_COUNT
;
50 $this->page
= tsController
::getRequest (PAG_VAR
);
51 $this->start
= $this->getStart ($this->page
);
53 // get the ORDER BY variables: URL?o=column_name:(bool)ASC
54 $this->order
= explode (':', tsController
::getRequest (PAG_ORDER
));
56 public function outputOrderHeaders () {
60 public function outputPagination () {
61 $retVal = $left = $right = '';
62 // how many stuff we got
63 $t = $this->getTotal();
64 $cnt = floor ($this->getTotal() / $this->count
);
65 $here = tsController
::getRequest(NAV_VAR
);
67 if (!empty ($this->order
))
69 if (!empty ($this->limit
))
72 for ($i=1; $i <= $cnt; $i++
) {
73 $r = tsController
::setRequest($here, array(PAG_VAR
=> $i));
74 if ($i != $this->page
)
75 $retVal .= '<a href="'.tsController
::setRequest($here, array(PAG_VAR
=> $i)).'">'.$i.'</a> ';
81 $left = '<a href="'.tsController
::setRequest($here, array(PAG_VAR
=>$this->page
-1)).'">«</a> ';
83 if ($this->page
< $cnt)
84 $right = '<a href="'.tsController
::setRequest($here, array(PAG_VAR
=>$this->page+
1)).'">»</a>';;
86 return $left . $retVal . $right;
89 public function addOrder () {
90 $fieldName = $this->order
[0];
91 $order = (bool)@$this->order
[1]; // if we have no value we treat it as DESC
93 if ($this->tdo
instanceof tdoAbstract
&& !empty ($this->order
)) {
94 // var_dump ($fieldName, $order, $this->tdo);die;
95 $this->tdo
->addOrder ($fieldName, $order);
99 public function addLimit () {
100 if ($this->tdo
instanceof tdoAbstract
&& !empty ($this->start
)) {
101 $this->tdo
->addLimit ($this->start
, $this->count
);