1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WhiteOctober\PagerfantaTestBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
6
|
|
|
use Pagerfanta\Pagerfanta; |
7
|
|
|
use Pagerfanta\Adapter\FixedAdapter; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
|
10
|
|
|
class PagerfantaController extends Controller |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
public function defaultViewAction() |
13
|
|
|
{ |
14
|
|
|
return $this->renderPagerfanta('defaultView'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function defaultShortViewAction() |
18
|
|
|
{ |
19
|
|
|
return $this->renderPagerfanta('defaultShortView'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function twitterBootstrapViewAction() |
23
|
|
|
{ |
24
|
|
|
return $this->renderPagerfanta('twitterBootstrapView'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function twitterBootstrap3ViewAction() |
28
|
|
|
{ |
29
|
|
|
return $this->renderPagerfanta('twitterBootstrap3View'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function viewWithOptionsAction() |
33
|
|
|
{ |
34
|
|
|
return $this->renderPagerfanta('viewWithOptions'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function viewWithoutFirstPageParamAction(Request $request) |
38
|
|
|
{ |
39
|
|
|
return $this->defaultWithRequestAction($request, 'viewWithoutFirstPageParam'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function defaultTranslatedViewAction() |
43
|
|
|
{ |
44
|
|
|
return $this->renderPagerfanta('defaultTranslatedView'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function twitterBootstrapTranslatedViewAction() |
48
|
|
|
{ |
49
|
|
|
return $this->renderPagerfanta('twitterBootstrapTranslatedView'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function twitterBootstrap3TranslatedViewAction() |
53
|
|
|
{ |
54
|
|
|
return $this->renderPagerfanta('twitterBootstrap3TranslatedView'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function myView1Action() |
58
|
|
|
{ |
59
|
|
|
return $this->renderPagerfanta('myView1'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function viewWithRouteParamsAction($test = null) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
return $this->renderPagerfanta('viewWithRouteParams'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function defaultWithRequestAction(Request $request, $name = 'defaultView') |
68
|
|
|
{ |
69
|
|
|
$template = $this->buildTemplateName($name); |
70
|
|
|
$pagerfanta = $this->createPagerfanta(); |
71
|
|
|
$pagerfanta->setMaxPerPage($request->query->get('maxPerPage', 10)); |
72
|
|
|
$pagerfanta->setCurrentPage($request->query->get('currentPage', 1)); |
73
|
|
|
|
74
|
|
|
return $this->render($template, array( |
75
|
|
|
'pagerfanta' => $pagerfanta, |
76
|
|
|
)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function renderPagerfanta($name) |
80
|
|
|
{ |
81
|
|
|
$template = $this->buildTemplateName($name); |
82
|
|
|
$pagerfanta = $this->createPagerfanta(); |
83
|
|
|
|
84
|
|
|
return $this->render($template, array( |
85
|
|
|
'pagerfanta' => $pagerfanta |
86
|
|
|
)); |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private function buildTemplateName($name) |
91
|
|
|
{ |
92
|
|
|
return sprintf('WhiteOctoberPagerfantaTestBundle:Pagerfanta:%s.html.twig', $name); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
private function createPagerfanta() |
96
|
|
|
{ |
97
|
|
|
$adapter = $this->createAdapter(); |
98
|
|
|
|
99
|
|
|
return new Pagerfanta($adapter); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function createAdapter() |
103
|
|
|
{ |
104
|
|
|
$nbResults = 100; |
105
|
|
|
$results = range(1, $nbResults); |
106
|
|
|
|
107
|
|
|
return new FixedAdapter($nbResults, $results); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.