Completed
Push — master ( 27ccf0...ab918a )
by Pablo
7s
created

PagerfantaController::defaultViewAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 twitterBootstrapViewAction()
18
    {
19
        return $this->renderPagerfanta('twitterBootstrapView');
20
    }
21
22
    public function twitterBootstrap3ViewAction()
23
    {
24
        return $this->renderPagerfanta('twitterBootstrap3View');
25
    }
26
27
    public function viewWithOptionsAction()
28
    {
29
        return $this->renderPagerfanta('viewWithOptions');
30
    }
31
32
    public function viewWithoutFirstPageParamAction(Request $request)
33
    {
34
        return $this->defaultWithRequestAction($request, 'viewWithoutFirstPageParam');
35
    }
36
37
    public function defaultTranslatedViewAction()
38
    {
39
        return $this->renderPagerfanta('defaultTranslatedView');
40
    }
41
42
    public function twitterBootstrapTranslatedViewAction()
43
    {
44
        return $this->renderPagerfanta('twitterBootstrapTranslatedView');
45
    }
46
47
    public function twitterBootstrap3TranslatedViewAction()
48
    {
49
        return $this->renderPagerfanta('twitterBootstrap3TranslatedView');
50
    }
51
52
    public function myView1Action()
53
    {
54
        return $this->renderPagerfanta('myView1');
55
    }
56
57
    public function viewWithRouteParamsAction($test = null)
0 ignored issues
show
Unused Code introduced by
The parameter $test is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        return $this->renderPagerfanta('viewWithRouteParams');
60
    }
61
62
    public function defaultWithRequestAction(Request $request, $name = 'defaultView')
63
    {
64
        $template = $this->buildTemplateName($name);
65
        $pagerfanta = $this->createPagerfanta();
66
        $pagerfanta->setMaxPerPage($request->query->get('maxPerPage', 10));
67
        $pagerfanta->setCurrentPage($request->query->get('currentPage', 1));
68
69
        return $this->render($template, array(
70
            'pagerfanta' => $pagerfanta,
71
        ));
72
    }
73
74
    private function renderPagerfanta($name)
75
    {
76
        $template = $this->buildTemplateName($name);
77
        $pagerfanta = $this->createPagerfanta();
78
79
        return $this->render($template, array(
80
            'pagerfanta' => $pagerfanta
81
        ));
82
83
    }
84
85
    private function buildTemplateName($name)
86
    {
87
        return sprintf('WhiteOctoberPagerfantaTestBundle:Pagerfanta:%s.html.twig', $name);
88
    }
89
90
    private function createPagerfanta()
91
    {
92
        $adapter = $this->createAdapter();
93
94
        return new Pagerfanta($adapter);
95
    }
96
97
    private function createAdapter()
98
    {
99
        $nbResults = 100;
100
        $results = range(1, $nbResults);
101
102
        return new FixedAdapter($nbResults, $results);
103
    }
104
}
105