-<?php namespace BookStack\Actions;
+<?php
-use BookStack\Entities\Entity;
+namespace BookStack\Actions;
+
+use BookStack\Entities\Models\Entity;
+use BookStack\Facades\Activity as ActivityService;
use League\CommonMark\CommonMarkConverter;
/**
- * Class CommentRepo
+ * Class CommentRepo.
*/
class CommentRepo
{
-
/**
- * @var Comment $comment
+ * @var Comment
*/
protected $comment;
-
public function __construct(Comment $comment)
{
$this->comment = $comment;
$comment->parent_id = $parent_id;
$entity->comments()->save($comment);
- Activity::add($entity, ActivityType::COMMENTED_ON, $entity->book->id);
+ ActivityService::addForEntity($entity, ActivityType::COMMENTED_ON);
+
return $comment;
}
$comment->text = $text;
$comment->html = $this->commentToHtml($text);
$comment->save();
+
return $comment;
}
public function commentToHtml(string $commentText): string
{
$converter = new CommonMarkConverter([
- 'html_input' => 'strip',
- 'max_nesting_level' => 10,
+ 'html_input' => 'strip',
+ 'max_nesting_level' => 10,
'allow_unsafe_links' => false,
]);
protected function getNextLocalId(Entity $entity): int
{
$comments = $entity->comments(false)->orderBy('local_id', 'desc')->first();
+
return ($comments->local_id ?? 0) + 1;
}
}