Safer Countable implementation, but requires one more query per list.
authorJan Schneider <jan@horde.org>
Sun, 30 Aug 2009 10:25:46 +0000 (12:25 +0200)
committerJan Schneider <jan@horde.org>
Sun, 30 Aug 2009 10:25:46 +0000 (12:25 +0200)
framework/Rdo/lib/Horde/Rdo/List.php

index 212878e..013cf76 100644 (file)
@@ -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;
+    }
+
 }