2017-01-13 11:15:48 -05:00
|
|
|
<?php namespace BookStack\Repos;
|
|
|
|
|
|
|
|
use BookStack\Comment;
|
2017-04-18 15:51:45 -04:00
|
|
|
use BookStack\Page;
|
2017-01-13 11:15:48 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class TagRepo
|
|
|
|
* @package BookStack\Repos
|
|
|
|
*/
|
|
|
|
class CommentRepo {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var Comment $comment
|
|
|
|
*/
|
|
|
|
protected $comment;
|
2017-04-18 15:51:45 -04:00
|
|
|
|
|
|
|
public function __construct(Comment $comment)
|
|
|
|
{
|
|
|
|
$this->comment = $comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create (Page $page, $data = []) {
|
|
|
|
$userId = user()->id;
|
|
|
|
$comment = $this->comment->newInstance();
|
|
|
|
$comment->fill($data);
|
|
|
|
// new comment
|
|
|
|
$comment->page_id = $page->id;
|
|
|
|
$comment->created_by = $userId;
|
|
|
|
$comment->save();
|
|
|
|
return $comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update($comment, $input) {
|
|
|
|
$userId = user()->id;
|
|
|
|
$comment->updated_by = $userId;
|
|
|
|
$comment->fill($input);
|
|
|
|
$comment->save();
|
|
|
|
return $comment;
|
|
|
|
}
|
2017-01-13 11:15:48 -05:00
|
|
|
|
2017-04-26 17:05:29 -04:00
|
|
|
public function getCommentsForPage($pageId, $commentId, $count = 20) {
|
|
|
|
// requesting parent comments
|
|
|
|
$query = $this->comment->getCommentsByPage($pageId, $commentId);
|
|
|
|
return $query->paginate($count);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommentCount($pageId) {
|
|
|
|
return $this->comment->where('page_id', '=', $pageId)->count();
|
2017-04-18 15:51:45 -04:00
|
|
|
}
|
2017-01-13 11:15:48 -05:00
|
|
|
}
|