2017-01-13 17:15:48 +01:00
|
|
|
<?php namespace BookStack\Repos;
|
|
|
|
|
|
|
|
use BookStack\Comment;
|
2017-04-18 21:51:45 +02:00
|
|
|
use BookStack\Page;
|
2017-01-13 17:15:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class TagRepo
|
|
|
|
* @package BookStack\Repos
|
|
|
|
*/
|
|
|
|
class CommentRepo {
|
|
|
|
/**
|
|
|
|
*
|
2017-05-15 21:10:14 +02:00
|
|
|
* @var Comment $comment
|
2017-01-13 17:15:48 +01:00
|
|
|
*/
|
|
|
|
protected $comment;
|
2017-04-18 21:51:45 +02: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;
|
2017-05-15 21:10:14 +02:00
|
|
|
$comment->created_by = $userId;
|
2017-05-25 04:32:49 +02:00
|
|
|
$comment->updated_at = null;
|
2017-04-18 21:51:45 +02:00
|
|
|
$comment->save();
|
|
|
|
return $comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update($comment, $input) {
|
|
|
|
$userId = user()->id;
|
|
|
|
$comment->updated_by = $userId;
|
|
|
|
$comment->fill($input);
|
|
|
|
$comment->save();
|
|
|
|
return $comment;
|
|
|
|
}
|
2017-05-15 21:10:14 +02:00
|
|
|
|
|
|
|
public function getCommentsForPage($pageId, $commentId, $count = 20) {
|
2017-04-26 23:05:29 +02:00
|
|
|
// requesting parent comments
|
|
|
|
$query = $this->comment->getCommentsByPage($pageId, $commentId);
|
2017-05-15 21:10:14 +02:00
|
|
|
return $query->paginate($count);
|
2017-04-26 23:05:29 +02:00
|
|
|
}
|
2017-05-15 21:10:14 +02:00
|
|
|
|
2017-04-26 23:05:29 +02:00
|
|
|
public function getCommentCount($pageId) {
|
|
|
|
return $this->comment->where('page_id', '=', $pageId)->count();
|
2017-04-18 21:51:45 +02:00
|
|
|
}
|
2017-01-13 17:15:48 +01:00
|
|
|
}
|