]> BookStack Code Mirror - bookstack/blobdiff - app/Actions/Activity.php
Extend /users API endpoint
[bookstack] / app / Actions / Activity.php
index 63eda591783c8d14a2fc2f478ee79b99f0bb0be8..c8590f0b25d12dc8f4f29210e51cd3c8b28de897 100644 (file)
@@ -3,9 +3,11 @@
 namespace BookStack\Actions;
 
 use BookStack\Auth\User;
-use BookStack\Entities\Entity;
+use BookStack\Entities\Models\Entity;
 use BookStack\Model;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\MorphTo;
+use Illuminate\Support\Str;
 
 /**
  * @property string $type
@@ -22,7 +24,7 @@ class Activity extends Model
     /**
      * Get the entity for this activity.
      */
-    public function entity()
+    public function entity(): MorphTo
     {
         if ($this->entity_type === '') {
             $this->entity_type = null;
@@ -46,6 +48,16 @@ class Activity extends Model
         return trans('activities.' . $this->type);
     }
 
+    /**
+     * Check if this activity is intended to be for an entity.
+     */
+    public function isForEntity(): bool
+    {
+        return Str::startsWith($this->type, [
+            'page_', 'chapter_', 'book_', 'bookshelf_'
+        ]);
+    }
+
     /**
      * Checks if another Activity matches the general information of another.
      */