]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Entity.php
LDAP: Added TLS support
[bookstack] / app / Entities / Entity.php
index d1a8664e472d1fc5e0fa1d86ef3990c8efd2a7ce..99922bcebe50047c18563da197091d3b9bca1215 100644 (file)
@@ -204,9 +204,9 @@ class Entity extends Ownable
     /**
      * Get the related delete records for this entity.
      */
-    public function deleteRecords(): MorphMany
+    public function deletions(): MorphMany
     {
-        return $this->morphMany(DeleteRecord::class, 'deletable');
+        return $this->morphMany(Deletion::class, 'deletable');
     }
 
     /**
@@ -287,6 +287,22 @@ class Entity extends Ownable
         return $path;
     }
 
+    /**
+     * Get the parent entity if existing.
+     * This is the "static" parent and does not include dynamic
+     * relations such as shelves to books.
+     */
+    public function getParent(): ?Entity
+    {
+        if ($this->isA('page')) {
+            return $this->chapter_id ? $this->chapter()->withTrashed()->first() : $this->book()->withTrashed()->first();
+        }
+        if ($this->isA('chapter')) {
+            return $this->book()->withTrashed()->first();
+        }
+        return null;
+    }
+
     /**
      * Rebuild the permissions for this entity.
      */