*/ class CemeteryList extends ZendDbResultIterator { /** * Creates a basic select statement for the collection. * * Populates the collection if you pass in $fields * Setting itemsPerPage turns on pagination mode * In pagination mode, this will only load the results for one page * * @param array $fields * @param int $itemsPerPage Turns on Pagination * @param int $currentPage */ public function __construct($fields=null,$itemsPerPage=null,$currentPage=null) { parent::__construct($itemsPerPage,$currentPage); if (is_array($fields)) { $this->find($fields); } } /** * Populates the collection * * @param array $fields * @param string|array $order Multi-column sort should be given as an array * @param int $limit * @param string|array $groupBy Multi-column group by should be given as an array */ public function find($fields=null,$order='name',$limit=null,$groupBy=null) { $this->select->from('cemeteries'); // Finding on fields from the cemeteries table is handled here if (count($fields)) { foreach ($fields as $key=>$value) { $this->select->where("$key=?",$value); } } // Finding on fields from other tables requires joining those tables. // You can handle fields from other tables by adding the joins here // If you add more joins you probably want to make sure that the // above foreach only handles fields from the cemeteries table. $this->select->order($order); if ($limit) { $this->select->limit($limit); } if ($groupBy) { $this->select->group($groupBy); } $this->populateList(); } /** * Hydrates all the Cemetery objects from a database result set * * This is a callback function, called from ZendDbResultIterator. It is * called once per row of the result. * * @param int $key The index of the result row to load * @return Cemetery */ protected function loadResult($key) { return new Cemetery($this->result[$key]); } }