From 53264e2c2bf2402cdb4a6df7cf4dc485a324feca Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 30 May 2009 06:58:48 +0000 Subject: [PATCH] "new static method to get an attribute of a column, eg. the comment" --- phpgwapi/inc/class.egw_db.inc.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/phpgwapi/inc/class.egw_db.inc.php b/phpgwapi/inc/class.egw_db.inc.php index 32ac272a50..d32daf7d4b 100644 --- a/phpgwapi/inc/class.egw_db.inc.php +++ b/phpgwapi/inc/class.egw_db.inc.php @@ -1581,6 +1581,32 @@ class egw_db return $table ? $this->app_data['table_defs'][$table] : $this->app_data['table_defs']; } + /** + * Get specified attribute (default comment) of a colum or whole definition (if $attribute === null) + * + * Can be used static, in which case the global db object is used ($GLOBALS['egw']->db) and $app should be specified + * + * @param string $column name of column + * @param string $table name of table + * @param string $app=null app name or NULL to use $this->app, set via egw_db::set_app() + * @param string $attribute='comment' what field to return, NULL for array with all fields, default 'comment' to return the comment + * @return string|array NULL if table or column or attribute not found + */ + /* static */ function get_column_attribute($column,$table,$app=null,$attribute='comment') + { + static $cached_columns,$cached_table; // some caching + + if ($cached_table !== $table || is_null($cached_columns)) + { + $db = isset($this) ? $this : $GLOBALS['egw']->db; + $table_def = $db->get_table_definitions($app,$table); + $cached_columns = is_array($table_def) ? $table_def['fd'] : false; + } + if ($cached_columns === false) return null; + + return is_null($attribute) ? $cached_columns[$column] : $cached_columns[$column][$attribute]; + } + /** * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type *