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\Support\Str;
12 * @property string $type
13 * @property User $user
14 * @property Entity $entity
15 * @property string $detail
16 * @property string $entity_type
17 * @property int $entity_id
18 * @property int $user_id
20 class Activity extends Model
24 * Get the entity for this activity.
26 public function entity()
28 if ($this->entity_type === '') {
29 $this->entity_type = null;
31 return $this->morphTo('entity');
35 * Get the user this activity relates to.
37 public function user(): BelongsTo
39 return $this->belongsTo(User::class);
43 * Returns text from the language files, Looks up by using the activity key.
45 public function getText(): string
47 return trans('activities.' . $this->type);
51 * Check if this activity is intended to be for an entity.
53 public function isForEntity(): bool
55 return Str::startsWith($this->type, [
56 'page_', 'chapter_', 'book_', 'bookshelf_'
61 * Checks if another Activity matches the general information of another.
63 public function isSimilarTo(Activity $activityB): bool
65 return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id];