]> BookStack Code Mirror - bookstack/blobdiff - app/Entity.php
Added ability to secure images behind auth
[bookstack] / app / Entity.php
index 6aeb66481dc436ca4654d8acd5c1ed3603d6665e..df8e4d38b241e9928ca951697b6da392744a39e2 100644 (file)
@@ -1,6 +1,8 @@
 <?php namespace BookStack;
 
 
+use Illuminate\Database\Eloquent\Relations\MorphMany;
+
 class Entity extends Ownable
 {
 
@@ -65,6 +67,17 @@ class Entity extends Ownable
         return $this->morphMany(Tag::class, 'entity')->orderBy('order', 'asc');
     }
 
+    /**
+     * Get the comments for an entity
+     * @param bool $orderByCreated
+     * @return MorphMany
+     */
+    public function comments($orderByCreated = true)
+    {
+        $query = $this->morphMany(Comment::class, 'entity');
+        return $orderByCreated ? $query->orderBy('created_at', 'asc') : $query;
+    }
+
     /**
      * Get the related search terms.
      * @return \Illuminate\Database\Eloquent\Relations\MorphMany
@@ -94,17 +107,6 @@ class Entity extends Ownable
             ->where('action', '=', $action)->count() > 0;
     }
 
-    /**
-     * Check if this entity has live (active) restrictions in place.
-     * @param $role_id
-     * @param $action
-     * @return bool
-     */
-    public function hasActiveRestriction($role_id, $action)
-    {
-        return $this->getRawAttribute('restricted') && $this->hasRestriction($role_id, $action);
-    }
-
     /**
      * Get the entity jointPermissions this is connected to.
      * @return \Illuminate\Database\Eloquent\Relations\MorphMany
@@ -176,5 +178,11 @@ class Entity extends Ownable
      */
     public function entityRawQuery(){return '';}
 
+    /**
+     * Get the url of this entity
+     * @param $path
+     * @return string
+     */
+    public function getUrl($path){return '/';}
 
 }