3 define ('PAG_VAR', 'pag');
4 define ('PAG_COUNT', 3);//
5 define ('PAG_ORDER', 'o');
7 * @desc Decorator class for tdoAbstract
11 private $start, $count, $total, $page, $order;
17 public function __construct () {
18 $this->getPaginationVariables ();
20 public function __destruct () {}
22 public function setCount ($int) {
24 $this->start
= $this->getStart();
27 public function outputOrderHeaders () {
31 public function outputPagination () {
32 $retVal = $left = $right = '';
33 // this should happen after we made all our stuff with the tdo (joins, wheres, orders..bla)
34 // how many stuff we got
35 $t = $this->getTotal();
36 $cnt = ceil ($this->getTotal () / $this->count
);
37 $here = tsController
::getRequest(NAV_VAR
);
39 for ($i=1; $i <= $cnt; $i++
) {
40 $r = tsController
::setRequest($here, array(PAG_VAR
=> $i));
41 if ($i != $this->page
)
42 $retVal .= '<a href="' . tsController
::setRequest($here, array(PAG_VAR
=> $i)) . '">'.$i.'</a> ';
48 $left = '<a href="'.tsController
::setRequest($here, array (PAG_VAR
=> $this->page
-1)).'">«</a> ';
50 if ($this->page
< $cnt)
51 $right = '<a href="'.tsController
::setRequest($here, array (PAG_VAR
=> $this->page+
1)).'">»</a>';;
53 return $left . $retVal . $right;
56 public function addObject (&$object) {
57 if (!($object instanceof tdoAbstract
))
59 $this->tdo
= &$object;
61 if (!empty ($this->order
))
63 // if (!empty ($this->start))
67 protected function getTotal () {
68 // getting the number of elements
69 if (empty ($this->total
) && ($this->tdo
instanceof tdoAbstract
)) {
70 $this->total
= (int)$this->tdo
->getCount ();
72 return (int)$this->total
;
75 protected function getStart () {
76 if ((int)$this->page
<= 0 /*/||
77 (int)$this->start > $this->getTotal()/**/
82 // calculate the limit based on $total count of items and the pagination
83 return $this->count
* ($this->page
-1) /*/+ 1/**/;//$this->start;
86 protected function getPaginationVariables () {
87 // get the page variables: URL?p=?
88 if (empty($this->count
))
89 $this->count
= PAG_COUNT
;
91 $this->page
= (int)tsController
::getRequest (PAG_VAR
);
93 $this->start
= $this->getStart ();
95 // get the ORDER BY variables: URL?o=column_name:(bool)ASC
96 $o = tsController
::getRequest (PAG_ORDER
);
99 $this->order
= explode (':', $o);
103 protected function addOrder () {
104 // this is dumb as it requires a column name to comre from user input
105 if ($this->tdo
instanceof tdoAbstract
&& !empty ($this->order
)) {
106 $fieldName = $this->order
[0];
107 $order = (bool)$this->order
[1]; // if we have no value we treat it as DESC
109 // $this->tdo->addOrder ($fieldName, $order);
113 protected function addLimit () {
114 // var_dump($this->start, $this->count);
115 if ($this->tdo
instanceof tdoAbstract
) {
116 $this->tdo
->addLimit ($this->start
, $this->count
);