Fixed whitespace for coding conventions. Optimized function searchDB() - it doesnt do everything twice now, just once. Completely redid the pagination() function so that it works properly. Renamed reOrder() to reorder().
This commit is contained in:
parent
d362f0c3c9
commit
b61b24945a
1 changed files with 64 additions and 83 deletions
|
@ -189,96 +189,77 @@ class uiSearch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the search query. Use getResult() to get the results.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function searchDB()
|
function searchDB()
|
||||||
{
|
{
|
||||||
if (count($this->criteria) === 0) {
|
if (count($this->criteria) === 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$offset = (isset($this->criteria['offset'])) ? $this->criteria['offset'] : 0;
|
$offset = (isset($this->criteria['offset'])) ? $this->criteria['offset'] : 0;
|
||||||
$this->results = array('page' => $offset / $this->criteria['limit']);
|
$this->results = array('page' => $offset / $this->criteria['limit']);
|
||||||
|
|
||||||
//print_r($this->criteria);
|
|
||||||
$results = $this->Base->gb->localSearch($this->criteria, $this->Base->sessid);
|
$results = $this->Base->gb->localSearch($this->criteria, $this->Base->sessid);
|
||||||
if (PEAR::isError($results)) {
|
$this->results['items'] = $results["results"];
|
||||||
//print_r($results);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
foreach ($results['results'] as $rec) {
|
|
||||||
$tmpId = $this->Base->gb->_idFromGunid($rec["gunid"]);
|
|
||||||
$this->results['items'][] = $this->Base->getMetaInfo($tmpId);
|
|
||||||
}
|
|
||||||
$this->results['cnt'] = $results['cnt'];
|
$this->results['cnt'] = $results['cnt'];
|
||||||
|
$this->pagination();
|
||||||
/*
|
|
||||||
## test
|
|
||||||
for ($n=0; $n<=$this->criteria['limit']; $n++) {
|
|
||||||
$this->results['items'][] = Array
|
|
||||||
(
|
|
||||||
'id' => 24,
|
|
||||||
'gunid' => '1cc472228d0cb2ac',
|
|
||||||
'title' => 'Item '.$n,
|
|
||||||
'creator' => 'Sebastian',
|
|
||||||
'duration' => ' 10:00',
|
|
||||||
'type' => 'webstream'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$results['cnt'] = 500;
|
|
||||||
$this->results['cnt'] = $results['cnt'];
|
|
||||||
## end test
|
|
||||||
*/
|
|
||||||
|
|
||||||
//print_r($this->results);
|
|
||||||
$this->pagination($results);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function pagination($results)
|
function pagination()
|
||||||
{
|
{
|
||||||
if (sizeof($this->results['items']) == 0) {
|
if (sizeof($this->results['items']) == 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
$offset = isset($this->criteria['offset']) ? $this->criteria['offset'] : 0;
|
$offset = isset($this->criteria['offset']) ? $this->criteria['offset'] : 0;
|
||||||
$currp = ($offset / $this->criteria['limit']) + 1; // current page
|
$currentPage = ($offset / $this->criteria['limit']) + 1;
|
||||||
$maxp = ceil($results['cnt'] / $this->criteria['limit']); // maximum page
|
$maxPage = ceil($this->results['cnt'] / $this->criteria['limit']);
|
||||||
|
|
||||||
/*
|
|
||||||
for ($n = 1; $n <= $maxp; $n = $n+$width) {
|
|
||||||
$width = pow(10, floor(($n)/10));
|
|
||||||
$this->results['pagination'][$n] = $n;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
$deltaLower = UI_SEARCHRESULTS_DELTA;
|
$deltaLower = UI_SEARCHRESULTS_DELTA;
|
||||||
$deltaUpper = UI_SEARCHRESULTS_DELTA;
|
$deltaUpper = UI_SEARCHRESULTS_DELTA;
|
||||||
$start = $currp;
|
$maxNumPaginationButtons = $deltaLower + $deltaUpper + 1;
|
||||||
|
|
||||||
if ($start + $maxp > 0) {
|
$start = 1;
|
||||||
$deltaLower += $start - $maxp; // correct lower boarder if page is near end
|
$end = $maxPage;
|
||||||
|
|
||||||
|
// If there are enough pages to warrant "next" and "previous"
|
||||||
|
// buttons...
|
||||||
|
if ($maxPage > $maxNumPaginationButtons) {
|
||||||
|
// When currentPage goes past deltaLower
|
||||||
|
if ($currentPage <= $deltaLower) {
|
||||||
|
$end = min($deltaLower + $deltaUpper + 1, $maxPage);
|
||||||
|
}
|
||||||
|
// When currentpage is near the end of the results.
|
||||||
|
elseif ($currentPage >= ($maxPage - $deltaUpper)) {
|
||||||
|
$start = max($maxPage - $deltaLower - $deltaUpper + 1, 1);
|
||||||
|
}
|
||||||
|
// somewhere in the middle
|
||||||
|
else {
|
||||||
|
$start = max($currentPage - $deltaLower, 1);
|
||||||
|
$end = min($currentPage + $deltaUpper, $maxPage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($n = $start-$deltaLower; $n <= $start+$deltaUpper; $n++) {
|
for ($n = $start; $n <= $end; $n++) {
|
||||||
if ($n <= 0) {
|
|
||||||
$deltaUpper++; // correct upper boarder if page is near zero
|
|
||||||
} elseif ($n <= $maxp) {
|
|
||||||
$this->results['pagination'][$n] = $n;
|
$this->results['pagination'][$n] = $n;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#array_pop($this->results['pagination']);
|
if (!isset($this->results['pagination'][1])) {
|
||||||
$this->results['pagination'][1] ? NULL : $this->results['pagination'][1] = '|<<';
|
$this->results['pagination'][1] = '|<<';
|
||||||
$this->results['pagination'][$maxp] ? NULL : $this->results['pagination'][$maxp] = '>>|';
|
}
|
||||||
$this->results['next'] = ($results['cnt'] > $offset + $this->criteria['limit']) ? TRUE : FALSE;
|
if (!isset($this->results['pagination'][$maxPage])) {
|
||||||
|
$this->results['pagination'][$maxPage] = '>>|';
|
||||||
|
}
|
||||||
|
$this->results['next'] = ($this->results['cnt'] > $offset + $this->criteria['limit']) ? TRUE : FALSE;
|
||||||
$this->results['prev'] = ($offset > 0) ? TRUE : FALSE;
|
$this->results['prev'] = ($offset > 0) ? TRUE : FALSE;
|
||||||
ksort($this->results['pagination']);
|
ksort($this->results['pagination']);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function reOrder($by)
|
function reorder($by)
|
||||||
{
|
{
|
||||||
$this->criteria['offset'] = NULL;
|
$this->criteria['offset'] = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue