@@ -3,47 +3,47 @@ |
||
| 3 | 3 | class Nip_Config |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - protected $_data; |
|
| 6 | + protected $_data; |
|
| 7 | 7 | |
| 8 | - public function parse($filename) |
|
| 9 | - { |
|
| 10 | - $config = parse_ini_file($filename, true); |
|
| 11 | - foreach ($config as $key => $value) { |
|
| 12 | - if (is_array($value)) { |
|
| 13 | - if (!isset($this->_data[$key])) { |
|
| 14 | - $this->_data[$key] = new stdClass; |
|
| 15 | - } |
|
| 16 | - foreach ($value as $subKey => $subValue) { |
|
| 17 | - $this->_data[$key]->$subKey = $subValue; |
|
| 18 | - } |
|
| 19 | - } else { |
|
| 20 | - $this->_data[$key] = $value; |
|
| 21 | - } |
|
| 22 | - } |
|
| 23 | - return $this; |
|
| 24 | - } |
|
| 8 | + public function parse($filename) |
|
| 9 | + { |
|
| 10 | + $config = parse_ini_file($filename, true); |
|
| 11 | + foreach ($config as $key => $value) { |
|
| 12 | + if (is_array($value)) { |
|
| 13 | + if (!isset($this->_data[$key])) { |
|
| 14 | + $this->_data[$key] = new stdClass; |
|
| 15 | + } |
|
| 16 | + foreach ($value as $subKey => $subValue) { |
|
| 17 | + $this->_data[$key]->$subKey = $subValue; |
|
| 18 | + } |
|
| 19 | + } else { |
|
| 20 | + $this->_data[$key] = $value; |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | + return $this; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function __get($name) |
|
| 27 | - { |
|
| 28 | - return $this->_data[$name]; |
|
| 29 | - } |
|
| 26 | + public function __get($name) |
|
| 27 | + { |
|
| 28 | + return $this->_data[$name]; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function __isset($name) |
|
| 32 | - { |
|
| 33 | - return isset($this->_data[$name]); |
|
| 34 | - } |
|
| 31 | + public function __isset($name) |
|
| 32 | + { |
|
| 33 | + return isset($this->_data[$name]); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Singleton |
|
| 38 | - * |
|
| 39 | - * @return Nip_Config |
|
| 40 | - */ |
|
| 41 | - static public function instance() |
|
| 42 | - { |
|
| 43 | - static $instance; |
|
| 44 | - if (!($instance instanceof self)) { |
|
| 45 | - $instance = new self(); |
|
| 46 | - } |
|
| 47 | - return $instance; |
|
| 48 | - } |
|
| 36 | + /** |
|
| 37 | + * Singleton |
|
| 38 | + * |
|
| 39 | + * @return Nip_Config |
|
| 40 | + */ |
|
| 41 | + static public function instance() |
|
| 42 | + { |
|
| 43 | + static $instance; |
|
| 44 | + if (!($instance instanceof self)) { |
|
| 45 | + $instance = new self(); |
|
| 46 | + } |
|
| 47 | + return $instance; |
|
| 48 | + } |
|
| 49 | 49 | } |
| 50 | 50 | \ No newline at end of file |
@@ -3,35 +3,35 @@ |
||
| 3 | 3 | class ACL_Permission extends Record |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - protected $_resource; |
|
| 7 | - protected $_role; |
|
| 6 | + protected $_resource; |
|
| 7 | + protected $_role; |
|
| 8 | 8 | |
| 9 | - public function setResource(ACL_Resource $resource) |
|
| 10 | - { |
|
| 11 | - $this->_resource = $resource; |
|
| 12 | - $this->id_acl_resource = ACL::instance()->getResourcePathString($resource); |
|
| 13 | - } |
|
| 9 | + public function setResource(ACL_Resource $resource) |
|
| 10 | + { |
|
| 11 | + $this->_resource = $resource; |
|
| 12 | + $this->id_acl_resource = ACL::instance()->getResourcePathString($resource); |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - public function getResource() |
|
| 16 | - { |
|
| 17 | - if (!$this->_resource) { |
|
| 18 | - $this->_resource = ACL::instance()->getResource($this->id_acl_resource); |
|
| 19 | - } |
|
| 20 | - return $this->_resource; |
|
| 21 | - } |
|
| 15 | + public function getResource() |
|
| 16 | + { |
|
| 17 | + if (!$this->_resource) { |
|
| 18 | + $this->_resource = ACL::instance()->getResource($this->id_acl_resource); |
|
| 19 | + } |
|
| 20 | + return $this->_resource; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function setRole(ACL_Role $role) |
|
| 24 | - { |
|
| 25 | - $this->_role = $role; |
|
| 26 | - $this->id_acl_role = ACL::instance()->getRoleID($role); |
|
| 27 | - } |
|
| 23 | + public function setRole(ACL_Role $role) |
|
| 24 | + { |
|
| 25 | + $this->_role = $role; |
|
| 26 | + $this->id_acl_role = ACL::instance()->getRoleID($role); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function getRole() |
|
| 30 | - { |
|
| 31 | - if (!$this->_role) { |
|
| 32 | - $this->_role = ACL::instance()->getRole($this->id_acl_role); |
|
| 33 | - } |
|
| 34 | - return $this->_role; |
|
| 35 | - } |
|
| 29 | + public function getRole() |
|
| 30 | + { |
|
| 31 | + if (!$this->_role) { |
|
| 32 | + $this->_role = ACL::instance()->getRole($this->id_acl_role); |
|
| 33 | + } |
|
| 34 | + return $this->_role; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | class ACL_Permissions extends Records |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * Singleton |
|
| 8 | - * |
|
| 9 | - * @return ACL_Permissions |
|
| 10 | - */ |
|
| 11 | - public static function instance() |
|
| 12 | - { |
|
| 13 | - static $instance; |
|
| 14 | - if (!($instance instanceof self)) { |
|
| 15 | - $instance = new self(); |
|
| 16 | - } |
|
| 17 | - return $instance; |
|
| 18 | - } |
|
| 6 | + /** |
|
| 7 | + * Singleton |
|
| 8 | + * |
|
| 9 | + * @return ACL_Permissions |
|
| 10 | + */ |
|
| 11 | + public static function instance() |
|
| 12 | + { |
|
| 13 | + static $instance; |
|
| 14 | + if (!($instance instanceof self)) { |
|
| 15 | + $instance = new self(); |
|
| 16 | + } |
|
| 17 | + return $instance; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | 20 | } |
| 21 | 21 | \ No newline at end of file |
@@ -3,61 +3,61 @@ |
||
| 3 | 3 | class ACL_Resources extends Records |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - protected $_sortOn = "name"; |
|
| 7 | - |
|
| 8 | - public function findAll() |
|
| 9 | - { |
|
| 10 | - if (!$this->getRegistry()->exists("all")) { |
|
| 11 | - $resources = parent::findAll(); |
|
| 12 | - $this->buildTree($resources); |
|
| 13 | - } |
|
| 14 | - |
|
| 15 | - return $this->getRegistry()->get('all'); |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - public function buildTree($resources = array()) |
|
| 19 | - { |
|
| 20 | - if ($resources) { |
|
| 21 | - /* @var $resource ACL_Resource */ |
|
| 22 | - foreach ($resources as $resource) { |
|
| 23 | - if ($resource->hasParent()) { |
|
| 24 | - $parent = $resources[$resource->id_parent]; |
|
| 25 | - $parent->addChild($resource); |
|
| 26 | - } |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Recursively builds parents path to passed resource |
|
| 33 | - * |
|
| 34 | - * @param ACL_Resource|bool $page |
|
| 35 | - * @param array $return |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 38 | - public function buildPath($resource, &$return = array()) |
|
| 39 | - { |
|
| 40 | - if (!($resource instanceof ACL_Resource)) { |
|
| 41 | - return array_reverse($return); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $return[] = $resource; |
|
| 45 | - |
|
| 46 | - return $this->buildPath($resource->getParent(), $return); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Singleton |
|
| 51 | - * |
|
| 52 | - * @return ACL_Resources |
|
| 53 | - */ |
|
| 54 | - public static function instance() |
|
| 55 | - { |
|
| 56 | - static $instance; |
|
| 57 | - if (!($instance instanceof self)) { |
|
| 58 | - $instance = new self(); |
|
| 59 | - } |
|
| 60 | - return $instance; |
|
| 61 | - } |
|
| 6 | + protected $_sortOn = "name"; |
|
| 7 | + |
|
| 8 | + public function findAll() |
|
| 9 | + { |
|
| 10 | + if (!$this->getRegistry()->exists("all")) { |
|
| 11 | + $resources = parent::findAll(); |
|
| 12 | + $this->buildTree($resources); |
|
| 13 | + } |
|
| 14 | + |
|
| 15 | + return $this->getRegistry()->get('all'); |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + public function buildTree($resources = array()) |
|
| 19 | + { |
|
| 20 | + if ($resources) { |
|
| 21 | + /* @var $resource ACL_Resource */ |
|
| 22 | + foreach ($resources as $resource) { |
|
| 23 | + if ($resource->hasParent()) { |
|
| 24 | + $parent = $resources[$resource->id_parent]; |
|
| 25 | + $parent->addChild($resource); |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Recursively builds parents path to passed resource |
|
| 33 | + * |
|
| 34 | + * @param ACL_Resource|bool $page |
|
| 35 | + * @param array $return |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | + public function buildPath($resource, &$return = array()) |
|
| 39 | + { |
|
| 40 | + if (!($resource instanceof ACL_Resource)) { |
|
| 41 | + return array_reverse($return); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $return[] = $resource; |
|
| 45 | + |
|
| 46 | + return $this->buildPath($resource->getParent(), $return); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Singleton |
|
| 51 | + * |
|
| 52 | + * @return ACL_Resources |
|
| 53 | + */ |
|
| 54 | + public static function instance() |
|
| 55 | + { |
|
| 56 | + static $instance; |
|
| 57 | + if (!($instance instanceof self)) { |
|
| 58 | + $instance = new self(); |
|
| 59 | + } |
|
| 60 | + return $instance; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | \ No newline at end of file |
@@ -3,89 +3,89 @@ |
||
| 3 | 3 | class ACL_Resource extends Record |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * @var ACL_Resource |
|
| 8 | - */ |
|
| 9 | - protected $_parent; |
|
| 10 | - protected $_children = array(); |
|
| 11 | - protected $_pathString; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * @param ACL_Resource $resource |
|
| 15 | - */ |
|
| 16 | - public function addChild($resource) |
|
| 17 | - { |
|
| 18 | - $this->_children[$resource->id] = $resource; |
|
| 19 | - $resource->setParent($this); |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public function hasParent() |
|
| 23 | - { |
|
| 24 | - return $this->id_parent > 0; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public function hasChildren() |
|
| 28 | - { |
|
| 29 | - return count($this->_children) > 0; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @return ACL_Resource |
|
| 34 | - */ |
|
| 35 | - public function getParent() |
|
| 36 | - { |
|
| 37 | - if (!$this->_parent) { |
|
| 38 | - if ($this->hasParent()) { |
|
| 39 | - $parent = $this->getManager()->findOne($this->id_parent); |
|
| 40 | - $parent->addChild($this); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return $this->_parent; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function getChildren() |
|
| 48 | - { |
|
| 49 | - return $this->_children; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function getPath() |
|
| 53 | - { |
|
| 54 | - return $this->getManager()->buildPath($this); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function getPathString() |
|
| 58 | - { |
|
| 59 | - if (!$this->_pathString) { |
|
| 60 | - $this->_pathString = implode(".", Nip_Helper_Array::instance()->pluck($this->getPath(), "slug")); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $this->_pathString; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param ACL_Resource $parent |
|
| 68 | - * @return ACL_Resource |
|
| 69 | - */ |
|
| 70 | - public function setParent(ACL_Resource $parent) |
|
| 71 | - { |
|
| 72 | - $this->_parent = $parent; |
|
| 73 | - return $this; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function getACL() |
|
| 77 | - { |
|
| 78 | - return ACL::instance(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function insertPermission($role, $type) |
|
| 82 | - { |
|
| 83 | - return $this->getACL()->insertPermission($this, $role, $type); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function removePermissions() |
|
| 87 | - { |
|
| 88 | - return $this->getACL()->removePermissions(false, $this); |
|
| 89 | - } |
|
| 6 | + /** |
|
| 7 | + * @var ACL_Resource |
|
| 8 | + */ |
|
| 9 | + protected $_parent; |
|
| 10 | + protected $_children = array(); |
|
| 11 | + protected $_pathString; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * @param ACL_Resource $resource |
|
| 15 | + */ |
|
| 16 | + public function addChild($resource) |
|
| 17 | + { |
|
| 18 | + $this->_children[$resource->id] = $resource; |
|
| 19 | + $resource->setParent($this); |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + public function hasParent() |
|
| 23 | + { |
|
| 24 | + return $this->id_parent > 0; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + public function hasChildren() |
|
| 28 | + { |
|
| 29 | + return count($this->_children) > 0; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @return ACL_Resource |
|
| 34 | + */ |
|
| 35 | + public function getParent() |
|
| 36 | + { |
|
| 37 | + if (!$this->_parent) { |
|
| 38 | + if ($this->hasParent()) { |
|
| 39 | + $parent = $this->getManager()->findOne($this->id_parent); |
|
| 40 | + $parent->addChild($this); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return $this->_parent; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function getChildren() |
|
| 48 | + { |
|
| 49 | + return $this->_children; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function getPath() |
|
| 53 | + { |
|
| 54 | + return $this->getManager()->buildPath($this); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function getPathString() |
|
| 58 | + { |
|
| 59 | + if (!$this->_pathString) { |
|
| 60 | + $this->_pathString = implode(".", Nip_Helper_Array::instance()->pluck($this->getPath(), "slug")); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $this->_pathString; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param ACL_Resource $parent |
|
| 68 | + * @return ACL_Resource |
|
| 69 | + */ |
|
| 70 | + public function setParent(ACL_Resource $parent) |
|
| 71 | + { |
|
| 72 | + $this->_parent = $parent; |
|
| 73 | + return $this; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function getACL() |
|
| 77 | + { |
|
| 78 | + return ACL::instance(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function insertPermission($role, $type) |
|
| 82 | + { |
|
| 83 | + return $this->getACL()->insertPermission($this, $role, $type); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function removePermissions() |
|
| 87 | + { |
|
| 88 | + return $this->getACL()->removePermissions(false, $this); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | \ No newline at end of file |
@@ -3,20 +3,20 @@ |
||
| 3 | 3 | class ACL_Roles extends Records |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - protected $_hasMany = array("Users"); |
|
| 6 | + protected $_hasMany = array("Users"); |
|
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * Singleton |
|
| 10 | - * |
|
| 11 | - * @return ACL_Roles |
|
| 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_Roles |
|
| 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 |
@@ -3,91 +3,91 @@ |
||
| 3 | 3 | class ACL_Role extends Record |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - public function insert() |
|
| 7 | - { |
|
| 8 | - parent::insert(); |
|
| 9 | - $this->insertPermissions(); |
|
| 10 | - } |
|
| 11 | - |
|
| 12 | - public function update($permissions = true) |
|
| 13 | - { |
|
| 14 | - if ($permissions) { |
|
| 15 | - $this->updatePermissions(); |
|
| 16 | - } |
|
| 17 | - parent::update(); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - public function delete() |
|
| 21 | - { |
|
| 22 | - $this->deletePermissions(); |
|
| 23 | - $this->deleteUsers(); |
|
| 24 | - parent::delete(); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public function insertPermission($resource, $type) |
|
| 28 | - { |
|
| 29 | - $this->getACL()->insertPermission($resource, $this, $type); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function insertPermissions() |
|
| 33 | - { |
|
| 34 | - if ($this->permissions) { |
|
| 35 | - foreach ($this->permissions as $resource => $types) { |
|
| 36 | - foreach ($types as $type => $value) { |
|
| 37 | - if (!$this->allowed($resource, $type)) { |
|
| 38 | - $this->getACL()->insertPermission($resource, $this, $type); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - return $this; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function deletePermissions($resource = false) |
|
| 47 | - { |
|
| 48 | - $this->getACL()->removePermissions($this, $resource); |
|
| 49 | - return $this; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function updatePermissions() |
|
| 53 | - { |
|
| 54 | - $this->deletePermissions(); |
|
| 55 | - $this->insertPermissions(); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function allowed($resource, $type) |
|
| 59 | - { |
|
| 60 | - return $this->getACL()->check($this, $resource, $type); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function getACL() |
|
| 64 | - { |
|
| 65 | - return ACL::instance(); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function getRoleID() |
|
| 69 | - { |
|
| 70 | - return get_class($this) . "." . $this->id; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function validate($request = array()) |
|
| 74 | - { |
|
| 75 | - $this->name = clean($request['name']); |
|
| 76 | - $this->permissions = $request['permission'] ? $request['permission'] : array(); |
|
| 77 | - |
|
| 78 | - $errors = array(); |
|
| 79 | - |
|
| 80 | - if (!$this->name) { |
|
| 81 | - $errors['name'] = 'Denumirea este obligatorie'; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $this->errors = $errors; |
|
| 85 | - |
|
| 86 | - if ($this->errors) { |
|
| 87 | - return false; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return true; |
|
| 91 | - } |
|
| 6 | + public function insert() |
|
| 7 | + { |
|
| 8 | + parent::insert(); |
|
| 9 | + $this->insertPermissions(); |
|
| 10 | + } |
|
| 11 | + |
|
| 12 | + public function update($permissions = true) |
|
| 13 | + { |
|
| 14 | + if ($permissions) { |
|
| 15 | + $this->updatePermissions(); |
|
| 16 | + } |
|
| 17 | + parent::update(); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + public function delete() |
|
| 21 | + { |
|
| 22 | + $this->deletePermissions(); |
|
| 23 | + $this->deleteUsers(); |
|
| 24 | + parent::delete(); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + public function insertPermission($resource, $type) |
|
| 28 | + { |
|
| 29 | + $this->getACL()->insertPermission($resource, $this, $type); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function insertPermissions() |
|
| 33 | + { |
|
| 34 | + if ($this->permissions) { |
|
| 35 | + foreach ($this->permissions as $resource => $types) { |
|
| 36 | + foreach ($types as $type => $value) { |
|
| 37 | + if (!$this->allowed($resource, $type)) { |
|
| 38 | + $this->getACL()->insertPermission($resource, $this, $type); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + return $this; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function deletePermissions($resource = false) |
|
| 47 | + { |
|
| 48 | + $this->getACL()->removePermissions($this, $resource); |
|
| 49 | + return $this; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function updatePermissions() |
|
| 53 | + { |
|
| 54 | + $this->deletePermissions(); |
|
| 55 | + $this->insertPermissions(); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function allowed($resource, $type) |
|
| 59 | + { |
|
| 60 | + return $this->getACL()->check($this, $resource, $type); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function getACL() |
|
| 64 | + { |
|
| 65 | + return ACL::instance(); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function getRoleID() |
|
| 69 | + { |
|
| 70 | + return get_class($this) . "." . $this->id; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function validate($request = array()) |
|
| 74 | + { |
|
| 75 | + $this->name = clean($request['name']); |
|
| 76 | + $this->permissions = $request['permission'] ? $request['permission'] : array(); |
|
| 77 | + |
|
| 78 | + $errors = array(); |
|
| 79 | + |
|
| 80 | + if (!$this->name) { |
|
| 81 | + $errors['name'] = 'Denumirea este obligatorie'; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $this->errors = $errors; |
|
| 85 | + |
|
| 86 | + if ($this->errors) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | } |
| 94 | 94 | \ No newline at end of file |
@@ -3,207 +3,207 @@ |
||
| 3 | 3 | class ACL |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - protected $_resources; |
|
| 7 | - protected $_roles; |
|
| 8 | - protected $_permissions; |
|
| 9 | - protected $_permissionMap; |
|
| 10 | - protected $_permissionTypes = array("view", "edit", "delete"); |
|
| 11 | - |
|
| 12 | - public function addResource($resource) |
|
| 13 | - { |
|
| 14 | - $this->_resources[$this->getResourcePathString($resource)] = $resource; |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - public function addRole($role) |
|
| 18 | - { |
|
| 19 | - $this->_roles[$this->getRoleID($role)] = $role; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Adds $type acces for $role to $resource |
|
| 24 | - * |
|
| 25 | - * @param mixed $resource |
|
| 26 | - * @param mixed $role |
|
| 27 | - * @param string $type |
|
| 28 | - */ |
|
| 29 | - public function addPermission($resource, $role, $type = "view") |
|
| 30 | - { |
|
| 31 | - $resource = $this->getResource($resource); |
|
| 32 | - $role = $this->getRole($role); |
|
| 33 | - $this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)][$type] = true; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Stores $type access for $role to $resource |
|
| 38 | - * Checks to see if permission already exists before insertion |
|
| 39 | - * |
|
| 40 | - * @param mixed $resource |
|
| 41 | - * @param mixed $role |
|
| 42 | - * @param string $type |
|
| 43 | - */ |
|
| 44 | - public function insertPermission($resource, $role, $type) |
|
| 45 | - { |
|
| 46 | - if (!$this->check($role, $resource, $type)) { |
|
| 47 | - $permission = ACL_Permissions::instance()->getNew(); |
|
| 48 | - |
|
| 49 | - $permission->setRole($this->getRole($role)); |
|
| 50 | - $permission->setResource($this->getResource($resource)); |
|
| 51 | - |
|
| 52 | - $permission->type = $type; |
|
| 53 | - $permission->insert(); |
|
| 54 | - |
|
| 55 | - $this->addPermission($resource, $role, $type); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Remove all permissions for $role [to $resource] |
|
| 61 | - * @param mixed $role |
|
| 62 | - */ |
|
| 63 | - public function removePermissions($role = false, $resource = false) |
|
| 64 | - { |
|
| 65 | - $permissions = $this->getPermissions($role, $resource); |
|
| 66 | - if ($permissions) { |
|
| 67 | - foreach ($permissions as $permission) { |
|
| 68 | - $permission->delete(); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - if ($role) { |
|
| 72 | - if ($resource) { |
|
| 73 | - unset($this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)]); |
|
| 74 | - } else { |
|
| 75 | - unset($this->_permissionMap[$this->getRoleID($role)]); |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - if ($resource) { |
|
| 79 | - foreach ($this->_permissionMap as $roleID => $resources) { |
|
| 80 | - unset($this->_permissionMap[$roleID][$this->getResourcePathString($resource)]); |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Checks if $role has $type acces to $resource |
|
| 88 | - * |
|
| 89 | - * @param mixed $role |
|
| 90 | - * @param mixed $resource |
|
| 91 | - * @param string $type |
|
| 92 | - * @return bool |
|
| 93 | - */ |
|
| 94 | - public function check($role, $resource, $type) |
|
| 95 | - { |
|
| 96 | - $role = $this->getRoleID($role); |
|
| 97 | - $resource = $this->getResourcePathString($resource); |
|
| 98 | - |
|
| 99 | - return $this->_permissionMap[$role][$resource][$type] == true; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param mixed $resource |
|
| 104 | - * @return ACL_Resource |
|
| 105 | - */ |
|
| 106 | - public function getResource($resource) |
|
| 107 | - { |
|
| 108 | - if (!($resource instanceof ACL_Resource)) { |
|
| 109 | - $resource = $this->_resources[$resource]; |
|
| 110 | - } |
|
| 111 | - return $resource; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - public function getResourcePathString($resource) |
|
| 115 | - { |
|
| 116 | - return $this->getResource($resource)->getPathString(); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function getRole($role) |
|
| 120 | - { |
|
| 121 | - if (!($role instanceof ACL_Role)) { |
|
| 122 | - $role = $this->_roles[$role]; |
|
| 123 | - } |
|
| 124 | - return $role; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function getRoleID($role) |
|
| 128 | - { |
|
| 129 | - return $this->getRole($role)->getRoleID(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function getPermissions($role = false, $resource = false) |
|
| 133 | - { |
|
| 134 | - if (!$this->_permissions) { |
|
| 135 | - $permissions = ACL_Permissions::instance()->findAll(); |
|
| 136 | - if ($permissions) { |
|
| 137 | - foreach ($permissions as $permission) { |
|
| 138 | - $this->addPermission($permission->id_acl_resource, $permission->id_acl_role, $permission->type); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - $this->_permissions = $permissions; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $return = array(); |
|
| 145 | - if ($this->_permissions) { |
|
| 146 | - foreach ($this->_permissions as $permission) { |
|
| 147 | - if ($role) { |
|
| 148 | - if ($permission->id_acl_role != $this->getRoleID($role)) { |
|
| 149 | - continue; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - if ($resource) { |
|
| 153 | - if ($permission->id_acl_resource != $this->getResourcePathString($resource)) { |
|
| 154 | - continue; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - $return[] = $permission; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - return $return; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - public function getResources() |
|
| 165 | - { |
|
| 166 | - if (!$this->_resources) { |
|
| 167 | - $resources = ACL_Resources::instance()->findAll(); |
|
| 168 | - if ($resources) { |
|
| 169 | - foreach ($resources as $resource) { |
|
| 170 | - $this->addResource($resource); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - return $this->_resources; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function getRoles() |
|
| 178 | - { |
|
| 179 | - if (!$this->_roles) { |
|
| 180 | - $roles = ACL_Roles::instance()->findAll(); |
|
| 181 | - |
|
| 182 | - if ($roles) { |
|
| 183 | - foreach ($roles as $role) { |
|
| 184 | - $this->addRole($role); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - return $this->_roles; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - public function getPermissionTypes() |
|
| 192 | - { |
|
| 193 | - return $this->_permissionTypes; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Singleton |
|
| 198 | - * @return ACL |
|
| 199 | - */ |
|
| 200 | - public static function instance() |
|
| 201 | - { |
|
| 202 | - static $instance; |
|
| 203 | - if (!($instance instanceof self)) { |
|
| 204 | - $instance = new self(); |
|
| 205 | - } |
|
| 206 | - return $instance; |
|
| 207 | - } |
|
| 6 | + protected $_resources; |
|
| 7 | + protected $_roles; |
|
| 8 | + protected $_permissions; |
|
| 9 | + protected $_permissionMap; |
|
| 10 | + protected $_permissionTypes = array("view", "edit", "delete"); |
|
| 11 | + |
|
| 12 | + public function addResource($resource) |
|
| 13 | + { |
|
| 14 | + $this->_resources[$this->getResourcePathString($resource)] = $resource; |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + public function addRole($role) |
|
| 18 | + { |
|
| 19 | + $this->_roles[$this->getRoleID($role)] = $role; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Adds $type acces for $role to $resource |
|
| 24 | + * |
|
| 25 | + * @param mixed $resource |
|
| 26 | + * @param mixed $role |
|
| 27 | + * @param string $type |
|
| 28 | + */ |
|
| 29 | + public function addPermission($resource, $role, $type = "view") |
|
| 30 | + { |
|
| 31 | + $resource = $this->getResource($resource); |
|
| 32 | + $role = $this->getRole($role); |
|
| 33 | + $this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)][$type] = true; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Stores $type access for $role to $resource |
|
| 38 | + * Checks to see if permission already exists before insertion |
|
| 39 | + * |
|
| 40 | + * @param mixed $resource |
|
| 41 | + * @param mixed $role |
|
| 42 | + * @param string $type |
|
| 43 | + */ |
|
| 44 | + public function insertPermission($resource, $role, $type) |
|
| 45 | + { |
|
| 46 | + if (!$this->check($role, $resource, $type)) { |
|
| 47 | + $permission = ACL_Permissions::instance()->getNew(); |
|
| 48 | + |
|
| 49 | + $permission->setRole($this->getRole($role)); |
|
| 50 | + $permission->setResource($this->getResource($resource)); |
|
| 51 | + |
|
| 52 | + $permission->type = $type; |
|
| 53 | + $permission->insert(); |
|
| 54 | + |
|
| 55 | + $this->addPermission($resource, $role, $type); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Remove all permissions for $role [to $resource] |
|
| 61 | + * @param mixed $role |
|
| 62 | + */ |
|
| 63 | + public function removePermissions($role = false, $resource = false) |
|
| 64 | + { |
|
| 65 | + $permissions = $this->getPermissions($role, $resource); |
|
| 66 | + if ($permissions) { |
|
| 67 | + foreach ($permissions as $permission) { |
|
| 68 | + $permission->delete(); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + if ($role) { |
|
| 72 | + if ($resource) { |
|
| 73 | + unset($this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)]); |
|
| 74 | + } else { |
|
| 75 | + unset($this->_permissionMap[$this->getRoleID($role)]); |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + if ($resource) { |
|
| 79 | + foreach ($this->_permissionMap as $roleID => $resources) { |
|
| 80 | + unset($this->_permissionMap[$roleID][$this->getResourcePathString($resource)]); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Checks if $role has $type acces to $resource |
|
| 88 | + * |
|
| 89 | + * @param mixed $role |
|
| 90 | + * @param mixed $resource |
|
| 91 | + * @param string $type |
|
| 92 | + * @return bool |
|
| 93 | + */ |
|
| 94 | + public function check($role, $resource, $type) |
|
| 95 | + { |
|
| 96 | + $role = $this->getRoleID($role); |
|
| 97 | + $resource = $this->getResourcePathString($resource); |
|
| 98 | + |
|
| 99 | + return $this->_permissionMap[$role][$resource][$type] == true; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param mixed $resource |
|
| 104 | + * @return ACL_Resource |
|
| 105 | + */ |
|
| 106 | + public function getResource($resource) |
|
| 107 | + { |
|
| 108 | + if (!($resource instanceof ACL_Resource)) { |
|
| 109 | + $resource = $this->_resources[$resource]; |
|
| 110 | + } |
|
| 111 | + return $resource; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + public function getResourcePathString($resource) |
|
| 115 | + { |
|
| 116 | + return $this->getResource($resource)->getPathString(); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function getRole($role) |
|
| 120 | + { |
|
| 121 | + if (!($role instanceof ACL_Role)) { |
|
| 122 | + $role = $this->_roles[$role]; |
|
| 123 | + } |
|
| 124 | + return $role; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function getRoleID($role) |
|
| 128 | + { |
|
| 129 | + return $this->getRole($role)->getRoleID(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function getPermissions($role = false, $resource = false) |
|
| 133 | + { |
|
| 134 | + if (!$this->_permissions) { |
|
| 135 | + $permissions = ACL_Permissions::instance()->findAll(); |
|
| 136 | + if ($permissions) { |
|
| 137 | + foreach ($permissions as $permission) { |
|
| 138 | + $this->addPermission($permission->id_acl_resource, $permission->id_acl_role, $permission->type); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + $this->_permissions = $permissions; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $return = array(); |
|
| 145 | + if ($this->_permissions) { |
|
| 146 | + foreach ($this->_permissions as $permission) { |
|
| 147 | + if ($role) { |
|
| 148 | + if ($permission->id_acl_role != $this->getRoleID($role)) { |
|
| 149 | + continue; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + if ($resource) { |
|
| 153 | + if ($permission->id_acl_resource != $this->getResourcePathString($resource)) { |
|
| 154 | + continue; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + $return[] = $permission; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + return $return; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + public function getResources() |
|
| 165 | + { |
|
| 166 | + if (!$this->_resources) { |
|
| 167 | + $resources = ACL_Resources::instance()->findAll(); |
|
| 168 | + if ($resources) { |
|
| 169 | + foreach ($resources as $resource) { |
|
| 170 | + $this->addResource($resource); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + return $this->_resources; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function getRoles() |
|
| 178 | + { |
|
| 179 | + if (!$this->_roles) { |
|
| 180 | + $roles = ACL_Roles::instance()->findAll(); |
|
| 181 | + |
|
| 182 | + if ($roles) { |
|
| 183 | + foreach ($roles as $role) { |
|
| 184 | + $this->addRole($role); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + return $this->_roles; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + public function getPermissionTypes() |
|
| 192 | + { |
|
| 193 | + return $this->_permissionTypes; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Singleton |
|
| 198 | + * @return ACL |
|
| 199 | + */ |
|
| 200 | + public static function instance() |
|
| 201 | + { |
|
| 202 | + static $instance; |
|
| 203 | + if (!($instance instanceof self)) { |
|
| 204 | + $instance = new self(); |
|
| 205 | + } |
|
| 206 | + return $instance; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | } |
| 210 | 210 | \ No newline at end of file |
@@ -12,42 +12,42 @@ |
||
| 12 | 12 | return $minutes; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - public function secondsInStringTime($seconds) |
|
| 16 | - { |
|
| 17 | - if ($days = intval((floor($seconds / 86400)))) { |
|
| 15 | + public function secondsInStringTime($seconds) |
|
| 16 | + { |
|
| 17 | + if ($days = intval((floor($seconds / 86400)))) { |
|
| 18 | 18 | $seconds = $seconds - $days*86400; |
| 19 | - $return .= ($return ? ' ' : '') . str_pad($days, 2, 0,STR_PAD_LEFT).'d'; |
|
| 20 | - } |
|
| 21 | - if ($hours = intval((floor($seconds / 3600))) OR $return) { |
|
| 19 | + $return .= ($return ? ' ' : '') . str_pad($days, 2, 0,STR_PAD_LEFT).'d'; |
|
| 20 | + } |
|
| 21 | + if ($hours = intval((floor($seconds / 3600))) OR $return) { |
|
| 22 | 22 | $seconds = $seconds - $hours*3600; |
| 23 | - $return .= ($return ? ' ' : '') . str_pad($hours, 2, 0,STR_PAD_LEFT).'h'; |
|
| 24 | - } |
|
| 25 | - if ($minutes = intval((floor($seconds / 60))) OR $return) { |
|
| 26 | - $seconds = $seconds - $minutes*60; |
|
| 27 | - $return .= ($return ? ' ' : '') . str_pad($minutes, 2, 0, STR_PAD_LEFT).'m'; |
|
| 28 | - } |
|
| 23 | + $return .= ($return ? ' ' : '') . str_pad($hours, 2, 0,STR_PAD_LEFT).'h'; |
|
| 24 | + } |
|
| 25 | + if ($minutes = intval((floor($seconds / 60))) OR $return) { |
|
| 26 | + $seconds = $seconds - $minutes*60; |
|
| 27 | + $return .= ($return ? ' ' : '') . str_pad($minutes, 2, 0, STR_PAD_LEFT).'m'; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - $seconds = round($seconds, 2); |
|
| 30 | + $seconds = round($seconds, 2); |
|
| 31 | 31 | if ($seconds) { |
| 32 | 32 | $return .= ($return ? ' ' : '') . str_pad($seconds, 2, 0, STR_PAD_LEFT).'s'; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - return $return; |
|
| 36 | - } |
|
| 35 | + return $return; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Singleton |
|
| 41 | - * |
|
| 42 | - * @return Nip_Helper_Date |
|
| 43 | - */ |
|
| 44 | - static public function instance() |
|
| 45 | - { |
|
| 46 | - static $instance; |
|
| 47 | - if (!($instance instanceof self)) { |
|
| 48 | - $instance = new self(); |
|
| 49 | - } |
|
| 50 | - return $instance; |
|
| 51 | - } |
|
| 39 | + /** |
|
| 40 | + * Singleton |
|
| 41 | + * |
|
| 42 | + * @return Nip_Helper_Date |
|
| 43 | + */ |
|
| 44 | + static public function instance() |
|
| 45 | + { |
|
| 46 | + static $instance; |
|
| 47 | + if (!($instance instanceof self)) { |
|
| 48 | + $instance = new self(); |
|
| 49 | + } |
|
| 50 | + return $instance; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | } |