From 2b2938d2dd3892f7055da256c920a12cd5fcf21b Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 10 May 2013 17:20:37 +0000 Subject: [PATCH] methods to get/set current account_id taking care of necessary offset for groups --- phpgwapi/inc/class.preferences.inc.php | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/phpgwapi/inc/class.preferences.inc.php b/phpgwapi/inc/class.preferences.inc.php index 4c9f207ca5..f453813e99 100644 --- a/phpgwapi/inc/class.preferences.inc.php +++ b/phpgwapi/inc/class.preferences.inc.php @@ -107,6 +107,18 @@ class preferences $this->db = $GLOBALS['egw_setup']->db; $this->table = $GLOBALS['egw_setup']->prefs_table; } + $this->set_account_id($account_id); + } + + /** + * Set account_id for class + * + * Takes care of offset for groups. + * + * @param int $account_id + */ + function set_account_id($account_id) + { // if we got instancated for a group, need to set offset of DEFAULT_ID! if ($account_id < 0 && $GLOBALS['egw']->accounts->exists($account_id) == 2) { @@ -118,6 +130,25 @@ class preferences } } + /** + * Return account_id class is instanciated for or "default" or "forced" + * + * Takes care of offset for groups. + * + * @return string|int + */ + function get_account_id() + { + switch ($this->account_id) + { + case self::DEFAULT_ID: + return 'default'; + case self::FORCED_ID: + return 'forced'; + } + return $this->account_id < self::DEFAULT_ID ? $this->account_id-self::DEFAULT_ID : $this->account_id; + } + /** * Old PHP4 contstructor *