-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPaginator.php
75 lines (67 loc) · 2.23 KB
/
Paginator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
*
* @author Wilson Ramiro Champi Tacuri
*/
class ZendR_Paginator extends Zend_Paginator
{
private static $_rowsPerPage = 20;
private static $_numberPages = 5;
public static function factory($data, $page, $rowsPerPage = null, $numberPages = null)
{
if ($rowsPerPage == null){
$rowsPerPage = self::$_rowsPerPage;
}
if ($numberPages == null){
$numberPages = self::$_numberPages;
}
if (is_array($data)) {
$pager = parent::factory($data);
} elseif (is_integer($data)) {
$pager = parent::factory($data);
} else {
switch (get_class($data)) {
case 'Doctrine_Collection':
$pager = parent::factory(
$data,
'DoctrineCollection',
array('ZendR_Paginator_Adapter' => 'ZendR/Paginator/Adapter')
);
break;
case 'Doctrine_Query':
$pager = parent::factory(
$data,
'DoctrineQuery',
array('ZendR_Paginator_Adapter' => 'ZendR/Paginator/Adapter')
);
break;
default:
$pager = parent::factory($data);
break;
}
}
$ykPager = new ZendR_Paginator($pager->getAdapter());
$ykPager->setCurrentPageNumber($page);
$ykPager->setPageRange($numberPages);
$ykPager->setItemCountPerPage($rowsPerPage);
return $ykPager;
}
public function render()
{
$resourceLayout = Zend_Controller_Front::getInstance()
->getParam('bootstrap')
->getResource('layout');
$view = $resourceLayout->getView();
$view->addBasePath(dirname(__FILE__) . '/Paginator');
$view->pager = $this;
return $view->render('pagination-control.phtml');
}
public function __toString()
{
try {
return $this->render();
} catch (Exception $e) {
return $e->getMessage();
}
}
}