3 namespace BookStack\Actions;
5 use BookStack\Auth\User;
6 use BookStack\Entities\Models\Entity;
8 use Illuminate\Database\Eloquent\Relations\BelongsTo;
9 use Illuminate\Database\Eloquent\Relations\MorphTo;
10 use Illuminate\Support\Str;
13 * @property string $type
14 * @property User $user
15 * @property Entity $entity
16 * @property string $detail
17 * @property string $entity_type
18 * @property int $entity_id
19 * @property int $user_id
21 class Activity extends Model
24 * Get the entity for this activity.
26 public function entity(): MorphTo
28 if ($this->entity_type === '') {
29 $this->entity_type = null;
32 return $this->morphTo('entity');
36 * Get the user this activity relates to.
38 public function user(): BelongsTo
40 return $this->belongsTo(User::class);
44 * Returns text from the language files, Looks up by using the activity key.
46 public function getText(): string
48 return trans('activities.' . $this->type);
52 * Check if this activity is intended to be for an entity.
54 public function isForEntity(): bool
56 return Str::startsWith($this->type, [
57 'page_', 'chapter_', 'book_', 'bookshelf_',
62 * Checks if another Activity matches the general information of another.
64 public function isSimilarTo(self $activityB): bool
66 return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id];