Index: Abstract.php =================================================================== --- Abstract.php (revision 9574) +++ Abstract.php (working copy) @@ -1049,7 +1049,72 @@ @Zend_Loader::loadClass($this->_rowsetClass); return new $this->_rowsetClass($data); } + + /** + * Fetches all result rows as an array of key-value pairs. + * + * The first column is the key, the second column is the + * value. + * + * Honors the Zend_Db_Adapter fetch mode. + * + * @param array $columns Array of columns, this must be 2 columns. + * @param string|array|Zend_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object. + * @param string|array $order OPTIONAL An SQL ORDER clause. + * @param int $count OPTIONAL An SQL LIMIT count. + * @param int $offset OPTIONAL An SQL LIMIT offset. + * @return Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode. + */ + public function fetchPairs(array $columns, $where = null, $order = null, $count = null, $offset = null) + { + if (count($columns) != 2) { + require_once "Zend/Db/Table/Exception.php"; + throw new Zend_Db_Table_Exception("Exactly 2 columns must be provided to build key => value pairs"); + } + if (!($where instanceof Zend_Db_Table_Select)) { + $select = $this->select()->from($this, $columns); + + if ($where !== null) { + $this->_where($select, $where); + } + + if ($order !== null) { + $this->_order($select, $order); + } + + if ($count !== null || $offset !== null) { + $select->limit($count, $offset); + } + + } else { + $where->from($this, $columns); + + if ($order !== null) { + $this->_order($where, $order); + } + + if ($count !== null || $offset !== null) { + $where->limit($count, $offest); + } + + $select = $where; + } + + $rows = $this->getAdapter()->fetchPairs($select); + + $data = array( + 'table' => $this, + 'data' => $rows, + 'readOnly' => $select->isReadOnly(), + 'rowClass' => $this->_rowClass, + 'stored' => true + ); + + Zend_Loader::loadClass($this->_rowsetClass); + return new $this->_rowsetClass($data); + } + /** * Fetches one row in an object of type Zend_Db_Table_Row_Abstract, * or returns Boolean false if no row matches the specified criteria.