]> BookStack Code Mirror - bookstack/blob - app/Actions/Activity.php
fix image delete confirm text
[bookstack] / app / Actions / Activity.php
1 <?php
2
3 namespace BookStack\Actions;
4
5 use BookStack\Auth\User;
6 use BookStack\Entities\Models\Entity;
7 use BookStack\Model;
8 use Illuminate\Database\Eloquent\Relations\BelongsTo;
9 use Illuminate\Support\Str;
10
11 /**
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
19  */
20 class Activity extends Model
21 {
22
23     /**
24      * Get the entity for this activity.
25      */
26     public function entity()
27     {
28         if ($this->entity_type === '') {
29             $this->entity_type = null;
30         }
31         return $this->morphTo('entity');
32     }
33
34     /**
35      * Get the user this activity relates to.
36      */
37     public function user(): BelongsTo
38     {
39         return $this->belongsTo(User::class);
40     }
41
42     /**
43      * Returns text from the language files, Looks up by using the activity key.
44      */
45     public function getText(): string
46     {
47         return trans('activities.' . $this->type);
48     }
49
50     /**
51      * Check if this activity is intended to be for an entity.
52      */
53     public function isForEntity(): bool
54     {
55         return Str::startsWith($this->type, [
56             'page_', 'chapter_', 'book_', 'bookshelf_'
57         ]);
58     }
59
60     /**
61      * Checks if another Activity matches the general information of another.
62      */
63     public function isSimilarTo(Activity $activityB): bool
64     {
65         return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id];
66     }
67 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.