Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
dac63a50
Commit
dac63a50
authored
Jul 25, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored the paginator class for cleanliness.
parent
8d2eefe1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
38 deletions
+24
-38
paginator.php
system/paginator.php
+24
-38
No files found.
system/paginator.php
View file @
dac63a50
...
@@ -30,13 +30,6 @@ class Paginator {
...
@@ -30,13 +30,6 @@ class Paginator {
*/
*/
public
$per_page
;
public
$per_page
;
/**
* The last page number.
*
* @var int
*/
public
$last_page
;
/**
/**
* The language that should be used when generating page links.
* The language that should be used when generating page links.
*
*
...
@@ -44,13 +37,6 @@ class Paginator {
...
@@ -44,13 +37,6 @@ class Paginator {
*/
*/
public
$language
;
public
$language
;
/**
* Indicates if HTTPS links should be generated.
*
* @var bool
*/
public
$https
=
false
;
/**
/**
* Create a new Paginator instance.
* Create a new Paginator instance.
*
*
...
@@ -62,7 +48,6 @@ class Paginator {
...
@@ -62,7 +48,6 @@ class Paginator {
public
function
__construct
(
$results
,
$total
,
$per_page
)
public
function
__construct
(
$results
,
$total
,
$per_page
)
{
{
$this
->
page
=
static
::
page
(
$total
,
$per_page
);
$this
->
page
=
static
::
page
(
$total
,
$per_page
);
$this
->
last_page
=
ceil
(
$total
/
$per_page
);
$this
->
per_page
=
$per_page
;
$this
->
per_page
=
$per_page
;
$this
->
results
=
$results
;
$this
->
results
=
$results
;
$this
->
total
=
$total
;
$this
->
total
=
$total
;
...
@@ -86,7 +71,7 @@ class Paginator {
...
@@ -86,7 +71,7 @@ class Paginator {
return
$last_page
;
return
$last_page
;
}
}
return
(
filter_var
(
$page
,
FILTER_VALIDATE_INT
)
===
false
or
$page
<
1
)
?
1
:
$page
;
return
(
$page
<
1
or
filter_var
(
$page
,
FILTER_VALIDATE_INT
)
===
false
)
?
1
:
$page
;
}
}
/**
/**
...
@@ -97,7 +82,7 @@ class Paginator {
...
@@ -97,7 +82,7 @@ class Paginator {
*/
*/
public
function
links
(
$adjacent
=
3
)
public
function
links
(
$adjacent
=
3
)
{
{
return
(
$this
->
last_page
>
1
)
?
'<div class="pagination">'
.
$this
->
previous
()
.
$this
->
numbers
(
$adjacent
)
.
$this
->
next
()
.
'</div>'
:
''
;
return
(
$this
->
last_page
()
>
1
)
?
'<div class="pagination">'
.
$this
->
previous
()
.
$this
->
numbers
(
$adjacent
)
.
$this
->
next
()
.
'</div>'
:
''
;
}
}
/**
/**
...
@@ -110,7 +95,7 @@ class Paginator {
...
@@ -110,7 +95,7 @@ class Paginator {
*/
*/
private
function
numbers
(
$adjacent
=
3
)
private
function
numbers
(
$adjacent
=
3
)
{
{
return
(
$this
->
last_page
<
7
+
(
$adjacent
*
2
))
?
$this
->
range
(
1
,
$this
->
last_page
)
:
$this
->
slider
(
$adjacent
);
return
(
$this
->
last_page
()
<
7
+
(
$adjacent
*
2
))
?
$this
->
range
(
1
,
$this
->
last_page
()
)
:
$this
->
slider
(
$adjacent
);
}
}
/**
/**
...
@@ -125,13 +110,15 @@ class Paginator {
...
@@ -125,13 +110,15 @@ class Paginator {
{
{
return
$this
->
range
(
1
,
2
+
(
$adjacent
*
2
))
.
$this
->
ending
();
return
$this
->
range
(
1
,
2
+
(
$adjacent
*
2
))
.
$this
->
ending
();
}
}
elseif
(
$this
->
page
>=
$this
->
last_page
-
(
$adjacent
*
2
))
elseif
(
$this
->
page
>=
$this
->
last_page
()
-
(
$adjacent
*
2
))
{
{
return
$this
->
beginning
()
.
$this
->
range
(
$this
->
last_page
-
2
-
(
$adjacent
*
2
),
$this
->
last_page
);
return
$this
->
beginning
()
.
$this
->
range
(
$this
->
last_page
()
-
2
-
(
$adjacent
*
2
),
$this
->
last_page
()
);
}
}
else
{
return
$this
->
beginning
()
.
$this
->
range
(
$this
->
page
-
$adjacent
,
$this
->
page
+
$adjacent
)
.
$this
->
ending
();
return
$this
->
beginning
()
.
$this
->
range
(
$this
->
page
-
$adjacent
,
$this
->
page
+
$adjacent
)
.
$this
->
ending
();
}
}
}
/**
/**
* Generate the "previous" HTML link.
* Generate the "previous" HTML link.
...
@@ -140,7 +127,7 @@ class Paginator {
...
@@ -140,7 +127,7 @@ class Paginator {
*/
*/
public
function
previous
()
public
function
previous
()
{
{
$text
=
Lang
::
line
(
'pagination.previous'
)
->
get
(
$this
->
language
);
$text
=
Lang
::
line
(
'pagination.previous'
)
->
get
();
return
(
$this
->
page
>
1
)
?
$this
->
link
(
$this
->
page
-
1
,
$text
,
'prev_page'
)
.
' '
:
HTML
::
span
(
$text
,
array
(
'class'
=>
'disabled prev_page'
))
.
' '
;
return
(
$this
->
page
>
1
)
?
$this
->
link
(
$this
->
page
-
1
,
$text
,
'prev_page'
)
.
' '
:
HTML
::
span
(
$text
,
array
(
'class'
=>
'disabled prev_page'
))
.
' '
;
}
}
...
@@ -152,9 +139,9 @@ class Paginator {
...
@@ -152,9 +139,9 @@ class Paginator {
*/
*/
public
function
next
()
public
function
next
()
{
{
$text
=
Lang
::
line
(
'pagination.next'
)
->
get
(
$this
->
language
);
$text
=
Lang
::
line
(
'pagination.next'
)
->
get
();
return
(
$this
->
page
<
$this
->
last_page
)
?
$this
->
link
(
$this
->
page
+
1
,
$text
,
'next_page'
)
:
HTML
::
span
(
$text
,
array
(
'class'
=>
'disabled next_page'
))
.
' '
;
return
(
$this
->
page
<
$this
->
last_page
())
?
$this
->
link
(
$this
->
page
+
1
,
$text
,
'next_page'
)
:
HTML
::
span
(
$text
,
array
(
'class'
=>
'disabled next_page'
))
;
}
}
/**
/**
...
@@ -174,7 +161,7 @@ class Paginator {
...
@@ -174,7 +161,7 @@ class Paginator {
*/
*/
private
function
ending
()
private
function
ending
()
{
{
return
$this
->
dots
()
.
$this
->
range
(
$this
->
last_page
-
1
,
$this
->
last_page
);
return
$this
->
dots
()
.
$this
->
range
(
$this
->
last_page
()
-
1
,
$this
->
last_page
()
);
}
}
/**
/**
...
@@ -187,7 +174,7 @@ class Paginator {
...
@@ -187,7 +174,7 @@ class Paginator {
*/
*/
private
function
link
(
$page
,
$text
,
$class
)
private
function
link
(
$page
,
$text
,
$class
)
{
{
return
HTML
::
link
(
Request
::
uri
()
.
'?page='
.
$page
,
$text
,
array
(
'class'
=>
$class
),
$this
->
https
);
return
HTML
::
link
(
Request
::
uri
()
.
'?page='
.
$page
,
$text
,
array
(
'class'
=>
$class
),
Request
::
is_secure
()
);
}
}
/**
/**
...
@@ -222,25 +209,24 @@ class Paginator {
...
@@ -222,25 +209,24 @@ class Paginator {
}
}
/**
/**
*
Set the language that should be used when generating pagination links
.
*
Determine the last page number based on the total pages and per page limit
.
*
*
* @param string $language
* @return int
* @return Paginator
*/
*/
p
ublic
function
lang
(
$language
)
p
rivate
function
last_page
(
)
{
{
$this
->
language
=
$language
;
return
ceil
(
$this
->
total
/
$this
->
per_page
);
return
$this
;
}
}
/**
/**
*
Force the pagination links to use HTTPS
.
*
Set the language that should be used when generating page links
.
*
*
* @param string $language
* @return Paginator
* @return Paginator
*/
*/
public
function
secure
(
)
public
function
lang
(
$language
)
{
{
$this
->
https
=
tru
e
;
$this
->
language
=
$languag
e
;
return
$this
;
return
$this
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment