diff --git a/src/Api/Jobs/ScorePostJob.php b/src/Api/Jobs/ScorePostJob.php index 184de201..edb8bef8 100644 --- a/src/Api/Jobs/ScorePostJob.php +++ b/src/Api/Jobs/ScorePostJob.php @@ -9,6 +9,8 @@ class ScorePostJob extends AbstractPostJob $score = intval($this->getArgument(self::SCORE)); UserModel::updateUserScore(Auth::getCurrentUser(), $post, $score); + + return $post; } public function requiresPrivilege() diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 82895bff..a860ad0c 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -241,12 +241,12 @@ class PostController //todo: //move these to PostEntity when implementing ApiController - $favorite = Auth::getCurrentUser()->hasFavorited($post); - $score = Auth::getCurrentUser()->getScore($post); + $isUserFavorite = Auth::getCurrentUser()->hasFavorited($post); + $userScore = Auth::getCurrentUser()->getScore($post); $flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', [])); - $context->favorite = $favorite; - $context->score = $score; + $context->isUserFavorite = $isUserFavorite; + $context->userScore = $userScore; $context->flagged = $flagged; $context->transport->post = $post; $context->transport->prevPostId = $prevPostId ? $prevPostId : null; diff --git a/src/Models/Entities/PostEntity.php b/src/Models/Entities/PostEntity.php index 38335641..37d217ae 100644 --- a/src/Models/Entities/PostEntity.php +++ b/src/Models/Entities/PostEntity.php @@ -18,9 +18,9 @@ class PostEntity extends AbstractEntity implements IValidatable protected $uploaderId; protected $source; - public $commentCount = 0; - public $favCount = 0; - public $score = 0; + protected $commentCount = 0; + protected $favCount = 0; + protected $score = 0; public function validate() { @@ -85,6 +85,21 @@ class PostEntity extends AbstractEntity implements IValidatable return $favorites; } + public function getScore() + { + return $this->score; + } + + public function getCommentCount() + { + return $this->commentCount; + } + + public function getFavoriteCount() + { + return $this->favCount; + } + public function getRelations() { if ($this->hasCache('relations')) diff --git a/src/Models/Entities/UserEntity.php b/src/Models/Entities/UserEntity.php index f4242e54..2cb7fde0 100644 --- a/src/Models/Entities/UserEntity.php +++ b/src/Models/Entities/UserEntity.php @@ -347,7 +347,7 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('favoritee'); $stmt->setCriterion(new Sql\EqualsFunctor('user_id', new Sql\Binding($this->getId()))); - return Database::fetchOne($stmt)['count']; + return (int) Database::fetchOne($stmt)['count']; } public function getCommentCount() @@ -356,7 +356,7 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('comment'); $stmt->setCriterion(new Sql\EqualsFunctor('commenter_id', new Sql\Binding($this->getId()))); - return Database::fetchOne($stmt)['count']; + return (int) Database::fetchOne($stmt)['count']; } public function getPostCount() @@ -365,6 +365,6 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('post'); $stmt->setCriterion(new Sql\EqualsFunctor('uploader_id', new Sql\Binding($this->getId()))); - return Database::fetchOne($stmt)['count']; + return (int) Database::fetchOne($stmt)['count']; } } diff --git a/src/Views/post-small.phtml b/src/Views/post-small.phtml index 98239456..78a87318 100644 --- a/src/Views/post-small.phtml +++ b/src/Views/post-small.phtml @@ -54,9 +54,9 @@ if ($masstag) $this->context->post->score, - 'comments' => $this->context->post->commentCount, - 'favs' => $this->context->post->favCount, + 'score' => $this->context->post->getScore(), + 'comments' => $this->context->post->getCommentCount(), + 'favs' => $this->context->post->getFavoriteCount(), ]; ?> diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml index 2f4439f8..1490e041 100644 --- a/src/Views/post-view.phtml +++ b/src/Views/post-view.phtml @@ -148,7 +148,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;