Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
139720fb
Commit
139720fb
authored
Nov 25, 2007
by
guilhermeblanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CHG: Updated Doctrine_Pager to become coding standards compliant
parent
05147fbe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
165 additions
and
159 deletions
+165
-159
Pager.php
lib/Doctrine/Pager.php
+165
-159
No files found.
lib/Doctrine/Pager.php
View file @
139720fb
...
...
@@ -33,84 +33,90 @@
*/
class
Doctrine_Pager
{
/**
/**
* @var Doctrine_Query $query Doctrine_Query object related to the pager
*/
protected
$query
;
/**
protected
$query
;
/**
* @var int $nbResults Number of results found
*/
protected
$nbResults
;
protected
$nbResults
;
/**
* @var int $maxPerPage Maximum number of itens per page
*/
protected
$maxPerPage
;
/**
protected
$maxPerPage
;
/**
* @var int $page Current page
*/
protected
$page
;
/**
protected
$page
;
/**
* @var int $lastPage Last page (total of pages)
*/
protected
$lastPage
;
protected
$lastPage
;
/**
* __construct
*
* @param mixed $query Accepts either a Doctrine_Query object or a string (which does the Doctrine_Query class creation).
* @param mixed $query Accepts either a Doctrine_Query object or a string
* (which does the Doctrine_Query class creation).
* @param int $page Current page
* @param int $maxPerPage Maximum itens per page
* @return void
*/
public
function
__construct
(
$query
,
$page
,
$maxPerPage
=
0
)
{
$this
->
setQuery
(
$query
);
$this
->
_setMaxPerPage
(
$maxPerPage
);
$this
->
_setPage
(
$page
);
$this
->
initialize
();
}
/**
* initialize
*
* Initialize Pager object calculating number of results
*
* @return void
*/
protected
function
initialize
()
{
public
function
__construct
(
$query
,
$page
,
$maxPerPage
=
0
)
{
$this
->
setQuery
(
$query
);
$this
->
_setMaxPerPage
(
$maxPerPage
);
$this
->
_setPage
(
$page
);
$this
->
initialize
();
}
/**
* initialize
*
* Initialize Pager object calculating number of results
*
* @return void
*/
protected
function
initialize
()
{
// etrieve the number of itens found
$count
=
$this
->
getQuery
()
->
offset
(
0
)
->
limit
(
0
)
->
count
();
$this
->
setNbResults
(
$count
);
$this
->
adjustOffset
();
}
/**
* adjustOffset
*
* Adjusts last page of Doctrine_Pager, offset and limit of Doctrine_Query associated
*
* @return void
*/
protected
function
adjustOffset
()
{
$this
->
setLastPage
(
max
(
1
,
ceil
(
$this
->
getNbResults
()
/
$this
->
getMaxPerPage
())));
$offset
=
(
$this
->
getPage
()
-
1
)
*
$this
->
getMaxPerPage
();
$p
=
$this
->
getQuery
();
$p
->
offset
(
$offset
);
$p
->
limit
(
$this
->
getMaxPerPage
());
}
$this
->
setNbResults
(
$count
);
$this
->
adjustOffset
();
}
/**
* adjustOffset
*
* Adjusts last page of Doctrine_Pager, offset and limit of Doctrine_Query associated
*
* @return void
*/
protected
function
adjustOffset
()
{
// Define new total of pages
$this
->
setLastPage
(
max
(
1
,
ceil
(
$this
->
getNbResults
()
/
$this
->
getMaxPerPage
()))
);
$offset
=
(
$this
->
getPage
()
-
1
)
*
$this
->
getMaxPerPage
();
// Assign new offset and limit to Doctrine_Query object
$p
=
$this
->
getQuery
();
$p
->
offset
(
$offset
);
$p
->
limit
(
$this
->
getMaxPerPage
());
}
/**
...
...
@@ -120,10 +126,10 @@ class Doctrine_Pager
*
* @return int the number of results found
*/
public
function
getNbResults
()
{
return
$this
->
nbResults
;
}
public
function
getNbResults
()
{
return
$this
->
nbResults
;
}
/**
...
...
@@ -134,10 +140,10 @@ class Doctrine_Pager
* @param $nb Number of results found on initial query fetch
* @return void
*/
protected
function
setNbResults
(
$nb
)
{
$this
->
nbResults
=
$nb
;
}
protected
function
setNbResults
(
$nb
)
{
$this
->
nbResults
=
$nb
;
}
/**
...
...
@@ -147,10 +153,10 @@ class Doctrine_Pager
*
* @return int first page
*/
public
function
getFirstPage
()
{
return
1
;
}
public
function
getFirstPage
()
{
return
1
;
}
/**
...
...
@@ -160,10 +166,10 @@ class Doctrine_Pager
*
* @return int last page (total of pages)
*/
public
function
getLastPage
()
{
return
$this
->
lastPage
;
}
public
function
getLastPage
()
{
return
$this
->
lastPage
;
}
/**
...
...
@@ -174,15 +180,15 @@ class Doctrine_Pager
* @param $page last page (total of pages)
* @return void
*/
protected
function
setLastPage
(
$page
)
{
$this
->
lastPage
=
$page
;
protected
function
setLastPage
(
$page
)
{
$this
->
lastPage
=
$page
;
if
(
$this
->
getPage
()
>
$page
)
{
$this
->
_setPage
(
$page
);
}
}
if
(
$this
->
getPage
()
>
$page
)
{
$this
->
_setPage
(
$page
);
}
}
/**
...
...
@@ -192,10 +198,10 @@ class Doctrine_Pager
*
* @return int current page
*/
public
function
getPage
()
{
return
$this
->
page
;
}
public
function
getPage
()
{
return
$this
->
page
;
}
/**
...
...
@@ -205,10 +211,10 @@ class Doctrine_Pager
*
* @return int next page
*/
public
function
getNextPage
()
{
return
min
(
$this
->
getPage
()
+
1
,
$this
->
getLastPage
());
}
public
function
getNextPage
()
{
return
min
(
$this
->
getPage
()
+
1
,
$this
->
getLastPage
());
}
/**
...
...
@@ -218,26 +224,26 @@ class Doctrine_Pager
*
* @return int previous page
*/
public
function
getPreviousPage
()
{
return
max
(
$this
->
getPage
()
-
1
,
$this
->
getFirstPage
());
}
/**
* haveToPaginate
*
* Return true if it's necessary to paginate or false if not
*
* @return bool true if it is necessary to paginate, false otherwise
*/
public
function
haveToPaginate
()
{
return
$this
->
getNbResults
()
>
$this
->
getMaxPerPage
();
}
/**
public
function
getPreviousPage
()
{
return
max
(
$this
->
getPage
()
-
1
,
$this
->
getFirstPage
());
}
/**
* haveToPaginate
*
* Return true if it's necessary to paginate or false if not
*
* @return bool true if it is necessary to paginate, false otherwise
*/
public
function
haveToPaginate
()
{
return
$this
->
getNbResults
()
>
$this
->
getMaxPerPage
();
}
/**
* setPage
*
* Defines the current page and automatically adjust offset and limits
...
...
@@ -245,11 +251,11 @@ class Doctrine_Pager
* @param $page current page
* @return void
*/
public
function
setPage
(
$page
)
{
$this
->
_setPage
(
$page
);
$this
->
adjustOffset
();
}
public
function
setPage
(
$page
)
{
$this
->
_setPage
(
$page
);
$this
->
adjustOffset
();
}
/**
...
...
@@ -260,11 +266,11 @@ class Doctrine_Pager
* @param $page current page
* @return void
*/
private
function
_setPage
(
$page
)
{
$page
=
intval
(
$page
);
$this
->
page
=
(
$page
<=
0
)
?
1
:
$page
;
}
private
function
_setPage
(
$page
)
{
$page
=
intval
(
$page
);
$this
->
page
=
(
$page
<=
0
)
?
1
:
$page
;
}
/**
...
...
@@ -274,13 +280,13 @@ class Doctrine_Pager
*
* @return int maximum number of itens per page
*/
public
function
getMaxPerPage
()
{
return
$this
->
maxPerPage
;
}
/**
public
function
getMaxPerPage
()
{
return
$this
->
maxPerPage
;
}
/**
* setMaxPerPage
*
* Defines the maximum number of itens per page and automatically adjust offset and limits
...
...
@@ -288,11 +294,11 @@ class Doctrine_Pager
* @param $max maximum number of itens per page
* @return void
*/
public
function
setMaxPerPage
(
$max
)
{
$this
->
_setMaxPerPage
(
$max
);
$this
->
adjustOffset
();
}
public
function
setMaxPerPage
(
$max
)
{
$this
->
_setMaxPerPage
(
$max
);
$this
->
adjustOffset
();
}
/**
...
...
@@ -303,16 +309,16 @@ class Doctrine_Pager
* @param $max maximum number of itens per page
* @return void
*/
private
function
_setMaxPerPage
(
$max
)
{
if
(
$max
>
0
)
{
$this
->
maxPerPage
=
$max
;
}
else
if
(
$max
==
0
)
{
$this
->
maxPerPage
=
25
;
}
else
{
$this
->
maxPerPage
=
abs
(
$max
);
}
}
private
function
_setMaxPerPage
(
$max
)
{
if
(
$max
>
0
)
{
$this
->
maxPerPage
=
$max
;
}
else
if
(
$max
==
0
)
{
$this
->
maxPerPage
=
25
;
}
else
{
$this
->
maxPerPage
=
abs
(
$max
);
}
}
/**
...
...
@@ -322,10 +328,10 @@ class Doctrine_Pager
*
* @return Doctrine_Query Doctrine_Query object related to the pager
*/
public
function
getQuery
()
{
return
$this
->
query
;
}
public
function
getQuery
()
{
return
$this
->
query
;
}
/**
...
...
@@ -333,17 +339,18 @@ class Doctrine_Pager
*
* Defines the maximum number of itens per page
*
* @param $query Accepts either a Doctrine_Query object or a string (which does the Doctrine_Query class creation).
* @param $query Accepts either a Doctrine_Query object or a string
* (which does the Doctrine_Query class creation).
* @return void
*/
protected
function
setQuery
(
$query
)
{
if
(
is_string
(
$query
))
{
$query
=
Doctrine_Query
::
create
()
->
from
(
$query
);
}
protected
function
setQuery
(
$query
)
{
if
(
is_string
(
$query
))
{
$query
=
Doctrine_Query
::
create
()
->
from
(
$query
);
}
$this
->
query
=
$query
;
}
$this
->
query
=
$query
;
}
/**
...
...
@@ -351,13 +358,12 @@ class Doctrine_Pager
* executes the query and populates the data set
*
* @param $params Optional parameters to Doctrine_Query::execute
* @param $hydrationMode Hyddration Mode of Doctrine_Query::execute returned ResultSet. Doctrine::Default is FETCH_RECORD
* @param $hydrationMode Hyddration Mode of Doctrine_Query::execute
* returned ResultSet. Doctrine::Default is FETCH_RECORD
* @return Doctrine_Collection the root collection
*/
public
function
execute
(
$params
=
array
(),
$hydrationMode
=
Doctrine
::
FETCH_RECORD
)
{
return
$this
->
getQuery
()
->
execute
(
$params
,
$hydrationMode
);
}
public
function
execute
(
$params
=
array
(),
$hydrationMode
=
Doctrine
::
FETCH_RECORD
)
{
return
$this
->
getQuery
()
->
execute
(
$params
,
$hydrationMode
);
}
}
?>
\ No newline at end of file
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