Simplify functions regarding locally cached profiles etc.

This commit is contained in:
Mikael Nordfeldth 2014-06-06 00:32:07 +02:00
parent c786892103
commit c8c6bf9a1c
3 changed files with 20 additions and 36 deletions

View File

@ -97,36 +97,28 @@ class Profile extends Managed_DataObject
public function getUser() public function getUser()
{ {
if (!isset($this->_user[$this->id])) { if (!isset($this->_user[$this->id])) {
$this->_setUser(User::getKV('id', $this->id)); $user = User::getKV('id', $this->id);
}
return $this->_user[$this->id];
}
public function _setUser(User $user=null)
{
if (!$user instanceof User) { if (!$user instanceof User) {
throw new NoSuchUserException(array('id'=>$this->id)); throw new NoSuchUserException(array('id'=>$this->id));
} }
$this->_user[$this->id] = $user; $this->_user[$this->id] = $user;
} }
return $this->_user[$this->id];
}
protected $_group = array(); protected $_group = array();
public function getGroup() public function getGroup()
{ {
if (!isset($this->_group[$this->id])) { if (!isset($this->_group[$this->id])) {
$this->_setGroup(User_group::getKV('profile_id', $this->id)); $group = User_group::getKV('profile_id', $this->id);
}
return $this->_group[$this->id];
}
public function _setGroup(User_group $group=null)
{
if (!$group instanceof User_group) { if (!$group instanceof User_group) {
throw new NoSuchGroupException(array('profile_id'=>$this->id)); throw new NoSuchGroupException(array('profile_id'=>$this->id));
} }
$this->_group[$this->id] = $group; $this->_group[$this->id] = $group;
} }
return $this->_group[$this->id];
}
public function isGroup() public function isGroup()
{ {

View File

@ -123,18 +123,14 @@ class User extends Managed_DataObject
public function getProfile() public function getProfile()
{ {
if (!isset($this->_profile[$this->id])) { if (!isset($this->_profile[$this->id])) {
$this->_setProfile(Profile::getKV('id', $this->id)); $profile = Profile::getKV('id', $this->id);
}
return $this->_profile[$this->id];
}
public function _setProfile(Profile $profile=null)
{
if (!$profile instanceof Profile) { if (!$profile instanceof Profile) {
throw new UserNoProfileException($this); throw new UserNoProfileException($this);
} }
$this->_profile[$this->id] = $profile; $this->_profile[$this->id] = $profile;
} }
return $this->_profile[$this->id];
}
public function getUri() public function getUri()
{ {

View File

@ -84,18 +84,14 @@ class User_group extends Managed_DataObject
public function getProfile() public function getProfile()
{ {
if (!isset($this->_profile[$this->profile_id])) { if (!isset($this->_profile[$this->profile_id])) {
$this->_setProfile(Profile::getKV('id', $this->profile_id)); $profile = Profile::getKV('id', $this->profile_id);
}
return $this->_profile[$this->profile_id];
}
public function _setProfile(Profile $profile=null)
{
if (!$profile instanceof Profile) { if (!$profile instanceof Profile) {
throw new GroupNoProfileException($this); throw new GroupNoProfileException($this);
} }
$this->_profile[$this->profile_id] = $profile; $this->_profile[$this->profile_id] = $profile;
} }
return $this->_profile[$this->profile_id];
}
public static function defaultLogo($size) public static function defaultLogo($size)
{ {