]> BookStack Code Mirror - bookstack/blobdiff - app/Activity/Models/Watch.php
ZIP Imports: Added API examples, finished testing
[bookstack] / app / Activity / Models / Watch.php
index 6637c9655de10e9f9366d7ff8a037e0b48125279..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
@@ -20,14 +22,24 @@ class Watch extends Model
 {
     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');
+    }
+
+    public function getLevelName(): string
+    {
+        return WatchLevels::levelValueToName($this->level);
+    }
+
+    public function ignoring(): bool
+    {
+        return $this->level === WatchLevels::IGNORE;
     }
 }