methods to get/set current account_id taking care of necessary offset for groups

This commit is contained in:
Ralf Becker 2013-05-10 17:20:37 +00:00
parent 61e00e4ebc
commit 2b2938d2dd

View File

@ -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
*