3 namespace BookStack\Activity\Models;
5 use BookStack\App\Model;
6 use BookStack\Users\Models\HasCreatorAndUpdater;
7 use BookStack\Util\HtmlContentFilter;
8 use Illuminate\Database\Eloquent\Factories\HasFactory;
9 use Illuminate\Database\Eloquent\Relations\BelongsTo;
10 use Illuminate\Database\Eloquent\Relations\MorphTo;
14 * @property string $text - Deprecated & now unused (#4821)
15 * @property string $html
16 * @property int|null $parent_id - Relates to local_id, not id
17 * @property int $local_id
18 * @property string $entity_type
19 * @property int $entity_id
20 * @property int $created_by
21 * @property int $updated_by
22 * @property string $content_ref
23 * @property bool $archived
25 class Comment extends Model implements Loggable
28 use HasCreatorAndUpdater;
30 protected $fillable = ['parent_id'];
33 * Get the entity that this comment belongs to.
35 public function entity(): MorphTo
37 return $this->morphTo('entity');
41 * Get the parent comment this is in reply to (if existing).
43 public function parent(): BelongsTo
45 return $this->belongsTo(Comment::class, 'parent_id', 'local_id', 'parent')
46 ->where('entity_type', '=', $this->entity_type)
47 ->where('entity_id', '=', $this->entity_id);
51 * Check if a comment has been updated since creation.
53 public function isUpdated(): bool
55 return $this->updated_at->timestamp > $this->created_at->timestamp;
58 public function logDescriptor(): string
60 return "Comment #{$this->local_id} (ID: {$this->id}) for {$this->entity_type} (ID: {$this->entity_id})";
63 public function safeHtml(): string
65 return HtmlContentFilter::removeScriptsFromHtmlString($this->html ?? '');