]> BookStack Code Mirror - bookstack/blob - app/Actions/Activity.php
Updated activities table format
[bookstack] / app / Actions / Activity.php
1 <?php
2
3 namespace BookStack\Actions;
4
5 use BookStack\Auth\User;
6 use BookStack\Entities\Entity;
7 use BookStack\Model;
8 use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
10 /**
11  * @property string $type
12  * @property User $user
13  * @property Entity $entity
14  * @property string $detail
15  * @property string $entity_type
16  * @property int $entity_id
17  * @property int $user_id
18  */
19 class Activity extends Model
20 {
21
22     /**
23      * Get the entity for this activity.
24      */
25     public function entity()
26     {
27         if ($this->entity_type === '') {
28             $this->entity_type = null;
29         }
30         return $this->morphTo('entity');
31     }
32
33     /**
34      * Get the user this activity relates to.
35      */
36     public function user(): BelongsTo
37     {
38         return $this->belongsTo(User::class);
39     }
40
41     /**
42      * Returns text from the language files, Looks up by using the activity key.
43      */
44     public function getText(): string
45     {
46         return trans('activities.' . $this->type);
47     }
48
49     /**
50      * Checks if another Activity matches the general information of another.
51      */
52     public function isSimilarTo(Activity $activityB): bool
53     {
54         return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id];
55     }
56 }