RvTwoClasses
[
class tree: RvTwoClasses
] [
index: RvTwoClasses
] [
all elements
]
Todo List
Packages:
Controllers
DDMS
Models
RvTwoClasses
Source for file searchResult.php
Documentation is available at
searchResult.php
<?php
/**
* <b>Class Description</b>: Wrapper class for an array of data that can be stored in the session array and
* accessed by subsequent AJAX calls for client scrolling through the data set in small chunks. *
*
@since
: 29/04/2009
*
@author
Jan van der Breggen
*
@package
RvTwoClasses
*
***/
class
SearchResult
{
private
$data
=
array
(
)
;
private
$resultsPerPage
=
0
;
private
$numberOfResults
=
0
;
private
$currentPage
= -
1
;
private
$numberOfPages
=
0
;
private
$cursor
=
0
;
private
$columns
=
array
(
)
;
function
__construct
(
$data
,
$resultsPerPage
,
$idField
=
'id'
)
{
$this
->
data
=
$this
->
makeDataArray
(
$data
,
$idField
)
;
$this
->
columns
=
$this
->
makeColumnArray
(
)
;
//print_r($data);
$this
->
resultsPerPage
=
$resultsPerPage
;
$this
->
numberOfResults
=
count
(
$data
)
;
$this
->
numberOfPages
= (integer)
(
$this
->
numberOfResults
/
$this
->
resultsPerPage
)
;
if
(
fmod
(
(float)
$this
->
numberOfResults
,
(float)
$this
->
resultsPerPage
)
<>
0
)
{
$this
->
numberOfPages
++
;
}
}
function
makeColumnArray
(
)
{
if
(
count
(
$this
->
data
)
>
0
)
{
return
array_keys
(
current
(
$this
->
data
))
;
}
return
array
(
)
;
}
function
getColumns
(
)
{
return
$this
->
columns
;
}
function
makeDataArray
(
$data
,
$idField
)
{
$newData
=
array
(
)
;
foreach
(
$data
as
$record
)
{
$newData
[
$record
[
$idField
]]
=
$record
;
}
return
$newData
;
}
function
getSelectValues
(
$idField
,
$arg1
,
$arg2
=
''
)
{
$result
=
array
(
)
;
foreach
(
$this
->
data
as
$record
)
{
$result
[
$record
[
$idField
]]
=
"
$record
[
$arg1
]
$record
[
$arg2
]
"
;
}
return
$result
;
}
function
getNextPage
(
)
{
return
$this
->
getPage
(
$this
->
currentPage
+
1
)
;
/*
$page = array();
if($this->currentPage+2>$this->numberOfPages){
$page = array_slice($this->data, $this->cursor, $this->numberOfResults-1);
} else {
$page = array_slice($this->data, $this->cursor, $this->resultsPerPage);
}
$this->currentPage++;
$this->cursor += count($page);
return $page;
*/
}
function
getPreviousPage
(
)
{
return
$this
->
getPage
(
$this
->
currentPage
-
1
)
;
}
function
getPage
(
$number
)
{
if
(
$number
==
$this
->
numberOfPages
)
{
$page
=
array_slice
(
$this
->
data
,
$number
*
$this
->
resultsPerPage
,
$this
->
numberOfResults
-
1
)
;
}
else
{
$page
=
array_slice
(
$this
->
data
,
$number
*
$this
->
resultsPerPage
,
$this
->
resultsPerPage
)
;
}
$this
->
cursor
=
(
$number
*
$this
->
resultsPerPage
)
+
count
(
$page
)
;
$this
->
currentPage
=
$number
;
return
$page
;
}
function
getCurrentPageNumber
(
)
{
return
$this
->
currentPage
;
}
function
getCurrentPageNumberForDisplay
(
)
{
return
$this
->
currentPage
+
1
;
}
function
getNumberOfPages
(
)
{
return
$this
->
numberOfPages
;
}
function
getNumberOfResults
(
)
{
return
count
(
$this
->
data
)
;
}
function
nextPagesLeft
(
)
{
if
(
$this
->
currentPage
==
$this
->
numberOfPages
-
1
)
return
false
;
return
true
;
}
function
previousPagesLeft
(
)
{
if
(
$this
->
currentPage
==
0
)
return
false
;
return
true
;
}
function
getResultByID
(
$id
)
{
return
$this
->
data
[
$id
]
;
}
}
?>
Documentation generated on Mon, 18 May 2009 11:22:17 +0200 by
phpDocumentor 1.4.1