-<?php
+<?php namespace BookStack;
-namespace BookStack;
-use Illuminate\Database\Eloquent\Model;
-
-abstract class Entity extends Model
+abstract class Entity extends Ownable
{
- use Ownable;
-
/**
* Compares this entity to another given entity.
* Matches by comparing class and id.
/**
* Get View objects for this entity.
- * @return mixed
*/
public function views()
{
}
/**
- * Allows checking of the exact class, Used to check entity type.
- * Cleaner method for is_a.
- * @param $type
+ * Get this entities restrictions.
+ */
+ public function restrictions()
+ {
+ return $this->morphMany('BookStack\Restriction', 'restrictable');
+ }
+
+ /**
+ * Check if this entity has a specific restriction set against it.
+ * @param $role_id
+ * @param $action
* @return bool
*/
- public static function isA($type)
+ public function hasRestriction($role_id, $action)
{
- return static::getClassName() === strtolower($type);
+ return $this->restrictions->where('role_id', $role_id)->where('action', $action)->count() > 0;
}
/**
- * Gets the class name.
- * @return string
+ * Allows checking of the exact class, Used to check entity type.
+ * Cleaner method for is_a.
+ * @param $type
+ * @return bool
*/
- public static function getClassName()
+ public static function isA($type)
{
- return strtolower(array_slice(explode('\\', static::class), -1, 1)[0]);
+ return static::getClassName() === strtolower($type);
}
/**
- *Gets a limited-length version of the entities name.
+ * Gets a limited-length version of the entities name.
* @param int $length
* @return string
*/