Author: sevein
Date: Wed Apr 18 15:34:15 2012
New Revision: 11466
Log:
QubitSearchPager for paging ES results
Added:
branches/2.0/lib/QubitSearchPager.class.php
Modified:
branches/2.0/apps/qubit/modules/default/templates/_pager.php
branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php
branches/2.0/apps/qubit/modules/search/templates/_searchResults.php
Modified: branches/2.0/apps/qubit/modules/default/templates/_pager.php
==============================================================================
--- branches/2.0/apps/qubit/modules/default/templates/_pager.php Wed Apr
18 00:03:05 2012 (r11465)
+++ branches/2.0/apps/qubit/modules/default/templates/_pager.php Wed Apr
18 15:34:15 2012 (r11466)
@@ -1,25 +1,51 @@
-<div class="visible-phone">
+<?php if ($pager->haveToPaginate()): ?>
- <ul class="pager">
- <li class="previous"><a href="#"><?php echo __('← Previous')
?></a></li>
- <li class="next"><a href="#"><?php echo __('Next →') ?></a></li>
- </ul>
-
-</div>
-
-<div class="hidden-phone">
-
- <div class="pagination">
-
- <ul>
- <li><a href="#"><?php echo __('← Previous') ?></a></li>
- <li><a href="#">1</a></li>
- <li><a href="#">2</a></li>
- <li><a href="#">3</a></li>
- <li><a href="#">4</a></li>
- <li><a href="#"><?php echo __('Next →') ?></a></li>
- </ul>
+ <div class="visible-phone">
+ <div class="pager">
+ <ul>
+
+ <?php if (1 < $pager->getPage()): ?>
+ <li class="previous">
+ <?php echo link_to('« '. __('Previous'), array('page' =>
$pager->getPage() - 1) + $sf_request->getParameterHolder()->getAll()) ?>
+ </li>
+ <?php endif; ?>
+
+ <?php if ($pager->getLastPage() > $pager->getPage()): ?>
+ <li class="next">
+ <?php echo link_to(__('Next'). ' »', array('page' =>
$pager->getPage() + 1) + $sf_request->getParameterHolder()->getAll()) ?>
+ </li>
+ <?php endif; ?>
+ </ul>
+ </div>
</div>
-</div>
+ <div class="hidden-phone">
+ <div class="pagination">
+ <ul>
+
+ <?php if (1 < $pager->getPage()): ?>
+ <li class="previous">
+ <?php echo link_to('« '. __('Previous'), array('page' =>
$pager->getPage() - 1) + $sf_request->getParameterHolder()->getAll()) ?>
+ </li>
+ <?php endif; ?>
+
+ <?php foreach ($pager->getLinks(10) as $page): ?>
+ <?php if ($pager->getPage() == $page): ?>
+ <li class="active"><a href="#"><?php echo $page ?></a></li>
+ <?php else: ?>
+ <li><?php echo link_to($page, array('page' => $page) +
$sf_request->getParameterHolder()->getAll(), array('title' => __('Go to page
%1%', array('%1%' => $page)))) ?></li>
+ <?php endif; ?>
+ <?php endforeach ?>
+
+ <?php if ($pager->getLastPage() > $pager->getPage()): ?>
+ <li class="next">
+ <?php echo link_to(__('Next'). ' »', array('page' =>
$pager->getPage() + 1) + $sf_request->getParameterHolder()->getAll()) ?>
+ </li>
+ <?php endif; ?>
+
+ </ul>
+ </div>
+ </div>
+
+<?php endif; ?>
Modified: branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php
==============================================================================
--- branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php
Wed Apr 18 00:03:05 2012 (r11465)
+++ branches/2.0/apps/qubit/modules/search/actions/indexAction.class.php
Wed Apr 18 15:34:15 2012 (r11466)
@@ -82,23 +82,21 @@
}
// mock up a QubitPager for partial template backward compatibility
- $this->pager = new stdClass();
- $this->pager->resultSet = $resultSet;
+ $this->pager = new QubitSearchPager;
+ $this->pager->setResultSet($resultSet);
+ $this->pager->setPage($request->page ? $request->page : 1);
- if (0 < $resultSet->getTotalHits())
+ if ('print' != $request->getGetParameter('media'))
{
- if ('print' != $request->getGetParameter('media'))
- {
- $this->pager->maxPerPage = $request->limit;
- }
- else
- {
- $this->pager->maxPerPage = 500; // force for print
- }
-
- $this->pager->resultSet = $resultSet;
- $this->pager->page = $request->page ? $request->page : 1;
+ $this->pager->setMaxPerPage($request->limit);
+ }
+ else
+ {
+ $this->pager->setMaxPerPage(500); // force for print
+ }
+ if ($this->pager->hasResults())
+ {
// pre-populate some lookup tables for multilingual values
foreach (QubitTerm::getLevelsOfDescription() as $lod)
{
Modified: branches/2.0/apps/qubit/modules/search/templates/_searchResults.php
==============================================================================
--- branches/2.0/apps/qubit/modules/search/templates/_searchResults.php Wed Apr
18 00:03:05 2012 (r11465)
+++ branches/2.0/apps/qubit/modules/search/templates/_searchResults.php Wed Apr
18 15:34:15 2012 (r11466)
@@ -4,13 +4,13 @@
<div class="span12 hidden-phone">
<h1><?php echo __('%1% Search Results in %2% Institutions', array(
- '%1%' => $pager->resultSet->getTotalHits(),
+ '%1%' => $pager->getNbResults(),
'%2%' => count($pager->facets['repository_id']['terms']))) ?></h1>
</div>
<div id="phone-filter" class="span12 visible-phone">
<h2 class="widebtn btn-huge" data-toggle="collapse"
data-target="#facets, #top-facet"><?php echo __('Filter %1% Results', array(
- '%1%' => $pager->resultSet->getTotalHits())) ?></h2>
+ '%1%' => $pager->getNbResults())) ?></h2>
</div>
</div>
@@ -203,20 +203,14 @@
<?php endforeach; ?>
<?php if ($numResults > 0): ?>
-
<div class="result media">
<h3><a href="#"><?php echo __('%1% results with digital media',
array('%1%' => $numResults)) ?><strong><?php echo __('Show all')
?></strong></a></h3>
</div>
-
<?php endif; ?>
- <?php foreach ($pager->resultSet->getResults() as $hit): ?>
+ <?php foreach ($pager->getResults() as $hit): ?>
- <?php $doc = $hit->getData() ?>
- <?php foreach ($doc['i18n'] as $i18n): ?>
- <?php $doc[$i18n['culture']] = $i18n ?>
- <?php endforeach; ?>
- <?php unset($doc['i18n']); // continue; ?>
+ <?php $doc = build_i18n_doc($hit) ?>
<div class="result">
@@ -224,9 +218,7 @@
<?php echo
link_to(image_tag($doc['digitalObject']['thumbnail_FullPath'], array('alt' =>
'image-thumb', 'width' => '150', 'height' => '150')), array('module' =>
'informationobject', 'slug' => $doc['slug']), array('title' =>
$doc[$sf_user->getCulture()]['title'] ?: $doc[$doc['sourceCulture']]['title']))
?>
<?php endif; ?>
- <h3>
- <?php echo link_to(($doc[$sf_user->getCulture()]['title'] ?:
$doc[$doc['sourceCulture']]['title']) . ' <strong> ' .
$pager->levelsOfDescription[$doc['levelOfDescriptionId']] . ' </strong> <em> '
. (($doc['publicationStatusId'] == QubitTerm::PUBLICATION_STATUS_DRAFT_ID) ?
'Draft' : '') . ' </em>', array('module' => 'informationobject', 'slug' =>
$doc['slug'])) ?>
- </h3>
+ <h3><?php echo link_to(($doc[$sf_user->getCulture()]['title'] ?:
$doc[$doc['sourceCulture']]['title']) . ' <strong> ' .
$pager->levelsOfDescription[$doc['levelOfDescriptionId']] . ' </strong> <em> '
. (($doc['publicationStatusId'] == QubitTerm::PUBLICATION_STATUS_DRAFT_ID) ?
'Draft' : '') . ' </em>', array('module' => 'informationobject', 'slug' =>
$doc['slug'])) ?></h3>
<ul class="breadcrumb">
<?php foreach($doc['ancestors'] as $id): ?>
@@ -244,27 +236,12 @@
array('%1%' =>
$doc[$sf_user->getCulture()]['creator'][0]['name'] ?:
$doc[$doc['sourceCulture']]['creator'][0]['name'])) ?>
<?php endif; ?>
</p>
+
</div>
<?php endforeach; ?>
-
- <?php echo get_partial('default/pager') ?>
-
- <?php if ($pager->resultSet->getTotalHits() > $pager->maxPerPage): ?>
- <div class="pager">
- <?php if (1 < $pager->page): ?>
- <div class="previous">
- <?php echo link_to('«'. __('Previous'), array('page' =>
$pager->page - 1) + $sf_request->getParameterHolder()->getAll(), array('rel' =>
'prev', 'class' => 'widebtn gray btn-huge')) ?>
- </div>
- <?php endif; ?>
- <?php if ($pager->resultSet->getTotalHits() > ($pager->maxPerPage
* $pager->page)): ?>
- <div class="next">
- <?php echo link_to(__('Next'). ' »', array('page' =>
$pager->page + 1) + $sf_request->getParameterHolder()->getAll(), array('rel' =>
'next', 'class' => 'widebtn gray btn-huge')) ?>
- </div>
- <?php endif; ?>
- </div>
- <?php endif; ?>
+ <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
</div>
Added: branches/2.0/lib/QubitSearchPager.class.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/2.0/lib/QubitSearchPager.class.php Wed Apr 18 15:34:15 2012
(r11466)
@@ -0,0 +1,74 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class QubitSearchPager extends sfPager
+{
+ protected
+ $nbResults = null,
+ $resultSet;
+
+ public function init()
+ {
+ $this->setNbResults($this->resultSet->getTotalHits());
+
+ if (0 == $this->getPage() || 0 == $this->getMaxPerPage())
+ {
+ $this->setLastPage(0);
+ }
+ else
+ {
+ $this->setLastPage(ceil($this->getNbResults() / $this->getMAxPerPage()));
+ }
+ }
+
+ public function getResults()
+ {
+ if (!isset($this->nbResults))
+ {
+ $this->init();
+ }
+
+ return $this->resultSet->getResults();
+ }
+
+ public function hasResults()
+ {
+ if (!isset($this->nbResults))
+ {
+ $this->init();
+ }
+
+ return 0 < $this->getNbResults();
+ }
+
+ public function retrieveObject($offset)
+ {
+ return array_slice($this->getResults, $offset, 1);
+ }
+
+ public function setResultSet(Elastica_ResultSet $resultSet)
+ {
+ $this->resultSet = $resultSet;
+ }
+
+ public function getNbResults()
+ {
+ return parent::getNbResults();
+ }
+}
--
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.com/group/qubit-commits?hl=en.