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
20 protected static $_classCache = array(
21 'getTableDescriptionFromCache' => array()
25 * wrapper around Zend_Db_Table_Abstract::fetchAll
27 * @param strin|array $_where OPTIONAL
28 * @param string $_order OPTIONAL
29 * @param string $_dir OPTIONAL
30 * @param int $_count OPTIONAL
31 * @param int $_offset OPTIONAL
32 * @throws Tinebase_Exception_InvalidArgument if $_dir is not ASC or DESC
33 * @return the row results per the Zend_Db_Adapter fetch mode.
35 public function fetchAll($_where = NULL, $_order = NULL, $_dir = 'ASC', $_count = NULL, $_offset = NULL)
37 if($_dir != 'ASC' && $_dir != 'DESC') {
38 throw new Tinebase_Exception_InvalidArgument('$_dir can be only ASC or DESC');
42 if($_order !== NULL) {
43 $order = $_order . ' ' . $_dir;
46 $rowSet = parent::fetchAll($_where, $order, $_count, $_offset);
52 * get total count of rows
54 * @param string|array|Zend_Db_Select $_where
56 public function getTotalCount($_where)
58 $tableInfo = $this->info();
60 if (is_array($_where) || is_string($_where)) {
61 $select = $this->getAdapter()->select();
62 foreach((array)$_where as $where) {
63 $select->where($where);
65 } elseif ($_where instanceof Zend_Db_Select ) {
69 $select->from($tableInfo['name'], array('count' => 'COUNT(*)'));
71 $stmt = $this->getAdapter()->query($select);
72 $result = $stmt->fetch(Zend_Db::FETCH_ASSOC);
74 return $result['count'];
78 * get describe table from metadata cache
80 * @param string $tableName
81 * @param Zend_Db_Adapter_Abstract $db
84 public static function getTableDescriptionFromCache($tableName, $db = NULL)
87 $db = Tinebase_Core::getDb();
90 $cache = Tinebase_Core::getCache();
91 $dbConfig = $db->getConfig();
93 $classCacheId = md5($dbConfig['host'] . $dbConfig['dbname'] . $tableName);
95 if (isset(self::$_classCache[__FUNCTION__][$classCacheId])) {
96 return self::$_classCache[__FUNCTION__][$classCacheId];
99 $cacheId = __FUNCTION__ . $classCacheId;
101 #if ($result = apc_fetch($cacheId)) {
102 # self::$_classCache[__FUNCTION__][$classCacheId] = $result;
107 $result = $cache->load($cacheId);
110 $result = $db->describeTable($tableName);
112 $cache->save($result, $cacheId);
113 #apc_store($cacheId, $result, 60);
114 self::$_classCache[__FUNCTION__][$classCacheId] = $result;