X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8e2437498f879f79f222119f8afeacf22f640f3d..refs/pull/651/head:/app/Comment.php diff --git a/app/Comment.php b/app/Comment.php index 4a9c48c74..2800ab21a 100644 --- a/app/Comment.php +++ b/app/Comment.php @@ -1,12 +1,10 @@ -morphTo('entity'); } - + /** - * Get the page that this comment is in. - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * Check if a comment has been updated since creation. + * @return bool */ - public function page() + public function isUpdated() { - return $this->belongsTo(Page::class); + return $this->updated_at->timestamp > $this->created_at->timestamp; } - + /** - * Get the owner of this comment. - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * Get created date as a relative diff. + * @return mixed */ - public function user() + public function getCreatedAttribute() { - return $this->belongsTo(User::class); + return $this->created_at->diffForHumans(); } - - public function getParentCommentsByPage($pageId, $pageNum = 0, $limit = 0) { - $data = ['pageId' => $pageId]; - $query = static::newQuery(); - $query->join('users AS u', 'comments.created_by', '=', 'u.id'); - $query->leftJoin('users AS u1', 'comments.updated_by', '=', 'u1.id'); - $query->leftJoin('images AS i', 'i.id', '=', 'u.image_id'); - $query->selectRaw('comments.id, text, html, comments.created_by, comments.updated_by, comments.created_at, comments.updated_at, ' - . 'u.name AS created_by_name, u1.name AS updated_by_name, ' - . '(SELECT count(c.id) FROM bookstack.comments c WHERE c.parent_id = comments.id AND page_id = ?) AS cnt_sub_comments, i.url AS avatar ', - [$pageId]); - $query->whereRaw('page_id = ? AND parent_id IS NULL', [$pageId]); - $query->orderBy('created_at'); - return $query; + + /** + * Get updated date as a relative diff. + * @return mixed + */ + public function getUpdatedAttribute() + { + return $this->updated_at->diffForHumans(); } }