]> BookStack Code Mirror - bookstack/blobdiff - app/Activity/Models/Watch.php
ZIP Imports: Added API examples, finished testing
[bookstack] / app / Activity / Models / Watch.php
index 6e0e1f787d3e384754b5aafbb1bc085d1887436e..dfb72cc0a369598add077fbca2c3074134956e27 100644 (file)
@@ -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;
     }
 }