]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Entity.php
LDAP: Added TLS support
[bookstack] / app / Entities / Entity.php
index 14328386ccc7b4e02577cb549bab9818d0c2bb70..99922bcebe50047c18563da197091d3b9bca1215 100644 (file)
@@ -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.
      */