3 define ('PAG_VAR', 'pag');
4 define ('PAG_COUNT', 3);//
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->total
= $this->tdo
->getCount ();
30 public function addObject (&$object) {
31 if (!($object instanceof tdoAbstract
))
33 $this->tdo
= &$object;
35 if (!empty ($this->order
))
37 if (!empty ($this->start
))
41 protected function getStart () {
42 if ((int)$this->page
<= 0) {
45 // calculate the limit based on $total count of items and the pagination
46 return $this->count
* ($this->page
-1) /*/+ 1/**/;
49 public function getPaginationVariables () {
50 // get the page variables: URL?p=?
51 $this->count
= PAG_COUNT
;
52 $this->page
= tsController
::getRequest (PAG_VAR
);
54 $this->start
= $this->getStart ();
56 // get the ORDER BY variables: URL?o=column_name:(bool)ASC
57 $o = tsController
::getRequest (PAG_ORDER
);
59 $this->order
= explode (':', $o);
62 public function outputOrderHeaders () {
66 public function outputPagination () {
67 $retVal = $left = $right = '';
68 // this should happen after we made all our stuff with the tdo (joins, wheres, orders..bla)
69 // how many stuff we got
70 $t = $this->getTotal();
71 $cnt = ceil ($this->getTotal () / $this->count
);
72 $here = tsController
::getRequest(NAV_VAR
);
74 for ($i=1; $i <= $cnt; $i++
) {
75 $r = tsController
::setRequest($here, array(PAG_VAR
=> $i));
76 if ($i != $this->page
)
77 $retVal .= '<a href="' . tsController
::setRequest($here, array(PAG_VAR
=> $i)) . '">'.$i.'</a> ';
83 $left = '<a href="'.tsController
::setRequest($here, array (PAG_VAR
=> $this->page
-1)).'">«</a> ';
85 if ($this->page
< $cnt)
86 $right = '<a href="'.tsController
::setRequest($here, array (PAG_VAR
=> $this->page+
1)).'">»</a>';;
88 return $left . $retVal . $right;
91 public function addOrder () {
92 if ($this->tdo
instanceof tdoAbstract
&& !empty ($this->order
)) {
93 $fieldName = $this->order
[0];
94 $order = (bool)$this->order
[1]; // if we have no value we treat it as DESC
96 $this->tdo
->addOrder ($fieldName, $order);
100 public function addLimit () {
101 if ($this->tdo
instanceof tdoAbstract
) {
102 // $this->tdo->addLimit ($this->start, $this->count);