X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8cdf3203ef67b01ad359699c5c6a5ea8d890e4f8..refs/pull/5721/head:/app/Activity/Models/Watch.php diff --git a/app/Activity/Models/Watch.php b/app/Activity/Models/Watch.php index 6e0e1f787..dfb72cc0a 100644 --- a/app/Activity/Models/Watch.php +++ b/app/Activity/Models/Watch.php @@ -2,10 +2,12 @@ namespace BookStack\Activity\Models; +use BookStack\Activity\WatchLevels; use BookStack\Permissions\Models\JointPermission; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphTo; /** * @property int $id @@ -18,35 +20,26 @@ use Illuminate\Database\Eloquent\Relations\HasMany; */ class Watch extends Model { - protected static array $levelByOption = [ - 'default' => -1, - 'ignore' => 0, - 'new' => 1, - 'updates' => 2, - 'comments' => 3, - ]; + protected $guarded = []; - public function watchable() + public function watchable(): MorphTo { - $this->morphTo(); + return $this->morphTo(); } public function jointPermissions(): HasMany { return $this->hasMany(JointPermission::class, 'entity_id', 'watchable_id') - ->whereColumn('favourites.watchable_type', '=', 'joint_permissions.entity_type'); + ->whereColumn('watches.watchable_type', '=', 'joint_permissions.entity_type'); } - /** - * @return string[] - */ - public static function getAvailableOptionNames(): array + public function getLevelName(): string { - return array_keys(static::$levelByOption); + return WatchLevels::levelValueToName($this->level); } - public static function optionNameToLevel(string $option): int + public function ignoring(): bool { - return static::$levelByOption[$option] ?? -1; + return $this->level === WatchLevels::IGNORE; } }