1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

#47 Implements the reply and edit functionality for comments.

This commit is contained in:
Abijeet
2017-05-16 00:40:14 +05:30
parent 4f231d1bf0
commit 03e5d61798
10 changed files with 149 additions and 95 deletions

View File

@ -5,8 +5,8 @@ use Illuminate\Support\Facades\DB;
class Comment extends Ownable
{
protected $fillable = ['text', 'html'];
protected $fillable = ['text', 'html', 'parent_id'];
/**
* Get the entity that this comment belongs to
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
@ -15,7 +15,7 @@ class Comment extends Ownable
{
return $this->morphTo('entity');
}
/**
* Get the page that this comment is in.
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@ -24,32 +24,32 @@ class Comment extends Ownable
{
return $this->belongsTo(Page::class);
}
/**
* Get the owner of this comment.
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
public function user()
{
return $this->belongsTo(User::class);
}
public function getCommentsByPage($pageId, $commentId, $pageNum = 0, $limit = 0) {
public function getCommentsByPage($pageId, $commentId, $pageNum = 0, $limit = 0) {
$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 ',
. '(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]);
if (empty($commentId)) {
$query->whereRaw('page_id = ? AND parent_id IS NULL', [$pageId]);
} else {
$query->whereRaw('page_id = ? AND parent_id = ?', [$pageId, $commentId]);
}
}
$query->orderBy('created_at');
return $query;
}