Author: peter
Date: 2008-09-28 11:32:00 -0700 (Sun, 28 Sep 2008)
New Revision: 1393
Added:
trunk/apps/qubit/lib/SearchPager.class.php
Modified:
trunk/apps/qubit/modules/search/actions/keywordAction.class.php
trunk/apps/qubit/modules/search/templates/_sidebar.php
trunk/apps/qubit/modules/search/templates/keywordSuccess.php
trunk/web/css/graphic.css
Log:
add simple paging to search results. Uses the same styling and same max hits
per page Admin setting as browse paging. TODO: add a maximum number of pages
option.
Added: trunk/apps/qubit/lib/SearchPager.class.php
===================================================================
--- trunk/apps/qubit/lib/SearchPager.class.php (rev 0)
+++ trunk/apps/qubit/lib/SearchPager.class.php 2008-09-28 18:32:00 UTC (rev
1393)
@@ -0,0 +1,114 @@
+<?php
+
+/*
+ * This file is part of the Qubit Toolkit.
+ * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
+ *
+ * It is based on PHP Array Pagination
+ * Copyright (C) 2007 Derek Harvey <www.lotsofcode.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+class searchPager
+{
+ 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
+ $this->page = $page;
+
+ // 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);
+ }
+
+ function getCurrentPage()
+ {
+ return $this->page;
+ }
+
+ function getPages()
+ {
+ $links = array();
+
+ for ($j = 1; $j < ($this->pages + 1); $j++)
+ {
+ $links[] = $j;
+ }
+
+ return $links;
+ }
+
+ function haveToPaginate()
+ {
+ if (count($this->allHits) > $this->perPage)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ function getHits()
+ {
+ return $this->hits;
+ }
+
+ function getFirstHit()
+ {
+ return (($this->page - 1) * $this->perPage) + 1;
+ }
+
+ function getLastHit()
+ {
+ if (count($this->getPages()) > $this->getCurrentPage())
+ {
+
+ return ($this->getFirstHit() + $this->perPage) -1;
+ }
+ else
+ {
+ return (count($this->allHits));
+ }
+ }
+
+}
\ No newline at end of file
Modified: trunk/apps/qubit/modules/search/actions/keywordAction.class.php
===================================================================
--- trunk/apps/qubit/modules/search/actions/keywordAction.class.php
2008-09-26 17:36:50 UTC (rev 1392)
+++ trunk/apps/qubit/modules/search/actions/keywordAction.class.php
2008-09-28 18:32:00 UTC (rev 1393)
@@ -25,7 +25,7 @@
{
$culture = $this->getUser()->getCulture();
setlocale(LC_CTYPE, $culture.'.utf-8');
- $this->query = $this->getRequestParameter('search_query');
+ $this->query = $this->getRequestParameter('query');
if ($this->query)
{
@@ -45,8 +45,24 @@
$hits = $index->find($c);
}
$this->hits = $hits;
+
+ //* begin pager expirement */
+ // send results through pagination
+ if ($this->getRequestParameter('page'))
+ {
+ $page = $this->getRequestParameter('page');
}
+ else
+ {
+ //set default page
+ $page = 1;
+ }
+ $this->results = new searchPager($hits, $page);
+ //* end pager expirement */
+
+ }
+
public function handleError()
{
return sfView::SUCCESS;
Modified: trunk/apps/qubit/modules/search/templates/_sidebar.php
===================================================================
--- trunk/apps/qubit/modules/search/templates/_sidebar.php 2008-09-26
17:36:50 UTC (rev 1392)
+++ trunk/apps/qubit/modules/search/templates/_sidebar.php 2008-09-28
18:32:00 UTC (rev 1393)
@@ -1,7 +1,7 @@
<div id="search-sidebar">
<?php echo form_tag('search/keyword', 'class=sidebarForm') ?>
<div>
- <?php echo input_tag('search_query',
$sf_request->getParameter('search_query'), 'class="textbox"') ?>
+ <?php echo input_tag('query', $sf_request->getParameter('query'),
'class="textbox"') ?>
</div>
<div>
<?php echo my_submit_tag(__('search')) ?>
Modified: trunk/apps/qubit/modules/search/templates/keywordSuccess.php
===================================================================
--- trunk/apps/qubit/modules/search/templates/keywordSuccess.php
2008-09-26 17:36:50 UTC (rev 1392)
+++ trunk/apps/qubit/modules/search/templates/keywordSuccess.php
2008-09-28 18:32:00 UTC (rev 1393)
@@ -1,10 +1,9 @@
<?php use_helper('Text') ?>
<?php if ($query): ?>
- <h1 class="search"><?php echo __("search for '%1%' returned %2% results",
array('%1%' => $query, '%2%' => count($hits))); ?></h1>
+ <h1 class="search"><?php echo __("Search for '%1%' returned %2% results",
array('%1%' => $query, '%2%' => count($hits))); ?></h1>
<?php endif; ?>
-<?php foreach ($hits as $hit): ?>
-
+<?php foreach ($results->getHits() as $hit): ?>
<div class="search-results" style="padding-top: 5px;">
<h3><?php echo link_to($hit->display_title,
'informationobject/show?id='.$hit->informationObjectId) ?></h3>
@@ -19,5 +18,22 @@
</div>
</div>
+<?php endforeach; ?>
-<?php endforeach; ?>
+<?php if ($results->haveToPaginate()): ?>
+ <div class="pager">
+ <?php if ($results->getCurrentPage() != 1): ?>
+ <?php echo link_to('< '.__('previous'),
'search/keyword?query='.$query.'&page='.($results->getCurrentPage() -1)) ?>
+ <?php endif; ?>
+ <?php foreach ($results->getPages() as $page): ?>
+ <?php echo ($page == $results->getCurrentPage()) ?
'<strong>'.$page.'</strong>' : link_to($page,
'search/keyword?query='.$query.'&page='.$page) ?>
+ <?php endforeach; ?>
+ <?php if (count($results->getPages()) > $results->getCurrentPage()): ?>
+ <?php echo link_to(__('next').' >',
'search/keyword?query='.$query.'&page='.($results->getCurrentPage() +1)) ?>
+ <?php endif; ?>
+ </div>
+<?php endif; ?>
+
+<div class="result-count">
+<?php echo __('displaying %1% to %2% of %3% results', array('%1%' =>
$results->getFirstHit(), '%2%' => $results->getLastHit(), '%3%' =>
count($hits))) ?>
+</div>
\ No newline at end of file
Modified: trunk/web/css/graphic.css
===================================================================
--- trunk/web/css/graphic.css 2008-09-26 17:36:50 UTC (rev 1392)
+++ trunk/web/css/graphic.css 2008-09-28 18:32:00 UTC (rev 1393)
@@ -135,6 +135,7 @@
color: #000000;
border-top: 2px solid #999999;
border-bottom: 2px solid #999999;
+font-size: 14px;
}
h2
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---