Completed
Push — master ( 1c775c...37f823 )
by Peter
05:37
created

Configuration::setFirstPageLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * AnimeDb package
4
 *
5
 * @package   AnimeDb
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
9
 */
10
namespace AnimeDb\Bundle\AppBundle\Util\Pagination;
11
12
/**
13
 * Pagination configuration
14
 *
15
 * @package AnimeDb\Bundle\AppBundle\Util\Pagination
16
 * @author Peter Gribanov <[email protected]>
17
 */
18
class Configuration
19
{
20
    /**
21
     * Length of the list of pagination defaults
22
     *
23
     * @var int
24
     */
25
    const DEFAULT_LIST_LENGTH = 5;
26
27
    /**
28
     * @var int
29
     */
30
    const DEFAULT_PAGE_LINK = '%s';
31
32
    /**
33
     * @var int
34
     */
35
    protected $total_pages = 0;
36
37
    /**
38
     * @var int
39
     */
40
    protected $current_page = 1;
41
42
    /**
43
     * @var View
44
     */
45
    protected $view;
46
47
    /**
48
     * The number of pages displayed in the navigation
49
     *
50
     * @var int
51
     */
52
    protected $max_navigate = self::DEFAULT_LIST_LENGTH;
53
54
    /**
55
     * @var string|callback
56
     */
57
    protected $page_link = self::DEFAULT_PAGE_LINK;
58
59
    /**
60
     * @var string
61
     */
62
    protected $first_page_link = '';
63
64
    /**
65
     * @param int $total_pages
66
     * @param int $current_page
67
     */
68 39
    public function __construct($total_pages = 0, $current_page = 1)
69
    {
70 39
        $this->current_page = $current_page;
71 39
        $this->total_pages = $total_pages;
72 39
    }
73
74
    /**
75
     * @param int $total_pages
76
     * @param int $current_page
77
     *
78
     * @return Configuration
79
     */
80 2
    public static function create($total_pages = 0, $current_page = 1)
81
    {
82 2
        return new static($total_pages, $current_page);
83
    }
84
85
    /**
86
     * @return int
87
     */
88 7
    public function getTotalPages()
89
    {
90 7
        return $this->total_pages;
91
    }
92
93
    /**
94
     * @param int $total_pages
95
     *
96
     * @return Configuration
97
     */
98 1
    public function setTotalPages($total_pages)
99
    {
100 1
        $this->total_pages = $total_pages;
101 1
        return $this;
102
    }
103
104
    /**
105
     * @return int
106
     */
107 7
    public function getCurrentPage()
108
    {
109 7
        return $this->current_page;
110
    }
111
112
    /**
113
     * @param int $current_page
114
     *
115
     * @return Configuration
116
     */
117 1
    public function setCurrentPage($current_page)
118
    {
119 1
        $this->current_page = $current_page;
120 1
        return $this;
121
    }
122
123
    /**
124
     * @return int
125
     */
126 3
    public function getMaxNavigate()
127
    {
128 3
        return $this->max_navigate;
129
    }
130
131
    /**
132
     * @param int $max_navigate
133
     *
134
     * @return Configuration
135
     */
136 3
    public function setMaxNavigate($max_navigate)
137
    {
138 3
        $this->max_navigate = $max_navigate;
139 3
        return $this;
140
    }
141
142
    /**
143
     * @return string|callback
144
     */
145 2
    public function getPageLink()
146
    {
147 2
        return $this->page_link;
148
    }
149
150
    /**
151
     * Set page link
152
     *
153
     * Basic reference, for example `page_%s.html` where %s page number, or
154
     * callback function which takes one parameter - the number of the page.
155
     *
156
     * <code>
157
     * function ($number) {
158
     *     return 'page_'.$number.'.html';
159
     * }
160
     * </code>
161
     *
162
     * @param string|callback $page_link
163
     *
164
     * @return Configuration
165
     */
166 3
    public function setPageLink($page_link)
167
    {
168 3
        $this->page_link = $page_link;
169 3
        return $this;
170
    }
171
172
    /**
173
     * @return string
174
     */
175
    public function getFirstPageLink()
176
    {
177
        return $this->first_page_link;
178
    }
179
180
    /**
181
     * @param string $first_page_link
182
     *
183
     * @return Configuration
184
     */
185
    public function setFirstPageLink($first_page_link)
186
    {
187
        $this->first_page_link = $first_page_link;
188
        return $this;
189
    }
190
191
    /**
192
     * @return View
193
     */
194 1
    public function getView()
195
    {
196 1
        if (!$this->view) {
197 1
            $this->view = new View($this);
198 1
        }
199 1
        return $this->view;
200
    }
201
}
202