Changeset 14108
- Timestamp:
- 12/17/08 01:23:27 (1 year ago)
- Files:
-
- branches/1.2/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/parts/configuration.php (modified) (1 diff)
- branches/1.2/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/parts/paginationAction.php (modified) (1 diff)
- branches/1.2/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/parts/configuration.php
r13291 r14108 60 60 <?php include dirname(__FILE__).'/sortingConfiguration.php' ?> 61 61 62 public function getTableMethod() 63 { 64 return '<?php echo isset($this->config['list']['table_method']) ? $this->config['list']['table_method'] : null ?>'; 65 <?php unset($this->config['list']['table_method']) ?> 66 } 67 68 public function getTableCountMethod() 69 { 70 return '<?php echo isset($this->config['list']['table_count_method']) ? $this->config['list']['table_count_method'] : null ?>'; 71 <?php unset($this->config['list']['table_count_method']) ?> 72 } 73 62 74 public function getConnection() 63 75 { branches/1.2/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/parts/paginationAction.php
r12669 r14108 4 4 $pager->setQuery($this->buildQuery()); 5 5 $pager->setPage($this->getPage()); 6 $pager->setTableMethod($this->configuration->getTableMethod()); 7 $pager->setTableCountMethod($this->configuration->getTableCountMethod()); 6 8 $pager->init(); 7 9 branches/1.2/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
r13394 r14108 19 19 class sfDoctrinePager extends sfPager implements Serializable 20 20 { 21 protected $query; 22 23 /** 24 * __construct 25 * 26 * @return void 27 */ 28 public function __construct($class, $defaultMaxPerPage = 10) 29 { 30 parent::__construct($class, $defaultMaxPerPage); 31 32 $this->setQuery(Doctrine_Query::create()->from($class)); 21 protected 22 $query = null, 23 $tableMethodName = null, 24 $tableCountMethodName = null; 25 26 /** 27 * Get the name of the table method used to retrieve the query object for the pager 28 * 29 * @return string $tableMethodName 30 */ 31 public function getTableMethod() 32 { 33 return $this->tableMethodName; 34 } 35 36 /** 37 * Set the name of the table method used to retrieve the query object for the pager 38 * 39 * @param string $tableMethodName 40 * @return void 41 */ 42 public function setTableMethod($tableMethodName) 43 { 44 $this->tableMethodName = $tableMethodName; 45 } 46 47 /** 48 * Get the name of the table method used to retrieve the query object for the pager count 49 * 50 * @return string $tableCountMethodName 51 */ 52 public function getTableCountMethod() 53 { 54 return $this->tableCountMethodName; 55 } 56 57 /** 58 * Set the name of the table method used to retrieve the query object for the pager count 59 * 60 * @param string $tableCountMethodName 61 * @return void 62 */ 63 public function setTableCountMethod($tableCountMethodName) 64 { 65 $this->tableCountMethodName = $tableCountMethodName; 33 66 } 34 67 … … 61 94 } 62 95 96 public function getCountQuery() 97 { 98 if (!$this->tableCountMethodName) 99 { 100 $q = clone $this->getQuery() 101 ->offset(0) 102 ->limit(0); 103 104 return $q; 105 } else { 106 $method = $this->tableCountMethodName; 107 return Doctrine::getTable($this->getClass())->$method(); 108 } 109 } 110 63 111 /** 64 112 * Initialize the pager instance and prepare it to be used for rendering … … 68 116 public function init() 69 117 { 70 $count = $this->getQuery()->offset(0)->limit(0)->count(); 118 $countQuery = $this->getCountQuery(); 119 $count = $countQuery->count(); 71 120 72 121 $this->setNbResults($count); … … 97 146 public function getQuery() 98 147 { 99 return $this->query; 148 if (!$this->tableMethodName) 149 { 150 if (!$this->query) 151 { 152 $this->query = Doctrine_Query::create()->from($this->getClass()); 153 } 154 155 return $this->query; 156 } else { 157 $method = $this->tableMethodName; 158 return Doctrine::getTable($this->getClass())->$method(); 159 } 100 160 } 101 161

