Continued work on getter/setters: post uploaders
This commit is contained in:
parent
8d8e92b84e
commit
878079030d
3 changed files with 13 additions and 4 deletions
|
@ -75,7 +75,9 @@ final class CommentEntity extends AbstractEntity implements IValidatable
|
||||||
{
|
{
|
||||||
if ($this->hasCache('commenter'))
|
if ($this->hasCache('commenter'))
|
||||||
return $this->getCache('commenter');
|
return $this->getCache('commenter');
|
||||||
$user = UserModel::findById($this->getCommenterId(), false);
|
if (!$this->commenterId)
|
||||||
|
return null;
|
||||||
|
$user = UserModel::findById($this->commenterId, false);
|
||||||
$this->setCache('commenter', $user);
|
$this->setCache('commenter', $user);
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
public $uploadDate;
|
public $uploadDate;
|
||||||
protected $imageWidth;
|
protected $imageWidth;
|
||||||
protected $imageHeight;
|
protected $imageHeight;
|
||||||
public $uploaderId;
|
protected $uploaderId;
|
||||||
protected $source;
|
protected $source;
|
||||||
public $commentCount = 0;
|
public $commentCount = 0;
|
||||||
public $favCount = 0;
|
public $favCount = 0;
|
||||||
|
@ -39,14 +39,21 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
{
|
{
|
||||||
if ($this->hasCache('uploader'))
|
if ($this->hasCache('uploader'))
|
||||||
return $this->getCache('uploader');
|
return $this->getCache('uploader');
|
||||||
|
if (!$this->uploaderId)
|
||||||
|
return null;
|
||||||
$uploader = UserModel::findById($this->uploaderId, false);
|
$uploader = UserModel::findById($this->uploaderId, false);
|
||||||
$this->setCache('uploader', $uploader);
|
$this->setCache('uploader', $uploader);
|
||||||
return $uploader;
|
return $uploader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUploaderId()
|
||||||
|
{
|
||||||
|
return $this->uploaderId;
|
||||||
|
}
|
||||||
|
|
||||||
public function setUploader($user)
|
public function setUploader($user)
|
||||||
{
|
{
|
||||||
$this->uploaderId = $user->getId();
|
$this->uploaderId = $user !== null ? $user->getId() : null;
|
||||||
$this->setCache('uploader', $user);
|
$this->setCache('uploader', $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ class PostModel extends AbstractCrudModel
|
||||||
'upload_date' => $post->uploadDate,
|
'upload_date' => $post->uploadDate,
|
||||||
'image_width' => $post->getImageWidth(),
|
'image_width' => $post->getImageWidth(),
|
||||||
'image_height' => $post->getImageHeight(),
|
'image_height' => $post->getImageHeight(),
|
||||||
'uploader_id' => $post->uploaderId,
|
'uploader_id' => $post->getUploaderId(),
|
||||||
'source' => $post->getSource(),
|
'source' => $post->getSource(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue