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