Author: jablko
Date: Thu Sep 17 19:56:00 2009
New Revision: 3403
Log:
Make QubitSearchPager a subclass of sfPager
Modified:
trunk/apps/qubit/modules/actor/actions/listAction.class.php
trunk/apps/qubit/modules/default/templates/_pager.php
trunk/apps/qubit/modules/informationobject/actions/listAction.class.php
trunk/apps/qubit/modules/repository/actions/listAction.class.php
trunk/apps/qubit/modules/search/actions/searchAction.class.php
trunk/apps/qubit/modules/search/templates/searchSuccess.php
trunk/lib/QubitSearchPager.class.php
Modified: trunk/apps/qubit/modules/actor/actions/listAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/actor/actions/listAction.class.php Thu Sep 17
19:55:19 2009 (r3402)
+++ trunk/apps/qubit/modules/actor/actions/listAction.class.php Thu Sep 17
19:56:00 2009 (r3403)
@@ -75,10 +75,12 @@
$query = new Zend_Search_Lucene_Search_Query_Boolean(array($query,
Zend_Search_Lucene_Search_QueryParser::parse($request->query)));
}
- $this->pager = new
QubitSearchPager($search->getEngine()->getIndex()->find($query),
$request->page);
+ $this->pager = new QubitSearchPager;
+ $this->pager->hits = $search->getEngine()->getIndex()->find($query);
+ $this->pager->setPage($request->page);
$ids = array();
- foreach ($this->pager->getHits() as $hit)
+ foreach ($this->pager->getResults() as $hit)
{
$ids[] = $hit->getDocument()->id;
}
Modified: trunk/apps/qubit/modules/default/templates/_pager.php
==============================================================================
--- trunk/apps/qubit/modules/default/templates/_pager.php Thu Sep 17
19:55:19 2009 (r3402)
+++ trunk/apps/qubit/modules/default/templates/_pager.php Thu Sep 17
19:56:00 2009 (r3403)
@@ -1,28 +1,28 @@
<?php if ($pager->haveToPaginate()): ?>
<div class="pager">
- <?php if (1 < $pager->getCurrentPage()): ?>
- <?php echo link_to('< '.__('previous'), array('page' =>
$pager->getCurrentPage() - 1) + $sf_request->getParameterHolder()->getAll()) ?>
+ <?php if (1 < $pager->getPage()): ?>
+ <?php echo link_to('< '.__('previous'), array('page' =>
$pager->getPage() - 1) + $sf_request->getParameterHolder()->getAll()) ?>
<?php endif; ?>
- <?php foreach ($pager->getPages() as $page): ?>
- <?php if ($pager->getCurrentPage() == $page): ?>
+ <?php foreach ($pager->getLinks() as $page): ?>
+ <?php if ($pager->getPage() == $page): ?>
<strong><?php echo $page ?></strong>
<?php else: ?>
<?php echo link_to($page, array('page' => $page) +
$sf_request->getParameterHolder()->getAll()) ?>
<?php endif; ?>
<?php endforeach ?>
- <?php if (count($pager->getPages()) > $pager->getCurrentPage()): ?>
- <?php echo link_to(__('next').' >', array('page' =>
$pager->getCurrentPage() + 1) + $sf_request->getParameterHolder()->getAll()) ?>
+ <?php if ($pager->getLastPage() > $pager->getPage()): ?>
+ <?php echo link_to(__('next').' >', array('page' => $pager->getPage() +
1) + $sf_request->getParameterHolder()->getAll()) ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="result-count">
- <?php if (count($pager->allHits) > 0): ?>
- <?php echo __('displaying %1% to %2% of %3% results', array('%1%' =>
$pager->getFirstHit(), '%2%' => $pager->getLastHit(), '%3%' =>
count($pager->allHits))) ?>
+ <?php if (0 < $pager->getNbResults()): ?>
+ <?php echo __('displaying %1% to %2% of %3% results', array('%1%' =>
$pager->getFirstIndice(), '%2%' => $pager->getLastIndice(), '%3%' =>
$pager->getNbResults())) ?>
<?php else: ?>
<?php echo __('No results found'); ?>
<? endif; ?>
Modified:
trunk/apps/qubit/modules/informationobject/actions/listAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/listAction.class.php
Thu Sep 17 19:55:19 2009 (r3402)
+++ trunk/apps/qubit/modules/informationobject/actions/listAction.class.php
Thu Sep 17 19:56:00 2009 (r3403)
@@ -86,10 +86,12 @@
$query->addSubquery(new Zend_Search_Lucene_Search_Query_Term(new
Zend_Search_Lucene_Index_Term(QubitTerm::PUBLICATION_STATUS_DRAFT_ID,
'publicationStatusId')), false);
}
- $this->pager = new
QubitSearchPager($search->getEngine()->getIndex()->find($query),
$request->page);
+ $this->pager = new QubitSearchPager;
+ $this->pager->hits = $search->getEngine()->getIndex()->find($query);
+ $this->pager->setPage($request->page);
$ids = array();
- foreach ($this->pager->getHits() as $hit)
+ foreach ($this->pager->getResults() as $hit)
{
$ids[] = $hit->getDocument()->id;
}
Modified: trunk/apps/qubit/modules/repository/actions/listAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/repository/actions/listAction.class.php Thu Sep
17 19:55:19 2009 (r3402)
+++ trunk/apps/qubit/modules/repository/actions/listAction.class.php Thu Sep
17 19:56:00 2009 (r3403)
@@ -35,10 +35,12 @@
$query = new Zend_Search_Lucene_Search_Query_Boolean(array($query,
Zend_Search_Lucene_Search_QueryParser::parse($request->query)));
}
- $this->pager = new
QubitSearchPager($search->getEngine()->getIndex()->find($query),
$request->page);
+ $this->pager = new QubitSearchPager;
+ $this->pager->hits = $search->getEngine()->getIndex()->find($query);
+ $this->pager->setPage($request->page);
$ids = array();
- foreach ($this->pager->getHits() as $hit)
+ foreach ($this->pager->getResults() as $hit)
{
$ids[] = $hit->getDocument()->id;
}
Modified: trunk/apps/qubit/modules/search/actions/searchAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/searchAction.class.php Thu Sep
17 19:55:19 2009 (r3402)
+++ trunk/apps/qubit/modules/search/actions/searchAction.class.php Thu Sep
17 19:56:00 2009 (r3403)
@@ -41,10 +41,12 @@
$query->addSubquery(Zend_Search_Lucene_Search_QueryParser::parse($request->query,
'UTF-8'), true);
- $this->pager = new
QubitSearchPager($search->getEngine()->getIndex()->find($query),
$request->page);
+ $this->pager = new QubitSearchPager;
+ $this->pager->hits = $search->getEngine()->getIndex()->find($query);
+ $this->pager->setPage($request->page);
$ids = array();
- foreach ($this->pager->getHits() as $hit)
+ foreach ($this->pager->getResults() as $hit)
{
$ids[] = $hit->getDocument()->id;
}
Modified: trunk/apps/qubit/modules/search/templates/searchSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/search/templates/searchSuccess.php Thu Sep 17
19:55:19 2009 (r3402)
+++ trunk/apps/qubit/modules/search/templates/searchSuccess.php Thu Sep 17
19:56:00 2009 (r3403)
@@ -1,7 +1,7 @@
<?php use_helper('Text') ?>
<?php if ($sf_request->query): ?>
- <h1 class="search"><?php echo __('Search for "%1%" returned %2% results',
array('%1%' => $sf_request->query, '%2%' => count($pager->allHits))) ?></h1>
+ <h1 class="search"><?php echo __('Search for "%1%" returned %2% results',
array('%1%' => $sf_request->query, '%2%' => $pager->getNbResults())) ?></h1>
<?php endif; ?>
<?php foreach ($informationObjects as $informationObject): ?>
Modified: trunk/lib/QubitSearchPager.class.php
==============================================================================
--- trunk/lib/QubitSearchPager.class.php Thu Sep 17 19:55:19 2009
(r3402)
+++ trunk/lib/QubitSearchPager.class.php Thu Sep 17 19:56:00 2009
(r3403)
@@ -23,99 +23,13 @@
* @author Peter Van Garderen <[email protected]>
* @version svn:$Id$
*/
-
-/*
- * This class is based on PHP Array Pagination by Derek Harvey
<www.lotsofcode.com>
- *
- */
-
-
-class QubitSearchPager
+class QubitSearchPager extends sfPager
{
- /*
- * Class constructor
- *
- * @param array $hits array of objects returned as hits from Zend Lucene
Search
- * @param integer $page current page of hits to display
- *
- */
- public function __construct($hits, $page)
- {
- // Assign the items per page variable
- if (sfConfig::get('app_hits_per_page') > 0)
- {
- // get perPage limit from Admin settings
- $this->perPage = sfConfig::get('app_hits_per_page', 10);
- }
- else
- {
- // set default perPage
- $this->perPage = 10;
- }
-
- // Assign the current page, first one by default
- $this->page = (int) $page ? $page : 1;
-
- // Take the length of the array
- $this->length = count($hits);
-
- // Get the number of pages
- $this->pages = ceil($this->length / $this->perPage);
-
- // Calculate the starting point
- $this->start = ceil(($this->page - 1) * $this->perPage);
-
- // Set the full array of hits
- $this->allHits = $hits;
-
- // Set the hits in scope on current page
- $this->hits = array_slice($hits, $this->start, $this->perPage);
- }
-
- public function getCurrentPage()
- {
- return $this->page;
- }
-
- public function getPages()
+ public function getResults()
{
- $links = array();
+ $this->nbResults = count($this->hits);
+ $this->lastPage = ceil($this->nbResults / $this->getMaxPerPage());
- for ($j = 1; $j < ($this->pages + 1); $j++)
- {
- $links[] = $j;
- }
-
- return $links;
- }
-
- public function haveToPaginate()
- {
- return count($this->allHits) > $this->perPage;
- }
-
- public function getHits()
- {
- return $this->hits;
- }
-
- public function getFirstHit()
- {
- return (($this->page - 1) * $this->perPage) + 1;
- }
-
- public function getLastHit()
- {
- if (count($this->getPages()) > $this->getCurrentPage())
- {
-
- return ($this->getFirstHit() + $this->perPage) - 1;
- }
- else
- {
-
- return (count($this->allHits));
- }
+ return array_slice($this->hits, $this->getFirstIndice() - 1,
$this->getMaxPerPage());
}
-
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---