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
f7eeb85e
Commit
f7eeb85e
authored
Jul 21, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Eloquent pagination.
parent
b29ba692
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
9 deletions
+35
-9
eloquent.php
system/db/eloquent.php
+35
-9
No files found.
system/db/eloquent.php
View file @
f7eeb85e
...
...
@@ -180,6 +180,31 @@ abstract class Eloquent {
return
(
count
(
$results
=
Eloquent\Hydrator
::
hydrate
(
$this
->
take
(
1
)))
>
0
)
?
reset
(
$results
)
:
null
;
}
/**
* Get paginated model results.
*
* @param int $per_page
* @return Paginator
*/
private
function
_paginate
(
$per_page
=
null
)
{
$total
=
$this
->
query
->
count
();
if
(
is_null
(
$per_page
))
{
if
(
!
property_exists
(
get_class
(
$this
),
'per_page'
))
{
throw
new
\Exception
(
"The number of models to display per page has not been specified."
);
}
$per_page
=
static
::
$per_page
;
}
$page
=
\System\Paginator
::
page
(
ceil
(
$total
/
$per_page
));
return
new
\System\Paginator
(
$this
->
for_page
(
$page
,
$per_page
)
->
get
(),
$total
,
$per_page
);
}
/**
* Retrieve the query for a 1:1 relationship.
*
...
...
@@ -190,6 +215,7 @@ abstract class Eloquent {
public
function
has_one
(
$model
,
$foreign_key
=
null
)
{
$this
->
relating
=
__FUNCTION__
;
return
$this
->
has_one_or_many
(
$model
,
$foreign_key
);
}
...
...
@@ -203,6 +229,7 @@ abstract class Eloquent {
public
function
has_many
(
$model
,
$foreign_key
=
null
)
{
$this
->
relating
=
__FUNCTION__
;
return
$this
->
has_one_or_many
(
$model
,
$foreign_key
);
}
...
...
@@ -417,14 +444,11 @@ abstract class Eloquent {
*/
public
function
__call
(
$method
,
$parameters
)
{
if
(
$method
==
'get'
)
if
(
in_array
(
$method
,
array
(
'get'
,
'first'
,
'paginate'
))
)
{
return
$this
->
_get
();
}
$method
=
'_'
.
$method
;
if
(
$method
==
'first'
)
{
return
$this
->
_first
();
return
$this
->
$method
();
}
if
(
in_array
(
$method
,
array
(
'count'
,
'sum'
,
'min'
,
'max'
,
'avg'
)))
...
...
@@ -446,14 +470,16 @@ abstract class Eloquent {
{
$model
=
static
::
make
(
get_called_class
());
if
(
$method
==
'
get'
or
$method
==
'
all'
)
if
(
$method
==
'all'
)
{
return
$model
->
_get
();
}
if
(
$method
==
'first'
)
if
(
in_array
(
$method
,
array
(
'get'
,
'first'
,
'paginate'
))
)
{
return
$model
->
_first
();
$method
=
'_'
.
$method
;
return
$model
->
$method
();
}
if
(
in_array
(
$method
,
array
(
'count'
,
'sum'
,
'min'
,
'max'
,
'avg'
)))
...
...
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