Permalink
Browse files

Change: Pagination.

  • Loading branch information...
1 parent f5973e4 commit 46d0e1e96793f843ed0024014adce3b3f37b698d @yuya-takeyama committed Sep 18, 2011
@@ -5,3 +5,4 @@
all:
app_active_days: 30
max_jobs_on_homepage: 10
+ max_jobs_on_category: 20
@@ -18,5 +18,13 @@ class categoryActions extends sfActions
public function executeShow(sfWebRequest $request)
{
$this->category = $this->getRoute()->getObject();
+
+ $this->pager = new sfDoctrinePager(
+ 'JobeetJob',
+ sfConfig::get('app_max_jobs_on_category')
+ );
+ $this->pager->setQuery($this->category->getActiveJobsQuery());
+ $this->pager->setPage($request->getParameter('page', 1));
+ $this->pager->init();
}
}
@@ -9,8 +9,40 @@
<h1><?php echo $category ?></h1>
</div>
-<?php
-include_partial('job/list', array(
- 'jobs' => $category->getActiveJobs()
-))
-?>
+<?php include_partial('job/list', array('jobs' => $pager->getResults())) ?>
+
+<?php if ($pager->haveToPaginate()): ?>
+ <div class="pagination">
+ <a href="<?php echo url_for('category', $category) ?>?page=1">
+ <img src="/images/first.png" alt="First page" title="First page" />
+ </a>
+
+ <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $pager->getPreviousPage() ?>">
+ <img src="/images/previous.png" alt="Previous page" title="Previous page" />
+ </a>
+
+ <?php foreach ($pager->getLinks() as $page): ?>
+ <?php if ($page == $pager->getPage()): ?>
+ <?php echo $page ?>
+ <?php else: ?>
+ <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $page ?>"><?php echo $page ?></a>
+ <?php endif; ?>
+ <? endforeach; ?>
+
+ <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $page ?>">
+ <img src="/images/next.png" alt="Next page" title="Next page" />
+ </a>
+
+ <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $pager->getLastPage() ?>">
+ <img src="/images/last.png" alt="Last page" title="Last page" />
+ </a>
+ </div>
+<?php endif; ?>
+
+<div class="pagination_desc">
+ <strong><?php echo count($pager) ?></strong> jobs in this category
+
+ <?php if ($pager->haveToPaginate()): ?>
+ - page <strong><?php echo $pager->getPage() ?>/<?php echo $pager->getLastPage() ?></strong>
+ <?php endif; ?>
+</div>
@@ -12,21 +12,23 @@
*/
class JobeetCategory extends BaseJobeetCategory
{
- public function getActiveJobs($max = 10)
+ public function getActiveJobsQuery()
{
$q = Doctrine_Query::create()
->from('JobeetJob j')
- ->where('j.category_id = ?', $this->getId())
- ->limit($max);
+ ->where('j.category_id = ?', $this->getId());
- return Doctrine_Core::getTable('JobeetJob')->getActiveJobs($q);
+ return Doctrine_Core::getTable('JobeetJob')->addActiveJobsQuery($q);
+ }
+
+ public function getActiveJobs($max = 10)
+ {
+ $q = $this->getActiveJobsQuery()->limit($max);
+ return $q->execute();
}
public function countActiveJobs()
{
- $q = Doctrine_Query::create()
- ->from('JobeetJob j')
- ->where('j.category_id = ?', $this->getId());
- return Doctrine_Core::getTable('JobeetJob')->countActiveJobs($q);
+ return $this->getActiveJobsQuery()->count();
}
}

0 comments on commit 46d0e1e

Please sign in to comment.