diff --git a/Account/Account.php b/Account/Account.php index 32c6174af..b26249b62 100644 --- a/Account/Account.php +++ b/Account/Account.php @@ -207,6 +207,28 @@ class Account implements ArrayableInterface, \JsonSerializable $this->l11n = $l11n; } + public function setPermissions(array $permissions) /* : void */ + { + $this->permissions = $permissions; + } + + public function hasPermission(int $permission, int $unit = null, string $app = null, int $module = null, int $type = null, $element = null, $component = null) : bool + { + foreach($this->permissions as $p) { + if(($p->getUnit() === $unit || $p->getUnit() === null) + && ($p->getApp() === $app || $p->getApp() === null) + && ($p->getModule() === $module || $p->getModule() === null) + && ($p->getType() === $type || $p->getType() === null) + && ($p->getElement() === $element || $p->getElement() === null) + && ($p->getComponent() === $component || $p->getComponent() === null) + && ($p->getPermission() | $permission) === $p->getPermission()) { + return true; + } + } + + return false; + } + /** * Get name. * diff --git a/Account/PermissionAbstract.php b/Account/PermissionAbstract.php new file mode 100644 index 000000000..ee6736ea4 --- /dev/null +++ b/Account/PermissionAbstract.php @@ -0,0 +1,136 @@ +unit; + } + + public function getApp() + { + return $this->app; + } + + public function getModule() + { + return $this->module; + } + + public function getFrom() + { + return $this->from; + } + + public function getType() + { + return $this->type; + } + + public function getElement() + { + return $this->element; + } + + public function getComponent() + { + return $this->component; + } + + public function getPermission() : int + { + return $this->permission; + } + + public function setUnit(int $unit = null) /* : void */ + { + $this->unit = $unit; + } + + public function setApp(int $app = null) /* : void */ + { + $this->app = $app; + } + + public function setModule(int $module = null) /* : void */ + { + $this->module = $module; + } + + public function setFrom(int $from = null) /* : void */ + { + $this->from = $from; + } + + public function setType(int $type = null) /* : void */ + { + $this->type = $type; + } + + public function setElement(int $element = null) /* : void */ + { + $this->element = $element; + } + + public function setComponent(int $component = null) /* : void */ + { + $this->component = $component; + } + + public function setPermission(int $permission = 0) /* : void */ + { + if($permission === 0) { + $this->permission = 0; + } else { + $this->permission |= $permission; + } + } +}