]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/CommentRepo.php
#47 Inserts null for updated_at when the user is creating a comment.
[bookstack] / app / Repos / CommentRepo.php
index e8db3f83e21a918cfb6263b23398cc2c7aa906c7..7e4955d5569e040c2fe39b465421627efe18ad19 100644 (file)
@@ -1,7 +1,7 @@
 <?php namespace BookStack\Repos;
 
 use BookStack\Comment;
-use BookStack\Entity;
+use BookStack\Page;
 
 /**
  * Class TagRepo
@@ -10,8 +10,42 @@ use BookStack\Entity;
 class CommentRepo {
     /**
      *
-     * @var Comment $comment 
+     * @var Comment $comment
      */
     protected $comment;
-    
+
+    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->updated_at = null;
+        $comment->save();
+        return $comment;
+    }
+
+    public function update($comment, $input) {
+        $userId = user()->id;
+        $comment->updated_by = $userId;
+        $comment->fill($input);
+        $comment->save();
+        return $comment;
+    }
+
+    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();
+    }
 }
\ No newline at end of file