- Fixed a sort order issue if the ID's in the database weren't in the correct order

- Added "pseudo-google-style" page numbers so there weren't hundreds of links on
every page
This commit is contained in:
wclouser%mozilla.com 2006-06-02 17:32:03 +00:00
Родитель f104c35a07
Коммит a645b84541
4 изменённых файлов: 51 добавлений и 36 удалений

Просмотреть файл

@ -155,7 +155,7 @@ class ResultsController extends AppController {
function index()
{
// Products dropdown
$this->set('products', $this->Application->findAll('visible=1'));
$this->set('products', $this->Application->findAll('visible=1', null, 'Application.id ASC'));
// Fill in all the data passed in $_GET
$this->set('url_params',$this->decodeAndSanitize($this->params['url']));
@ -176,7 +176,7 @@ class ResultsController extends AppController {
function comments()
{
// Products dropdown
$this->set('products', $this->Application->findAll('visible=1'));
$this->set('products', $this->Application->findAll('visible=1', null, 'Application.id ASC'));
// Fill in all the data passed in $_GET
$this->set('url_params',$this->decodeAndSanitize($this->params['url']));

Просмотреть файл

@ -55,8 +55,8 @@ class Result extends AppModel {
/* Note that 'Application' is not the actual name of the table! You can
* thank cake for that.*/
array_push($_conditions, "`Application`.`name` LIKE '%{$_product}%'");
array_push($_conditions, "`Application`.`version` LIKE '%{$_version}%'");
array_push($_conditions, "`Application`.`name` LIKE '{$_product}'");
array_push($_conditions, "`Application`.`version` LIKE '{$_version}'");
} else {
// defaults I guess?
array_push($_conditions, "`Application`.`name` LIKE 'Mozilla Firefox'");
@ -120,8 +120,8 @@ class Result extends AppModel {
/* Note that 'Application' is not the actual name of the table! You can
* thank cake for that.*/
array_push($_conditions, "`Application`.`name` LIKE '%{$_product}%'");
array_push($_conditions, "`Application`.`version` LIKE '%{$_version}%'");
array_push($_conditions, "`Application`.`name` LIKE '{$_product}'");
array_push($_conditions, "`Application`.`version` LIKE '{$_version}'");
} else {
// defaults I guess?
array_push($_conditions, "`Application`.`name` LIKE 'Mozilla Firefox'");

Просмотреть файл

@ -105,43 +105,58 @@ class PaginationHelper {
return false;
}
/**
* Returns a list of page numbers separated by $separator
* Returns a "Google style" list of page numbers
*
* @param string $separator - defaults to null
* @param string $prefix - defaults to null. If set, displays prefix before page links.
* @param int $pageSetLength - defaults to 10. Maximum number of pages to show.
* @param string $prevLabel - defaults to null. If set, displays previous link.
* @param string $nextLabel - defaults to null. If set, displays next link.
*
**/
function pageNumbers($separator=null)
function pageNumbers($separator=null, $prefix=null, $pageSetLength=10, $prevLabel=null, $nextLabel=null)
{
if (empty($this->_pageDetails) || $this->_pageDetails['pageCount'] == 1) { return false; }
$t = array();
$text = '';
$pc = 1;
do
$modulo = $this->_pageDetails['page'] % $pageSetLength;
if ($modulo)
{ // any number > 0
$prevSetLastPage = $this->_pageDetails['page'] - $modulo;
} else { // 0, last page of set
$prevSetLastPage = $this->_pageDetails['page'] - $pageSetLength;
}
//$nextSetFirstPage = $prevSetLastPage + $pageSetLength + 1;
if ($prevLabel) $t[] = $this->prevPage($prevLabel);
// loops through each page number
$pageSet = $prevSetLastPage + $pageSetLength;
if ($pageSet > $this->_pageDetails['pageCount']) $pageSet = $this->_pageDetails['pageCount'];
for ($pageIndex = $prevSetLastPage+1; $pageIndex <= $pageSet; $pageIndex++)
{
if ($pageIndex == $this->_pageDetails['page'])
{
if($pc == $this->_pageDetails['page'])
{
$text = '<em>'.$pc.'</em>';
}
else
{
if($this->style == 'ajax')
{
$text = $this->Ajax->linkToRemote($pc, array("fallback"=>$this->action."#","url" =>$this->link.$pc,"update" => "ajax_update","method"=>"get"));
}
else
{
$text = $this->Html->link($pc,$this->link.$pc);
}
}
$t[] = $text;
$pc++;
}
while ($pc<=$this->_pageDetails['pageCount']);
$t = implode($separator, $t);
return $t;
$t[] = '<em>'.$pageIndex.'</em>';
}
else
{
if($this->style == 'ajax')
{
$t[] = $this->Ajax->linkToRemote($pageIndex, array("fallback"=>$this->action."#","url" =>$this->link.$pageIndex,"update" => "ajax_update","method"=>"get"));
} else {
$t[] = $this->Html->link($pageIndex,$this->link.$pageIndex);
}
}
}
if ($nextLabel) $t[] = $this->nextPage($nextLabel);
$t = implode($separator, $t);
return $prefix.$t;
}
/**
* Displays a link to the previous page, where the page doesn't exist then

Просмотреть файл

@ -40,7 +40,7 @@
<ul id="page-numbers">
<li><?php echo $pagination->show('Show ', ' '); ?></li>
<li><?php echo $pagination->result('Results: '); ?></li>
<li><?php echo $pagination->pageNumbers(' '); ?></li>
<li><?php echo $pagination->pageNumbers(' ',null,10,'Prev','Next'); ?></li>
</ul>
<?php endif;?>