DoctrineQuery.php

Go to the documentation of this file.
00001 <?php
00002 
00033 class Robo47_Paginator_Adapter_DoctrineQuery
00034 implements Zend_Paginator_Adapter_Interface
00035 {
00036 
00040     protected $_query;
00041 
00046     public function __construct(Doctrine_Query $query)
00047     {
00048         $this->setQuery($query);
00049     }
00050 
00056     public function setQuery(Doctrine_Query $query)
00057     {
00058         $this->_query = $query;
00059         return $this;
00060     }
00061 
00066     public function getQuery()
00067     {
00068         return $this->_query;
00069     }
00070 
00078     public function count()
00079     {
00080         return $this->_query->count();
00081     }
00082 
00090     public function getItems($offset, $itemCountPerPage)
00091     {
00092         $data = $this->_query
00093             ->limit($itemCountPerPage)
00094             ->offset($offset)
00095             ->execute();
00096         if ($data instanceof Doctrine_Collection) {
00097             return $data->getData();
00098         } elseif(is_array($data)) {
00099             return $data;
00100         } else {
00101             $message = 'Unexpected datatype for getItems(): ' .
00102                 Robo47_Core::getType($data);
00103             throw new Robo47_Paginator_Adapter_Exception($message);
00104         }
00105     }
00106 }