[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/addon/propel/ -> sfPropelPager.class.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the symfony package.
   5   * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   * 
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * @package    symfony
  13   * @subpackage addon
  14   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  15   * @version    SVN: $Id: sfPropelPager.class.php 2728 2006-11-17 09:46:01Z chtito $
  16   */
  17  
  18  /**
  19   *
  20   * sfPropelPager class.
  21   *
  22   * @package    symfony
  23   * @subpackage addon
  24   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  25   * @version    SVN: $Id: sfPropelPager.class.php 2728 2006-11-17 09:46:01Z chtito $
  26   */
  27  class sfPropelPager extends sfPager
  28  {
  29    protected
  30      $criteria               = null,
  31      $peer_method_name       = 'doSelect',
  32      $peer_count_method_name = 'doCount';
  33  
  34    public function __construct($class, $maxPerPage = 10)
  35    {
  36      parent::__construct($class, $maxPerPage);
  37  
  38      $this->setCriteria(new Criteria());
  39      $this->tableName = constant($class.'Peer::TABLE_NAME');
  40    }
  41    
  42    public function init()
  43    {
  44      $hasMaxRecordLimit = ($this->getMaxRecordLimit() !== false);
  45      $maxRecordLimit = $this->getMaxRecordLimit();
  46  
  47      $cForCount = clone $this->getCriteria();
  48      $cForCount->setOffset(0);
  49      $cForCount->setLimit(0);
  50      $cForCount->clearGroupByColumns();
  51  
  52      // require the model class (because autoloading can crash under some conditions)
  53      if (!$classPath = sfCore::getClassPath($this->getClassPeer()))
  54      {
  55        throw new sfException(sprintf('Unable to find path for class "%s".', $this->getClassPeer()));
  56      }
  57      require_once($classPath);
  58      $count = call_user_func(array($this->getClassPeer(), $this->getPeerCountMethod()), $cForCount);
  59  
  60      $this->setNbResults($hasMaxRecordLimit ? min($count, $maxRecordLimit) : $count);
  61  
  62      $c = $this->getCriteria();
  63      $c->setOffset(0);
  64      $c->setLimit(0);
  65  
  66      if (($this->getPage() == 0 || $this->getMaxPerPage() == 0))
  67      {
  68        $this->setLastPage(0);
  69      }
  70      else
  71      {
  72        $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage()));
  73  
  74        $offset = ($this->getPage() - 1) * $this->getMaxPerPage();
  75        $c->setOffset($offset);
  76  
  77        if ($hasMaxRecordLimit)
  78        {
  79          $maxRecordLimit = $maxRecordLimit - $offset;
  80          if ($maxRecordLimit > $this->getMaxPerPage())
  81          {
  82            $c->setLimit($this->getMaxPerPage());
  83          }
  84          else
  85          {
  86            $c->setLimit($maxRecordLimit);
  87          }
  88        }
  89        else
  90        {
  91          $c->setLimit($this->getMaxPerPage());
  92        }
  93      }
  94    }
  95  
  96    protected function retrieveObject($offset)
  97    {
  98      $cForRetrieve = clone $this->getCriteria();
  99      $cForRetrieve->setOffset($offset - 1);
 100      $cForRetrieve->setLimit(1);
 101  
 102      $results = call_user_func(array($this->getClassPeer(), $this->getPeerMethod()), $cForRetrieve);
 103  
 104      return $results[0];
 105    }
 106  
 107    public function getResults()
 108    {
 109      $c = $this->getCriteria();
 110  
 111      return call_user_func(array($this->getClassPeer(), $this->getPeerMethod()), $c);
 112    }
 113  
 114    public function getPeerMethod()
 115    {
 116      return $this->peer_method_name;
 117    }
 118  
 119    public function setPeerMethod($peer_method_name)
 120    {
 121      $this->peer_method_name = $peer_method_name;
 122    }
 123  
 124    public function getPeerCountMethod()
 125    {
 126      return $this->peer_count_method_name;
 127    }
 128  
 129    public function setPeerCountMethod($peer_count_method_name)
 130    {
 131      $this->peer_count_method_name = $peer_count_method_name;
 132    }
 133    
 134    public function getClassPeer()
 135    {
 136      return $this->class.'Peer';
 137    }
 138  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7