From 878079030d24cfad2ea3f99bf807ae39969bd402 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 7 May 2014 18:39:14 +0200 Subject: [PATCH] Continued work on getter/setters: post uploaders --- src/Models/Entities/CommentEntity.php | 4 +++- src/Models/Entities/PostEntity.php | 11 +++++++++-- src/Models/PostModel.php | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Models/Entities/CommentEntity.php b/src/Models/Entities/CommentEntity.php index 5683b77b..8eebddb2 100644 --- a/src/Models/Entities/CommentEntity.php +++ b/src/Models/Entities/CommentEntity.php @@ -75,7 +75,9 @@ final class CommentEntity extends AbstractEntity implements IValidatable { if ($this->hasCache('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); return $user; } diff --git a/src/Models/Entities/PostEntity.php b/src/Models/Entities/PostEntity.php index 9bbd64e2..f3c3973a 100644 --- a/src/Models/Entities/PostEntity.php +++ b/src/Models/Entities/PostEntity.php @@ -15,7 +15,7 @@ class PostEntity extends AbstractEntity implements IValidatable public $uploadDate; protected $imageWidth; protected $imageHeight; - public $uploaderId; + protected $uploaderId; protected $source; public $commentCount = 0; public $favCount = 0; @@ -39,14 +39,21 @@ class PostEntity extends AbstractEntity implements IValidatable { if ($this->hasCache('uploader')) return $this->getCache('uploader'); + if (!$this->uploaderId) + return null; $uploader = UserModel::findById($this->uploaderId, false); $this->setCache('uploader', $uploader); return $uploader; } + public function getUploaderId() + { + return $this->uploaderId; + } + public function setUploader($user) { - $this->uploaderId = $user->getId(); + $this->uploaderId = $user !== null ? $user->getId() : null; $this->setCache('uploader', $user); } diff --git a/src/Models/PostModel.php b/src/Models/PostModel.php index 9b6c7ecc..e91438f1 100644 --- a/src/Models/PostModel.php +++ b/src/Models/PostModel.php @@ -56,7 +56,7 @@ class PostModel extends AbstractCrudModel 'upload_date' => $post->uploadDate, 'image_width' => $post->getImageWidth(), 'image_height' => $post->getImageHeight(), - 'uploader_id' => $post->uploaderId, + 'uploader_id' => $post->getUploaderId(), 'source' => $post->getSource(), ];