@@ -5,18 +5,18 @@ |
||
| 5 | 5 | class Permissions extends Records |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * Singleton |
|
| 10 | - * |
|
| 11 | - * @return ACL_Permissions |
|
| 12 | - */ |
|
| 13 | - public static function instance() |
|
| 14 | - { |
|
| 15 | - static $instance; |
|
| 16 | - if (!($instance instanceof self)) { |
|
| 17 | - $instance = new self(); |
|
| 18 | - } |
|
| 19 | - return $instance; |
|
| 20 | - } |
|
| 8 | + /** |
|
| 9 | + * Singleton |
|
| 10 | + * |
|
| 11 | + * @return ACL_Permissions |
|
| 12 | + */ |
|
| 13 | + public static function instance() |
|
| 14 | + { |
|
| 15 | + static $instance; |
|
| 16 | + if (!($instance instanceof self)) { |
|
| 17 | + $instance = new self(); |
|
| 18 | + } |
|
| 19 | + return $instance; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -5,91 +5,91 @@ |
||
| 5 | 5 | class Role extends Record |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - public function insert() |
|
| 9 | - { |
|
| 10 | - parent::insert(); |
|
| 11 | - $this->insertPermissions(); |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - public function update($permissions = true) |
|
| 15 | - { |
|
| 16 | - if ($permissions) { |
|
| 17 | - $this->updatePermissions(); |
|
| 18 | - } |
|
| 19 | - parent::update(); |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public function delete() |
|
| 23 | - { |
|
| 24 | - $this->deletePermissions(); |
|
| 25 | - $this->deleteUsers(); |
|
| 26 | - parent::delete(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function insertPermission($resource, $type) |
|
| 30 | - { |
|
| 31 | - $this->getACL()->insertPermission($resource, $this, $type); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function insertPermissions() |
|
| 35 | - { |
|
| 36 | - if ($this->permissions) { |
|
| 37 | - foreach ($this->permissions as $resource => $types) { |
|
| 38 | - foreach ($types as $type => $value) { |
|
| 39 | - if (!$this->allowed($resource, $type)) { |
|
| 40 | - $this->getACL()->insertPermission($resource, $this, $type); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - return $this; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function deletePermissions($resource = false) |
|
| 49 | - { |
|
| 50 | - $this->getACL()->removePermissions($this, $resource); |
|
| 51 | - return $this; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function updatePermissions() |
|
| 55 | - { |
|
| 56 | - $this->deletePermissions(); |
|
| 57 | - $this->insertPermissions(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function allowed($resource, $type) |
|
| 61 | - { |
|
| 62 | - return $this->getACL()->check($this, $resource, $type); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getACL() |
|
| 66 | - { |
|
| 67 | - return ACL::instance(); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function getRoleID() |
|
| 71 | - { |
|
| 72 | - return get_class($this) . "." . $this->id; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function validate($request = array()) |
|
| 76 | - { |
|
| 77 | - $this->name = clean($request['name']); |
|
| 78 | - $this->permissions = $request['permission'] ? $request['permission'] : array(); |
|
| 79 | - |
|
| 80 | - $errors = array(); |
|
| 81 | - |
|
| 82 | - if (!$this->name) { |
|
| 83 | - $errors['name'] = 'Denumirea este obligatorie'; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $this->errors = $errors; |
|
| 87 | - |
|
| 88 | - if ($this->errors) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return true; |
|
| 93 | - } |
|
| 8 | + public function insert() |
|
| 9 | + { |
|
| 10 | + parent::insert(); |
|
| 11 | + $this->insertPermissions(); |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + public function update($permissions = true) |
|
| 15 | + { |
|
| 16 | + if ($permissions) { |
|
| 17 | + $this->updatePermissions(); |
|
| 18 | + } |
|
| 19 | + parent::update(); |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + public function delete() |
|
| 23 | + { |
|
| 24 | + $this->deletePermissions(); |
|
| 25 | + $this->deleteUsers(); |
|
| 26 | + parent::delete(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function insertPermission($resource, $type) |
|
| 30 | + { |
|
| 31 | + $this->getACL()->insertPermission($resource, $this, $type); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function insertPermissions() |
|
| 35 | + { |
|
| 36 | + if ($this->permissions) { |
|
| 37 | + foreach ($this->permissions as $resource => $types) { |
|
| 38 | + foreach ($types as $type => $value) { |
|
| 39 | + if (!$this->allowed($resource, $type)) { |
|
| 40 | + $this->getACL()->insertPermission($resource, $this, $type); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + return $this; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function deletePermissions($resource = false) |
|
| 49 | + { |
|
| 50 | + $this->getACL()->removePermissions($this, $resource); |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function updatePermissions() |
|
| 55 | + { |
|
| 56 | + $this->deletePermissions(); |
|
| 57 | + $this->insertPermissions(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function allowed($resource, $type) |
|
| 61 | + { |
|
| 62 | + return $this->getACL()->check($this, $resource, $type); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getACL() |
|
| 66 | + { |
|
| 67 | + return ACL::instance(); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function getRoleID() |
|
| 71 | + { |
|
| 72 | + return get_class($this) . "." . $this->id; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function validate($request = array()) |
|
| 76 | + { |
|
| 77 | + $this->name = clean($request['name']); |
|
| 78 | + $this->permissions = $request['permission'] ? $request['permission'] : array(); |
|
| 79 | + |
|
| 80 | + $errors = array(); |
|
| 81 | + |
|
| 82 | + if (!$this->name) { |
|
| 83 | + $errors['name'] = 'Denumirea este obligatorie'; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $this->errors = $errors; |
|
| 87 | + |
|
| 88 | + if ($this->errors) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return true; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | } |
| 96 | 96 | \ No newline at end of file |