]> BookStack Code Mirror - bookstack/blobdiff - app/Entity.php
reduced icon size
[bookstack] / app / Entity.php
index 6aeb66481dc436ca4654d8acd5c1ed3603d6665e..1ea4e8dac57cc56e8b978b11ca94f7850d914142 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace BookStack;
 
+use Illuminate\Database\Eloquent\Relations\MorphMany;
 
 class Entity extends Ownable
 {
@@ -26,7 +27,9 @@ class Entity extends Ownable
     {
         $matches = [get_class($this), $this->id] === [get_class($entity), $entity->id];
 
-        if ($matches) return true;
+        if ($matches) {
+            return true;
+        }
 
         if (($entity->isA('chapter') || $entity->isA('page')) && $this->isA('book')) {
             return $entity->book_id === $this->id;
@@ -65,6 +68,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 +108,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
@@ -157,7 +160,9 @@ class Entity extends Ownable
      */
     public function getShortName($length = 25)
     {
-        if (strlen($this->name) <= $length) return $this->name;
+        if (strlen($this->name) <= $length) {
+            return $this->name;
+        }
         return substr($this->name, 0, $length - 3) . '...';
     }
 
@@ -174,7 +179,18 @@ class Entity extends Ownable
      * Return a generalised, common raw query that can be 'unioned' across entities.
      * @return string
      */
-    public function entityRawQuery(){return '';}
-
+    public function entityRawQuery()
+    {
+        return '';
+    }
 
+    /**
+     * Get the url of this entity
+     * @param $path
+     * @return string
+     */
+    public function getUrl($path)
+    {
+        return '/';
+    }
 }