X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/860d4d4be5eb7b1d4b13fcc31bf5fe3eafb01a33..refs/pull/692/head:/app/Comment.php diff --git a/app/Comment.php b/app/Comment.php index 8588982e5..2800ab21a 100644 --- a/app/Comment.php +++ b/app/Comment.php @@ -1,12 +1,10 @@ -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); - } - - public function getPageComments($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, comments.parent_id, ' - . 'u.name AS created_by_name, u1.name AS updated_by_name, ' - . 'i.url AS avatar '); - $query->whereRaw('page_id = ?', [$pageId]); - $query->orderBy('created_at'); - return $query->get(); - } - - public function getAllPageComments($pageId) { - return self::where('page_id', '=', $pageId)->with(['createdBy' => function($query) { - $query->select('id', 'name', 'image_id'); - }, 'updatedBy' => function($query) { - $query->select('id', 'name'); - }, 'createdBy.avatar' => function ($query) { - $query->select('id', 'path', 'url'); - }])->get(); - } - - public function getCommentById($commentId) { - return self::where('id', '=', $commentId)->with(['createdBy' => function($query) { - $query->select('id', 'name', 'image_id'); - }, 'updatedBy' => function($query) { - $query->select('id', 'name'); - }, 'createdBy.avatar' => function ($query) { - $query->select('id', 'path', 'url'); - }])->first(); + return $this->created_at->diffForHumans(); } - public function getCreatedAttribute() { - $created = [ - 'day_time_str' => $this->created_at->toDayDateTimeString(), - 'diff' => $this->created_at->diffForHumans() - ]; - return $created; - } - - public function getUpdatedAttribute() { - if (empty($this->updated_at)) { - return null; - } - $updated = [ - 'day_time_str' => $this->updated_at->toDayDateTimeString(), - 'diff' => $this->updated_at->diffForHumans() - ]; - return $updated; - } - - public function getSubCommentsAttribute() { - return $this->sub_comments; + /** + * Get updated date as a relative diff. + * @return mixed + */ + public function getUpdatedAttribute() + { + return $this->updated_at->diffForHumans(); } }