Author: Vance Lucas (vance@vancelucas.com)
Inheritance: implements Countable, implements IteratorAggregate
Example #1
0
 /**
  *
  */
 public function __construct(phpDataMapper_Query $query, $page = 1, $itemsPerPage = 30)
 {
     $this->_mapper = $query->mapper();
     $this->_query = $query;
     $this->page($page);
     $this->perPage($itemsPerPage);
 }
Example #2
0
 /**
  * Return result set for current query
  */
 public function toCollection(phpDataMapper_Query $query, $stmt)
 {
     $mapper = $query->mapper();
     if ($stmt instanceof PDOStatement) {
         $results = array();
         // Set object to fetch results into
         $stmt->setFetchMode(PDO::FETCH_CLASS, $mapper->entityClass());
         // Fetch all results into new DataMapper_Result class
         while ($row = $stmt->fetch(PDO::FETCH_CLASS)) {
             $row->setIsNew(false);
             // Load relations for this row
             $relations = $mapper->getRelationsFor($row);
             if ($relations && is_array($relations) && count($relations) > 0) {
                 foreach ($relations as $relationCol => $relationObj) {
                     $row->{$relationCol} = $relationObj;
                 }
             }
             // Store in array for ResultSet
             $results[] = $row;
             // Mark row as loaded
             $row->loaded(true);
         }
         // Ensure set is closed
         $stmt->closeCursor();
         $collectionClass = $mapper->collectionClass();
         return new $collectionClass($results);
     } else {
         $mapper->addError(__METHOD__ . " - Unable to execute query " . implode(' | ', $this->adapterRead()->errorInfo()));
         return array();
     }
 }