From f9306660750871faf8a404f6c5d92d81ca438947 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Sun, 30 Aug 2009 12:25:46 +0200 Subject: [PATCH] Safer Countable implementation, but requires one more query per list. --- framework/Rdo/lib/Horde/Rdo/List.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/framework/Rdo/lib/Horde/Rdo/List.php b/framework/Rdo/lib/Horde/Rdo/List.php index 212878ee1..013cf76e8 100644 --- a/framework/Rdo/lib/Horde/Rdo/List.php +++ b/framework/Rdo/lib/Horde/Rdo/List.php @@ -12,7 +12,7 @@ * @category Horde * @package Horde_Rdo */ -class Horde_Rdo_List implements Iterator +class Horde_Rdo_List implements Iterator, Countable { /** * Rdo Mapper @@ -57,6 +57,12 @@ class Horde_Rdo_List implements Iterator protected $_eof; /** + * The number of objects in the list. + * @var integer + */ + protected $_count; + + /** * Constructor. * * @param mixed $query The query to run when results are @@ -91,6 +97,8 @@ class Horde_Rdo_List implements Iterator // Keep a handle on the Mapper object for running the query. $this->_mapper = $mapper; + + $this->_count = $this->_mapper->count($query); } /** @@ -190,4 +198,9 @@ class Horde_Rdo_List implements Iterator return !$this->_eof; } + public function count() + { + return $this->_count; + } + } -- 2.11.0