@@ -12,9 +12,9 @@ |
||
| 12 | 12 | protected $_records = null; |
| 13 | 13 | protected $_localCache; |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @return Record |
|
| 17 | - */ |
|
| 15 | + /** |
|
| 16 | + * @return Record |
|
| 17 | + */ |
|
| 18 | 18 | public function findOne($primary) { |
| 19 | 19 | if (!$this->_records) { |
| 20 | 20 | $this->getAll(); |
@@ -5,10 +5,10 @@ |
||
| 5 | 5 | class Auths extends Records |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @return self |
|
| 10 | - */ |
|
| 11 | - public function getCurrent() |
|
| 8 | + /** |
|
| 9 | + * @return self |
|
| 10 | + */ |
|
| 11 | + public function getCurrent() |
|
| 12 | 12 | { |
| 13 | 13 | $model = $this->getModel(); |
| 14 | 14 | if ($_SESSION[$model]) { |
@@ -5,61 +5,61 @@ |
||
| 5 | 5 | class Resources extends Records |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - protected $_sortOn = "name"; |
|
| 8 | + protected $_sortOn = "name"; |
|
| 9 | 9 | |
| 10 | - public function findAll() |
|
| 11 | - { |
|
| 12 | - if (!$this->getRegistry()->exists("all")) { |
|
| 13 | - $resources = parent::findAll(); |
|
| 14 | - $this->buildTree($resources); |
|
| 15 | - } |
|
| 10 | + public function findAll() |
|
| 11 | + { |
|
| 12 | + if (!$this->getRegistry()->exists("all")) { |
|
| 13 | + $resources = parent::findAll(); |
|
| 14 | + $this->buildTree($resources); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - return $this->getRegistry()->get('all'); |
|
| 18 | - } |
|
| 17 | + return $this->getRegistry()->get('all'); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function buildTree($resources = array()) |
|
| 21 | - { |
|
| 22 | - if ($resources) { |
|
| 23 | - /* @var $resource ACL_Resource */ |
|
| 24 | - foreach ($resources as $resource) { |
|
| 25 | - if ($resource->hasParent()) { |
|
| 26 | - $parent = $resources[$resource->id_parent]; |
|
| 27 | - $parent->addChild($resource); |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - } |
|
| 31 | - } |
|
| 20 | + public function buildTree($resources = array()) |
|
| 21 | + { |
|
| 22 | + if ($resources) { |
|
| 23 | + /* @var $resource ACL_Resource */ |
|
| 24 | + foreach ($resources as $resource) { |
|
| 25 | + if ($resource->hasParent()) { |
|
| 26 | + $parent = $resources[$resource->id_parent]; |
|
| 27 | + $parent->addChild($resource); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Recursively builds parents path to passed resource |
|
| 35 | - * |
|
| 36 | - * @param ACL_Resource|bool $page |
|
| 37 | - * @param array $return |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - public function buildPath($resource, &$return = array()) |
|
| 41 | - { |
|
| 42 | - if (!($resource instanceof ACL_Resource)) { |
|
| 43 | - return array_reverse($return); |
|
| 44 | - } |
|
| 33 | + /** |
|
| 34 | + * Recursively builds parents path to passed resource |
|
| 35 | + * |
|
| 36 | + * @param ACL_Resource|bool $page |
|
| 37 | + * @param array $return |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + public function buildPath($resource, &$return = array()) |
|
| 41 | + { |
|
| 42 | + if (!($resource instanceof ACL_Resource)) { |
|
| 43 | + return array_reverse($return); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $return[] = $resource; |
|
| 46 | + $return[] = $resource; |
|
| 47 | 47 | |
| 48 | - return $this->buildPath($resource->getParent(), $return); |
|
| 49 | - } |
|
| 48 | + return $this->buildPath($resource->getParent(), $return); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Singleton |
|
| 53 | - * |
|
| 54 | - * @return ACL_Resources |
|
| 55 | - */ |
|
| 56 | - public static function instance() |
|
| 57 | - { |
|
| 58 | - static $instance; |
|
| 59 | - if (!($instance instanceof self)) { |
|
| 60 | - $instance = new self(); |
|
| 61 | - } |
|
| 62 | - return $instance; |
|
| 63 | - } |
|
| 51 | + /** |
|
| 52 | + * Singleton |
|
| 53 | + * |
|
| 54 | + * @return ACL_Resources |
|
| 55 | + */ |
|
| 56 | + public static function instance() |
|
| 57 | + { |
|
| 58 | + static $instance; |
|
| 59 | + if (!($instance instanceof self)) { |
|
| 60 | + $instance = new self(); |
|
| 61 | + } |
|
| 62 | + return $instance; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
| 66 | 66 | \ No newline at end of file |
@@ -5,89 +5,89 @@ |
||
| 5 | 5 | class Resource extends Record |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @var ACL_Resource |
|
| 10 | - */ |
|
| 11 | - protected $_parent; |
|
| 12 | - protected $_children = array(); |
|
| 13 | - protected $_pathString; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * @param ACL_Resource $resource |
|
| 17 | - */ |
|
| 18 | - public function addChild($resource) |
|
| 19 | - { |
|
| 20 | - $this->_children[$resource->id] = $resource; |
|
| 21 | - $resource->setParent($this); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function hasParent() |
|
| 25 | - { |
|
| 26 | - return $this->id_parent > 0; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function hasChildren() |
|
| 30 | - { |
|
| 31 | - return count($this->_children) > 0; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return ACL_Resource |
|
| 36 | - */ |
|
| 37 | - public function getParent() |
|
| 38 | - { |
|
| 39 | - if (!$this->_parent) { |
|
| 40 | - if ($this->hasParent()) { |
|
| 41 | - $parent = $this->getManager()->findOne($this->id_parent); |
|
| 42 | - $parent->addChild($this); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $this->_parent; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function getChildren() |
|
| 50 | - { |
|
| 51 | - return $this->_children; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function getPath() |
|
| 55 | - { |
|
| 56 | - return $this->getManager()->buildPath($this); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function getPathString() |
|
| 60 | - { |
|
| 61 | - if (!$this->_pathString) { |
|
| 62 | - $this->_pathString = implode(".", Nip_Helper_Array::instance()->pluck($this->getPath(), "slug")); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $this->_pathString; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param ACL_Resource $parent |
|
| 70 | - * @return ACL_Resource |
|
| 71 | - */ |
|
| 72 | - public function setParent(ACL_Resource $parent) |
|
| 73 | - { |
|
| 74 | - $this->_parent = $parent; |
|
| 75 | - return $this; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function getACL() |
|
| 79 | - { |
|
| 80 | - return ACL::instance(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function insertPermission($role, $type) |
|
| 84 | - { |
|
| 85 | - return $this->getACL()->insertPermission($this, $role, $type); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function removePermissions() |
|
| 89 | - { |
|
| 90 | - return $this->getACL()->removePermissions(false, $this); |
|
| 91 | - } |
|
| 8 | + /** |
|
| 9 | + * @var ACL_Resource |
|
| 10 | + */ |
|
| 11 | + protected $_parent; |
|
| 12 | + protected $_children = array(); |
|
| 13 | + protected $_pathString; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * @param ACL_Resource $resource |
|
| 17 | + */ |
|
| 18 | + public function addChild($resource) |
|
| 19 | + { |
|
| 20 | + $this->_children[$resource->id] = $resource; |
|
| 21 | + $resource->setParent($this); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function hasParent() |
|
| 25 | + { |
|
| 26 | + return $this->id_parent > 0; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function hasChildren() |
|
| 30 | + { |
|
| 31 | + return count($this->_children) > 0; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return ACL_Resource |
|
| 36 | + */ |
|
| 37 | + public function getParent() |
|
| 38 | + { |
|
| 39 | + if (!$this->_parent) { |
|
| 40 | + if ($this->hasParent()) { |
|
| 41 | + $parent = $this->getManager()->findOne($this->id_parent); |
|
| 42 | + $parent->addChild($this); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $this->_parent; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function getChildren() |
|
| 50 | + { |
|
| 51 | + return $this->_children; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function getPath() |
|
| 55 | + { |
|
| 56 | + return $this->getManager()->buildPath($this); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function getPathString() |
|
| 60 | + { |
|
| 61 | + if (!$this->_pathString) { |
|
| 62 | + $this->_pathString = implode(".", Nip_Helper_Array::instance()->pluck($this->getPath(), "slug")); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $this->_pathString; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param ACL_Resource $parent |
|
| 70 | + * @return ACL_Resource |
|
| 71 | + */ |
|
| 72 | + public function setParent(ACL_Resource $parent) |
|
| 73 | + { |
|
| 74 | + $this->_parent = $parent; |
|
| 75 | + return $this; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function getACL() |
|
| 79 | + { |
|
| 80 | + return ACL::instance(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function insertPermission($role, $type) |
|
| 84 | + { |
|
| 85 | + return $this->getACL()->insertPermission($this, $role, $type); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function removePermissions() |
|
| 89 | + { |
|
| 90 | + return $this->getACL()->removePermissions(false, $this); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | } |
| 94 | 94 | \ No newline at end of file |
@@ -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 |