]> BookStack Code Mirror - bookstack/blob - app/Activity/Models/Watch.php
Merge pull request #5917 from BookStackApp/copy_references
[bookstack] / app / Activity / Models / Watch.php
1 <?php
2
3 namespace BookStack\Activity\Models;
4
5 use BookStack\Activity\WatchLevels;
6 use BookStack\Permissions\Models\JointPermission;
7 use Carbon\Carbon;
8 use Illuminate\Database\Eloquent\Factories\HasFactory;
9 use Illuminate\Database\Eloquent\Model;
10 use Illuminate\Database\Eloquent\Relations\HasMany;
11 use Illuminate\Database\Eloquent\Relations\MorphTo;
12
13 /**
14  * @property int $id
15  * @property int $user_id
16  * @property int $watchable_id
17  * @property string $watchable_type
18  * @property int $level
19  * @property Carbon $created_at
20  * @property Carbon $updated_at
21  */
22 class Watch extends Model
23 {
24     use HasFactory;
25
26     protected $guarded = [];
27
28     public function watchable(): MorphTo
29     {
30         return $this->morphTo();
31     }
32
33     public function jointPermissions(): HasMany
34     {
35         return $this->hasMany(JointPermission::class, 'entity_id', 'watchable_id')
36             ->whereColumn('watches.watchable_type', '=', 'joint_permissions.entity_type');
37     }
38
39     public function getLevelName(): string
40     {
41         return WatchLevels::levelValueToName($this->level);
42     }
43
44     public function ignoring(): bool
45     {
46         return $this->level === WatchLevels::IGNORE;
47     }
48 }