From 407b4defad493592010c4c66296a230a4cc5c582 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 8 Mar 2008 21:31:12 +0000 Subject: [PATCH] static strip_array_keys method to strip a colum-prefix from a result, docu update about depricated functions which use the internal result-set --- phpgwapi/inc/class.egw_db.inc.php | 45 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/phpgwapi/inc/class.egw_db.inc.php b/phpgwapi/inc/class.egw_db.inc.php index 299be2315d..91daed0882 100644 --- a/phpgwapi/inc/class.egw_db.inc.php +++ b/phpgwapi/inc/class.egw_db.inc.php @@ -183,8 +183,11 @@ class egw_db } /** - * @return int id of current query - */ + * Return the result-object of the last query + * + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone + * @return ADORecordSet + */ function query_id() { return $this->Query_ID; @@ -476,8 +479,10 @@ class egw_db } /** - * Discard the current query result - */ + * Discard the current query result + * + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone + */ function free() { unset($this->Query_ID); // else copying of the db-object does not work @@ -572,6 +577,7 @@ class egw_db * * Specifying a fetch_mode only works for newly fetched rows, the first row always gets fetched by query!!! * + * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object * @param int $fetch_mode ADODB_FETCH_BOTH = numerical+assoc keys (eGW default), ADODB_FETCH_ASSOC or ADODB_FETCH_NUM * @return bool was another row found? */ @@ -627,6 +633,7 @@ class egw_db /** * Move to position in result set * + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone * @param int $pos required row (optional), default first row * @return boolean true if sucessful or false if not found */ @@ -748,6 +755,7 @@ class egw_db /** * Number of rows in current result set * + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone * @return int number of rows */ function num_rows() @@ -758,6 +766,7 @@ class egw_db /** * Number of fields in current row * + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone * @return int number of fields */ function num_fields() @@ -813,6 +822,7 @@ class egw_db /** * Returns a query-result-row as an associative array (no numerical keys !!!) * + * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object * @param bool $do_next_record should next_record() be called or not (default not) * @param string $strip='' string to strip of the column-name, default '' * @return array/bool the associative array or False if no (more) result-row is availible @@ -823,17 +833,7 @@ class egw_db { return False; } - $result = array(); - foreach($this->Record as $column => $value) - { - if (!is_numeric($column)) - { - if ($strip) $column = str_replace($strip,'',$column); - - $result[$column] = $value; - } - } - return $result; + return $strip ? self::strip_array_keys($this->Record,$strip) : $this->Record; } /** @@ -1774,4 +1774,19 @@ class egw_db return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,ADODB_FETCH_ASSOC); } + + /** + * Strip eg. a prefix from the keys of an array + * + * @param array $arr + * @param string/array $strip + * @return array + */ + static function strip_array_keys($arr,$strip) + { + $keys = array_keys($arr); + + return array_walk($keys,create_function('&$v,$k,$strip','$v = str_replace($strip,\'\',$v);'),$strip) ? + array_combine($keys,$arr) : $arr; + } }