7 * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
8 * @copyright Copyright (c) 2007-2008 Metaways Infosystems GmbH (http://www.metaways.de)
9 * @author Lars Kneschke <l.kneschke@metaways.de>
13 * the class provides functions to handle applications
18 class Tinebase_Db_Table extends Zend_Db_Table_Abstract
21 * wrapper around Zend_Db_Table_Abstract::fetchAll
23 * @param strin|array $_where OPTIONAL
24 * @param string $_order OPTIONAL
25 * @param string $_dir OPTIONAL
26 * @param int $_count OPTIONAL
27 * @param int $_offset OPTIONAL
28 * @throws Tinebase_Exception_InvalidArgument if $_dir is not ASC or DESC
29 * @return the row results per the Zend_Db_Adapter fetch mode.
31 public function fetchAll($_where = NULL, $_order = NULL, $_dir = 'ASC', $_count = NULL, $_offset = NULL)
33 if($_dir != 'ASC' && $_dir != 'DESC') {
34 throw new Tinebase_Exception_InvalidArgument('$_dir can be only ASC or DESC');
38 if($_order !== NULL) {
39 $order = $_order . ' ' . $_dir;
42 $rowSet = parent::fetchAll($_where, $order, $_count, $_offset);
48 * get total count of rows
50 * @param string|array|Zend_Db_Select $_where
52 public function getTotalCount($_where)
54 $tableInfo = $this->info();
56 if (is_array($_where) || is_string($_where)) {
57 $select = $this->getAdapter()->select();
58 foreach((array)$_where as $where) {
59 $select->where($where);
61 } elseif ($_where instanceof Zend_Db_Select ) {
65 $select->from($tableInfo['name'], array('count' => 'COUNT(*)'));
67 $stmt = $this->getAdapter()->query($select);
68 $result = $stmt->fetch(Zend_Db::FETCH_ASSOC);
70 return $result['count'];
74 * get describe table from metadata cache
76 * @param string $tableName
77 * @param Zend_Db_Adapter_Abstract $db
80 public static function getTableDescriptionFromCache($tableName, $db = NULL)
83 $db = Tinebase_Core::getDb();
90 $tableDescription = new Tinebase_Db_Table($config);
91 $tableInfo = $tableDescription->info();
92 $result = $tableInfo['metadata'];
93 } catch (Zend_Db_Table_Exception $zdte) {
94 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
95 . ' Could not fetch schema from cache: ' . $zdte->getMessage());
96 $result = $db->describeTable($tableName);