Author: Kris.Wallsmith
Date: 2010-02-08 19:02:19 +0100 (Mon, 08 Feb 2010)
New Revision: 27747
Modified:
branches/1.3/lib/addon/sfPager.class.php
branches/1.3/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
branches/1.3/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
branches/1.3/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
branches/1.4/lib/addon/sfPager.class.php
branches/1.4/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
branches/1.4/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
branches/1.4/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
Log:
[1.3, 1.4] fixed doctrine pager iteration (closes #7758, refs #8021)
Modified: branches/1.3/lib/addon/sfPager.class.php
===================================================================
--- branches/1.3/lib/addon/sfPager.class.php 2010-02-08 17:13:41 UTC (rev
27746)
+++ branches/1.3/lib/addon/sfPager.class.php 2010-02-08 18:02:19 UTC (rev
27747)
@@ -31,6 +31,8 @@
$currentMaxLink = 1,
$parameterHolder = null,
$maxRecordLimit = false,
+
+ // used by iterator interface
$results = null,
$resultsCounter = 0;
@@ -493,23 +495,45 @@
$this->parameterHolder->set($name, $value);
}
- protected function initResultsIfRequired()
+ /**
+ * Returns true if the properties used for iteration have been initialized.
+ *
+ * @return boolean
+ */
+ protected function isIteratorInitialized()
{
- if (null === $this->results)
- {
- $this->results = $this->getResults();
- $this->resultsCounter = count($this->results);
- }
+ return null !== $this->results;
}
/**
+ * Loads data into properties used for iteration.
+ */
+ protected function initializeIterator()
+ {
+ $this->results = $this->getResults();
+ $this->resultsCounter = count($this->results);
+ }
+
+ /**
+ * Empties properties used for iteration.
+ */
+ protected function resetIterator()
+ {
+ $this->results = null;
+ $this->resultsCounter = 0;
+ }
+
+ /**
* Returns the current result.
*
* @see Iterator
*/
public function current()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
return current($this->results);
}
@@ -521,7 +545,10 @@
*/
public function key()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
return key($this->results);
}
@@ -533,7 +560,10 @@
*/
public function next()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
--$this->resultsCounter;
@@ -547,7 +577,10 @@
*/
public function rewind()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
$this->resultsCounter = count($this->results);
@@ -561,7 +594,10 @@
*/
public function valid()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
return $this->resultsCounter > 0;
}
Modified:
branches/1.3/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
===================================================================
---
branches/1.3/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
2010-02-08 17:13:41 UTC (rev 27746)
+++
branches/1.3/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
2010-02-08 18:02:19 UTC (rev 27747)
@@ -93,7 +93,7 @@
*/
public function init()
{
- $this->results = null;
+ $this->resetIterator();
$countQuery = $this->getCountQuery();
$count = $countQuery->count();
@@ -185,4 +185,17 @@
{
return $this->getQuery()->execute(array(), $hydrationMode);
}
+
+ /**
+ * @see sfPager
+ */
+ protected function initializeIterator()
+ {
+ parent::initializeIterator();
+
+ if ($this->results instanceof Doctrine_Collection)
+ {
+ $this->results = $this->results->getData();
+ }
+ }
}
Modified:
branches/1.3/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
===================================================================
--- branches/1.3/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
2010-02-08 17:13:41 UTC (rev 27746)
+++ branches/1.3/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
2010-02-08 18:02:19 UTC (rev 27747)
@@ -11,7 +11,7 @@
$app = 'frontend';
require_once(dirname(__FILE__).'/../bootstrap/functional.php');
-$t = new lime_test(13);
+$t = new lime_test(23);
$total = 50;
for ($i = 0; $i < $total; $i++)
@@ -62,10 +62,19 @@
$t->is($pager->getQuery()->getSqlQuery(), 'SELECT a.id AS a__id, a.name AS
a__name, a.type AS a__type FROM author a WHERE (a.id < 9999999 AND a.id > 0)
LIMIT 25');
-
$pager = new sfDoctrinePager('Author', $numPerPage);
$pager->setQuery(Doctrine_Query::create()->from('Author a')->where('a.id <
9999999'));
$pager->setPage(1);
$pager->init();
$t->is($pager->getQuery()->getSqlQuery(), 'SELECT a.id AS a__id, a.name AS
a__name, a.type AS a__type FROM author a WHERE (a.id < 9999999) LIMIT 25');
+
+// pager interface
+$t->diag('iterator interface');
+
+$pager = new sfDoctrinePager('Author', 10);
+$pager->init();
+foreach ($pager as $author)
+{
+ $t->isa_ok($author, 'Author');
+}
Modified:
branches/1.3/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
===================================================================
--- branches/1.3/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
2010-02-08 17:13:41 UTC (rev 27746)
+++ branches/1.3/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
2010-02-08 18:02:19 UTC (rev 27747)
@@ -42,7 +42,7 @@
*/
public function init()
{
- $this->results = null;
+ $this->resetIterator();
$hasMaxRecordLimit = ($this->getMaxRecordLimit() !== false);
$maxRecordLimit = $this->getMaxRecordLimit();
Modified: branches/1.4/lib/addon/sfPager.class.php
===================================================================
--- branches/1.4/lib/addon/sfPager.class.php 2010-02-08 17:13:41 UTC (rev
27746)
+++ branches/1.4/lib/addon/sfPager.class.php 2010-02-08 18:02:19 UTC (rev
27747)
@@ -31,6 +31,8 @@
$currentMaxLink = 1,
$parameterHolder = null,
$maxRecordLimit = false,
+
+ // used by iterator interface
$results = null,
$resultsCounter = 0;
@@ -493,23 +495,45 @@
$this->parameterHolder->set($name, $value);
}
- protected function initResultsIfRequired()
+ /**
+ * Returns true if the properties used for iteration have been initialized.
+ *
+ * @return boolean
+ */
+ protected function isIteratorInitialized()
{
- if (null === $this->results)
- {
- $this->results = $this->getResults();
- $this->resultsCounter = count($this->results);
- }
+ return null !== $this->results;
}
/**
+ * Loads data into properties used for iteration.
+ */
+ protected function initializeIterator()
+ {
+ $this->results = $this->getResults();
+ $this->resultsCounter = count($this->results);
+ }
+
+ /**
+ * Empties properties used for iteration.
+ */
+ protected function resetIterator()
+ {
+ $this->results = null;
+ $this->resultsCounter = 0;
+ }
+
+ /**
* Returns the current result.
*
* @see Iterator
*/
public function current()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
return current($this->results);
}
@@ -521,7 +545,10 @@
*/
public function key()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
return key($this->results);
}
@@ -533,7 +560,10 @@
*/
public function next()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
--$this->resultsCounter;
@@ -547,7 +577,10 @@
*/
public function rewind()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
$this->resultsCounter = count($this->results);
@@ -561,7 +594,10 @@
*/
public function valid()
{
- $this->initResultsIfRequired();
+ if (!$this->isIteratorInitialized())
+ {
+ $this->initializeIterator();
+ }
return $this->resultsCounter > 0;
}
Modified:
branches/1.4/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
===================================================================
---
branches/1.4/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
2010-02-08 17:13:41 UTC (rev 27746)
+++
branches/1.4/lib/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php
2010-02-08 18:02:19 UTC (rev 27747)
@@ -93,7 +93,7 @@
*/
public function init()
{
- $this->results = null;
+ $this->resetIterator();
$countQuery = $this->getCountQuery();
$count = $countQuery->count();
@@ -185,4 +185,17 @@
{
return $this->getQuery()->execute(array(), $hydrationMode);
}
+
+ /**
+ * @see sfPager
+ */
+ protected function initializeIterator()
+ {
+ parent::initializeIterator();
+
+ if ($this->results instanceof Doctrine_Collection)
+ {
+ $this->results = $this->results->getData();
+ }
+ }
}
Modified:
branches/1.4/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
===================================================================
--- branches/1.4/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
2010-02-08 17:13:41 UTC (rev 27746)
+++ branches/1.4/lib/plugins/sfDoctrinePlugin/test/functional/PagerTest.php
2010-02-08 18:02:19 UTC (rev 27747)
@@ -11,7 +11,7 @@
$app = 'frontend';
require_once(dirname(__FILE__).'/../bootstrap/functional.php');
-$t = new lime_test(13);
+$t = new lime_test(23);
$total = 50;
for ($i = 0; $i < $total; $i++)
@@ -62,10 +62,19 @@
$t->is($pager->getQuery()->getSqlQuery(), 'SELECT a.id AS a__id, a.name AS
a__name, a.type AS a__type FROM author a WHERE (a.id < 9999999 AND a.id > 0)
LIMIT 25');
-
$pager = new sfDoctrinePager('Author', $numPerPage);
$pager->setQuery(Doctrine_Query::create()->from('Author a')->where('a.id <
9999999'));
$pager->setPage(1);
$pager->init();
$t->is($pager->getQuery()->getSqlQuery(), 'SELECT a.id AS a__id, a.name AS
a__name, a.type AS a__type FROM author a WHERE (a.id < 9999999) LIMIT 25');
+
+// pager interface
+$t->diag('iterator interface');
+
+$pager = new sfDoctrinePager('Author', 10);
+$pager->init();
+foreach ($pager as $author)
+{
+ $t->isa_ok($author, 'Author');
+}
Modified:
branches/1.4/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
===================================================================
--- branches/1.4/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
2010-02-08 17:13:41 UTC (rev 27746)
+++ branches/1.4/lib/plugins/sfPropelPlugin/lib/addon/sfPropelPager.class.php
2010-02-08 18:02:19 UTC (rev 27747)
@@ -42,7 +42,7 @@
*/
public function init()
{
- $this->results = null;
+ $this->resetIterator();
$hasMaxRecordLimit = ($this->getMaxRecordLimit() !== false);
$maxRecordLimit = $this->getMaxRecordLimit();
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.