]> BookStack Code Mirror - bookstack/blob - app/Repos/CommentRepo.php
#47 Inserts null for updated_at when the user is creating a comment.
[bookstack] / app / Repos / CommentRepo.php
1 <?php namespace BookStack\Repos;
2
3 use BookStack\Comment;
4 use BookStack\Page;
5
6 /**
7  * Class TagRepo
8  * @package BookStack\Repos
9  */
10 class CommentRepo {
11     /**
12      *
13      * @var Comment $comment
14      */
15     protected $comment;
16
17     public function __construct(Comment $comment)
18     {
19         $this->comment = $comment;
20     }
21
22     public function create (Page $page, $data = []) {
23         $userId = user()->id;
24         $comment = $this->comment->newInstance();
25         $comment->fill($data);
26         // new comment
27         $comment->page_id = $page->id;
28         $comment->created_by = $userId;
29         $comment->updated_at = null;
30         $comment->save();
31         return $comment;
32     }
33
34     public function update($comment, $input) {
35         $userId = user()->id;
36         $comment->updated_by = $userId;
37         $comment->fill($input);
38         $comment->save();
39         return $comment;
40     }
41
42     public function getCommentsForPage($pageId, $commentId, $count = 20) {
43         // requesting parent comments
44         $query = $this->comment->getCommentsByPage($pageId, $commentId);
45         return $query->paginate($count);
46     }
47
48     public function getCommentCount($pageId) {
49         return $this->comment->where('page_id', '=', $pageId)->count();
50     }
51 }