]> BookStack Code Mirror - bookstack/blob - app/Activity/Models/Watch.php
Add optional OIDC avatar fetching from the “picture” claim
[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\Model;
9 use Illuminate\Database\Eloquent\Relations\HasMany;
10 use Illuminate\Database\Eloquent\Relations\MorphTo;
11
12 /**
13  * @property int $id
14  * @property int $user_id
15  * @property int $watchable_id
16  * @property string $watchable_type
17  * @property int $level
18  * @property Carbon $created_at
19  * @property Carbon $updated_at
20  */
21 class Watch extends Model
22 {
23     protected $guarded = [];
24
25     public function watchable(): MorphTo
26     {
27         return $this->morphTo();
28     }
29
30     public function jointPermissions(): HasMany
31     {
32         return $this->hasMany(JointPermission::class, 'entity_id', 'watchable_id')
33             ->whereColumn('watches.watchable_type', '=', 'joint_permissions.entity_type');
34     }
35
36     public function getLevelName(): string
37     {
38         return WatchLevels::levelValueToName($this->level);
39     }
40
41     public function ignoring(): bool
42     {
43         return $this->level === WatchLevels::IGNORE;
44     }
45 }