+
+ /**
+ * 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
+ */
+ public function jointPermissions()
+ {
+ return $this->morphMany(JointPermission::class, 'entity');
+ }
+
+ /**
+ * Allows checking of the exact class, Used to check entity type.
+ * Cleaner method for is_a.
+ * @param $type
+ * @return bool
+ */
+ public static function isA($type)
+ {
+ return static::getType() === strtolower($type);
+ }
+
+ /**
+ * Get entity type.
+ * @return mixed
+ */
+ public static function getType()
+ {
+ return strtolower(static::getClassName());
+ }
+
+ /**
+ * Get an instance of an entity of the given type.
+ * @param $type
+ * @return Entity
+ */
+ public static function getEntityInstance($type)
+ {
+ $types = ['Page', 'Book', 'Chapter'];
+ $className = str_replace([' ', '-', '_'], '', ucwords($type));
+ if (!in_array($className, $types)) {
+ return null;
+ }
+
+ return app('BookStack\\' . $className);
+ }
+
+ /**
+ * Gets a limited-length version of the entities name.
+ * @param int $length
+ * @return string
+ */
+ public function getShortName($length = 25)
+ {
+ if (strlen($this->name) <= $length) return $this->name;
+ return substr($this->name, 0, $length - 3) . '...';
+ }
+
+ /**
+ * Get the body text of this entity.
+ * @return mixed
+ */
+ public function getText()
+ {
+ return $this->{$this->textField};
+ }
+
+ /**
+ * Return a generalised, common raw query that can be 'unioned' across entities.
+ * @return string
+ */
+ public function entityRawQuery(){return '';}
+
+