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
*/
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;
}
}