/
paginationAction.php
59 lines (48 loc) · 1.72 KB
/
paginationAction.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
protected function getPager()
{
$pager = $this->configuration->getPager('<?php echo $this->getModelClass() ?>');
$pager->setQuery($this->buildQuery());
$pager->setPage($this->getPage());
$pager->setMaxPerPage($this->getMaxPerPage());
$pager->init();
return $pager;
}
protected function setPage($page)
{
$this->getUser()->setAttribute('<?php echo $this->getModuleName() ?>.page', $page, 'admin_module');
}
protected function getPage()
{
return $this->getUser()->getAttribute('<?php echo $this->getModuleName() ?>.page', 1, 'admin_module');
}
protected function setMaxPerPage($page)
{
$this->getUser()->setAttribute('<?php echo $this->getModuleName() ?>.per_page', $page, 'admin_module');
}
protected function getMaxPerPage()
{
return $this->getUser()->getAttribute('<?php echo $this->getModuleName() ?>.per_page', 1, 'admin_module');
}
protected function buildQuery()
{
$tableMethod = $this->configuration->getTableMethod();
<?php if ($this->configuration->hasFilterForm()): ?>
if (null === $this->filters)
{
$this->filters = $this->configuration->getFilterForm($this->getFilters());
}
$this->filters->setTableMethod($tableMethod);
$query = $this->filters->buildQuery($this->getFilters());
<?php else: ?>
$query = Doctrine_Core::getTable('<?php echo $this->getModelClass() ?>')
->createQuery('a');
if ($tableMethod)
{
$query = Doctrine_Core::getTable('<?php echo $this->getModelClass() ?>')->$tableMethod($query);
}
<?php endif; ?>
$this->addSortQuery($query);
$event = $this->dispatcher->filter(new sfEvent($this, 'admin.build_query'), $query);
$query = $event->getReturnValue();
return $query;
}