Skip to content

Commit

Permalink
Fixing the bug where tags and author filters didn't persist through p…
Browse files Browse the repository at this point in the history
…agination.
  • Loading branch information
weaverryan committed Dec 11, 2010
1 parent d5bdb9f commit df12bb0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
13 changes: 11 additions & 2 deletions modules/ioBlog/lib/BaseioBlogActions.class.php
Expand Up @@ -54,20 +54,29 @@ protected function setupQueryFromRequest(sfWebRequest $request)
}
$q = $tbl->addRecentOrderBy($q);

$this->filterQueryParams = array();
$this->pagerRoute = 'io_blog_index';

// process a tag parameter if present
if ($request->getParameter('tag'))
if ($tag = $request->getParameter('tag'))
{
Doctrine_Core::getTable('Tag')->getObjectTaggedWithQuery(
'ioBlog',
$request->getParameter('tag'),
$tag,
$q
);

$this->filterQueryParams['tag'] = $tag;
$this->pagerRoute = 'io_blog_index_tag';
}
elseif ($author = $request->getParameter('author'))
{
$user = Doctrine_Core::getTable('sfGuardUser')->findOneByUsername($author);
$this->forward404Unless($user);
$q = $tbl->addAuthorQuery($user, $q);

$this->filterQueryParams['author'] = $author;
$this->pagerRoute = 'io_blog_index_author';
}

$q = $tbl->addAuthorJoinQuery($q);
Expand Down
19 changes: 6 additions & 13 deletions modules/ioBlog/templates/_pagerNavigation.php
@@ -1,29 +1,22 @@
<?php $params = unescape_variable($params) ?>
<?php $webRoot = sfConfig::get('app_io_blog_web_dir', '/ioBlogPlugin') ?>

<?php if ($pager->haveToPaginate()): ?>
<div class="pagination">
<a href="<?php echo url_for('io_blog_index', array('page' => 1)) ?>">
<?php echo image_tag($webRoot.'/images/pager/first.png', array('alt' => 'First page')) ?>
</a>
<a href="<?php echo url_for($route, array_merge($params, array('page' => 1))) ?>"><?php echo image_tag($webRoot.'/images/pager/first.png', array('alt' => 'First page')) ?></a>

<a href="<?php echo url_for('io_blog_index', array('page' => $pager->getPreviousPage())) ?>">
<?php echo image_tag($webRoot.'/images/pager/previous.png', array('alt' => 'Previous page')) ?>
</a>
<a href="<?php echo url_for($route, array_merge($params, array('page' => $pager->getPreviousPage()))) ?>"><?php echo image_tag($webRoot.'/images/pager/previous.png', array('alt' => 'Previous page')) ?></a>

<?php foreach ($pager->getLinks() as $page): ?>
<?php if ($page == $pager->getPage()): ?>
<b><?php echo $page ?></b>
<?php else: ?>
<a href="<?php echo url_for('io_blog_index', array('page' => $page)) ?>"><?php echo $page ?></a>
<a href="<?php echo url_for($route, array_merge($params, array('page' => $page))) ?>"><?php echo $page ?></a>
<?php endif; ?>
<?php endforeach; ?>

<a href="<?php echo url_for('io_blog_index', array('page' => $pager->getNextPage())) ?>">
<?php echo image_tag($webRoot.'/images/pager/next.png', array('alt' => 'Next page')) ?>
</a>
<a href="<?php echo url_for($route, array_merge($params, array('page' => $pager->getNextPage()))) ?>"><?php echo image_tag($webRoot.'/images/pager/next.png', array('alt' => 'Next page')) ?></a>

<a href="<?php echo url_for('io_blog_index', array('page' => $pager->getLastPage())) ?>">
<?php echo image_tag($webRoot.'/images/pager/last.png', array('alt' => 'Last page')) ?>
</a>
<a href="<?php echo url_for($route, array_merge($filterQueryParams, array('page' => $pager->getLastPage()))) ?>"><?php echo image_tag($webRoot.'/images/pager/last.png', array('alt' => 'Last page')) ?></a>
</div>
<?php endif; ?>
12 changes: 10 additions & 2 deletions modules/ioBlog/templates/indexSuccess.php
Expand Up @@ -2,7 +2,11 @@

<h1><?php echo $title ?></h1>

<?php include_partial('ioBlog/pagerNavigation', array('pager' => $pager)) ?>
<?php include_partial('ioBlog/pagerNavigation', array(
'pager' => $pager,
'route' => $pagerRoute,
'params' => $filterQueryParams,
)) ?>

<?php if ($pager->getNbResults() > 0): ?>

Expand All @@ -23,4 +27,8 @@
<?php endif; ?>
<?php endif; ?>

<?php include_partial('ioBlog/pagerNavigation', array('pager' => $pager)) ?>
<?php include_partial('ioBlog/pagerNavigation', array(
'pager' => $pager,
'route' => $pagerRoute,
'params' => $filterQueryParams,
)) ?>

0 comments on commit df12bb0

Please sign in to comment.