Non-dynamic user and group fetching in Profile
This commit is contained in:
parent
adf896bc12
commit
1217cd59bf
|
@ -92,32 +92,40 @@ class Profile extends Managed_DataObject
|
||||||
return $user->getProfile();
|
return $user->getProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected $_user = -1; // Uninitialized value distinct from null
|
protected $_user = array();
|
||||||
|
|
||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
if ($this->_user === -1) {
|
if (!isset($this->_user[$this->id])) {
|
||||||
$this->_user = User::getKV('id', $this->id);
|
$this->_setUser(User::getKV('id', $this->id));
|
||||||
}
|
}
|
||||||
if (!$this->_user instanceof User) {
|
return $this->_user[$this->id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _setUser(User $user=null)
|
||||||
|
{
|
||||||
|
if (!$user instanceof User) {
|
||||||
throw new NoSuchUserException(array('id'=>$this->id));
|
throw new NoSuchUserException(array('id'=>$this->id));
|
||||||
}
|
}
|
||||||
|
$this->_user[$this->id] = $user;
|
||||||
return $this->_user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected $_group = -1;
|
protected $_group = array();
|
||||||
|
|
||||||
public function getGroup()
|
public function getGroup()
|
||||||
{
|
{
|
||||||
if ($this->_group === -1) {
|
if (!isset($this->_group[$this->id])) {
|
||||||
$this->_group = User_group::getKV('profile_id', $this->id);
|
$this->_setGroup(User_group::getKV('profile_id', $this->id));
|
||||||
}
|
}
|
||||||
if (!$this->_group instanceof User_group) {
|
return $this->_group[$this->id];
|
||||||
throw new NoSuchGroupException(array('profile_id'=>$this->id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_group;
|
public function _setGroup(User_group $group=null)
|
||||||
|
{
|
||||||
|
if (!$group instanceof User_group) {
|
||||||
|
throw new NoSuchGroupException(array('profile_id'=>$this->id));
|
||||||
|
}
|
||||||
|
$this->_group[$this->id] = $group;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isGroup()
|
public function isGroup()
|
||||||
|
@ -140,8 +148,6 @@ class Profile extends Managed_DataObject
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected $_avatars = array();
|
|
||||||
|
|
||||||
public function getAvatar($width, $height=null)
|
public function getAvatar($width, $height=null)
|
||||||
{
|
{
|
||||||
return Avatar::byProfile($this, $width, $height);
|
return Avatar::byProfile($this, $width, $height);
|
||||||
|
@ -1539,7 +1545,7 @@ class Profile extends Managed_DataObject
|
||||||
function __sleep()
|
function __sleep()
|
||||||
{
|
{
|
||||||
$vars = parent::__sleep();
|
$vars = parent::__sleep();
|
||||||
$skip = array('_user', '_avatars');
|
$skip = array('_user', '_group');
|
||||||
return array_diff($vars, $skip);
|
return array_diff($vars, $skip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user