123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
-
- namespace Luticate\Auth\Business;
-
- use Luticate\Utils\LuBusiness;
- use Luticate\Auth\DataAccess\LuticatePermissionsDataAccess;
- use Luticate\Auth\DBO\LuticatePermissionsDbo;
- use Luticate\Utils\LuMultipleDbo;
-
- class LuticatePermissionsBusiness extends LuBusiness {
- protected static function getDataAccess()
- {
- return new LuticatePermissionsDataAccess();
- }
-
- public static function checkPermissionName($permission_name)
- {
- $perm = LuticatePermissionsDataAccess::getByName($permission_name);
- if (is_null($perm)) {
- self::notFound("Permission not found");
- }
- return $perm;
- }
-
- public static function getEffectivePermission($user_id, $permission_name)
- {
- self::checkPermissionName($permission_name);
- $val = LuticatePermissionsDataAccess::getEffectivePermission($user_id, $permission_name);
- $perm = new LuticatePermissionsDbo();
- $perm->setValue($val);
- $perm->setName($permission_name);
- return $perm;
- }
-
- public static function getAllEffectivePermission($user_id)
- {
- $values = LuticatePermissionsDataAccess::getAllEffectivePermission($user_id);
- $dbos = [];
- foreach ($values as $value) {
- $dbo = new LuticatePermissionsDbo();
- $dbo->setName($value->getPermissonName());
- $dbo->setValue($value->getVal());
- $dbos[] = $dbo;
- }
- return new LuMultipleDbo(count($dbos), $dbos);
- }
-
- public static function getEffectiveDynamicPermission($user_id, $permission_name, $resource_id)
- {
- $dynamic_permission_name = "LU_DYN_" . $permission_name . "_" . $resource_id;
- $val = self::getEffectivePermission($user_id, $dynamic_permission_name);
- if (is_null($val->getValue())) {
- return self::getEffectivePermission($user_id, $permission_name);
- }
- return $val;
- }
-
- public static function get($permission_name)
- {
- $perm = LuticatePermissionsDataAccess::getByName($permission_name);
- if (is_null($perm)) {
- self::notFound("Permission not found");
- }
- return $perm;
- }
-
- public static function add($permission_name, $permission_value)
- {
- $perm = LuticatePermissionsDataAccess::getByName($permission_name);
- if (is_null($perm)) {
- $perm = new LuticatePermissionsDbo();
- $perm->setName($permission_name);
- $perm->setValue($permission_value);
- LuticatePermissionsDataAccess::add($perm);
- return true;
- }
- self::badInput("Permission name already exists");
- return false;
- }
-
- public static function del($permission_name)
- {
- LuticatePermissionsDataAccess::delete($permission_name);
- return true;
- }
-
- public static function edit($permission_name, $permission_value)
- {
- self::checkPermissionName($permission_name);
- LuticatePermissionsDataAccess::edit($permission_name, $permission_value);
- return true;
- }
- }
|