Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

добавил пагинацию для списка проектов

  • Loading branch information...
commit 2426f392fa7af594ac1af1a0c84eeb42c87e0890 1 parent 39bb9fe
@FladeX authored
View
10 apps/frontend/modules/projects/actions/actions.class.php
@@ -12,7 +12,15 @@ class projectsActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
- $this->projects = Doctrine_Core::getTable('projects')->getActiveProjects(sfConfig::get('app_projects_per_page'));
+ $this->projects = Doctrine_Core::getTable('projects')->getActiveProjects();
+
+ $this->pager = new sfDoctrinePager(
+ 'projects',
+ sfConfig::get('app_projects_per_page')
+ );
+ //$this->pager->setQuery($this->projects->getActiveProjectsQuery());
+ $this->pager->setPage($request->getParameter('page', 1));
+ $this->pager->init();
}
public function executeShow(sfWebRequest $request)
View
39 apps/frontend/modules/projects/templates/indexSuccess.php
@@ -115,29 +115,36 @@
</ul>
</div>
- <?php include_partial('projects/list', array('projects' => $projects)) ?>
+ <?php include_partial('projects/list', array('projects' => $pager->getResults())) ?>
+ <?php if ($pager->haveToPaginate()): ?>
<div id="paging">
<div class="numbers">
- <span class="current">1</span>
- <a href="#">2</a>
- <a href="#">3</a>
- <a href="#">4</a>
- <a href="#">5</a>
- <a href="#">6</a>
- <a href="#">7</a>
- <a href="#">8</a>
- <a href="#">9</a>
- <a href="#">10</a>
- <span>...</span>
- <a href="#">25</a>
+ <?php foreach ($pager->getLinks() as $page): ?>
+ <?php if ($page == $pager->getPage()): ?>
+ <span class="current"><?php echo $page ?></span>
+ <?php else: ?>
+ <a href="<?php echo url_for('projects', $projects) ?>page=<?php echo $page ?>"><?php echo $page ?></a>
+ <?php endif; ?>
+ <?php endforeach; ?>
</div>
<div class="keys">
<div class="next">
- <a href="#">следующая</a>
+ <?php if ($pager->getPage() != $pager->getNextPage()): ?>
+ <a href="<?php echo url_for('projects', $projects) ?>page=<?php echo $pager->getNextPage() ?>">следующая</a>
+ <?php else: ?>
+ следующая
+ <?php endif; ?>
+ </div>
+ <div class="prev">
+ <?php if ($pager->getPage() != $pager->getPreviousPage()): ?>
+ <a href="<?php echo url_for('projects', $projects) ?>page=<?php echo $pager->getPreviousPage() ?>">предыдущая</a>
+ <?php else: ?>
+ предыдущая
+ <?php endif; ?>
</div>
- <div class="prev">предыдущая</div>
</div>
- </div>
+ </div><!-- #paging -->
+ <?php endif; ?>
</div><!-- #primaryContent -->
View
15 lib/model/doctrine/projects.class.php
@@ -7,9 +7,22 @@
*
* @package posting
* @subpackage model
- * @author Your name here
+ * @author Max Istlyaev
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
class projects extends Baseprojects
{
+ public function getActiveProjects($max = 10)
+ {
+ $q = $this->getActiveProjectsQuery()
+ ->limit($max);
+
+ return $q->execute();
+ }
+
+ public function countActiveProjects()
+ {
+ return $this->getActiveProjectsQuery()->count();
+ }
+
}
View
47 lib/model/doctrine/projectsTable.class.php
@@ -12,16 +12,43 @@ class projectsTable extends Doctrine_Table
*
* @return object projectsTable
*/
- public function getActiveProjects($per_page = 2)
- {
- $q = $this->createQuery('p')
- ->where('p.status <> 0')
- ->limit($per_page);
+ public function retrieveActiveProjects(Doctrine_Query $q)
+ {
+ return $this->addActiveProjectsQuery($q)->fetchOne();
+ }
+
+ public function getActiveProjects(Doctrine_Query $q = null)
+ {
+ return $this->addActiveProjectsQuery($q)->execute();
+ }
- return $q->execute();
+ public function getActiveProjectsQuery()
+ {
+ $q = Doctrine_Query::create()
+ ->from('projects p')
+ ->where('p.status <> 0', $this->getId());
+
+ return Doctrine_Core::getTable('projects')->addActiveProjectsQuery($q);
+ }
+
+ public function countActiveProjects(Doctrine_Query $q = null)
+ {
+ return $this->addActiveProjectsQuery($q)->count();
+ }
+
+ public function addActiveProjectsQuery(Doctrine_Query $q = null)
+ {
+ if (is_null($q))
+ {
+ $q = Doctrine_Query::create()
+ ->from('projects p');
}
- //public static function getInstance()
- //{
- // return Doctrine_Core::getTable('projects');
- //}
+
+ $alias = $q->getRootAlias();
+
+ $q->andWhere($alias . '.expired_at > ?', date('Y-m-d h:i:s', time()))
+ ->addOrderBy($alias . '.expired_at DESC');
+
+ return $q;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.