Returns a user role data
@param integer|null $role_id
342667
protected function setUserRole($role_id)
    {
        $this->data_role = array();

        if (is_numeric($role_id)) {

            $this->data_role = $this->role->get($role_id);

            if (empty($this->data_role)) {
                $this->outputHttpStatus(404);
            }
        }
    }
527898
def get_role(role_id,**kwargs):
    
    try:
        role = db.DBSession.query(Role).filter(Role.id==role_id).one()
        return role
    except NoResultFound:
        raise HydraError("Role not found (role_id={})".format(role_id))
379376
public function GetCountForRole($RoleID = '') {
      if (!is_array($RoleID))
         $RoleID = array($RoleID);
      
      return $this->SQL
         ->Select('a.ActivityID', 'count', 'ActivityCount')
         ->From('Activity a')
         ->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID')
         ->Join('UserRole ur', 'a.ActivityUserID = ur.UserID')
         ->WhereIn('ur.RoleID', $RoleID)
         ->Where('t.Public', '1')
         ->Get()
         ->FirstRow()
         ->ActivityCount;
   }
339889
public static function getRoleIdByAppIdAndUserId($app_id, $user_id)
    {
        $cacheKey = static::makeRoleIdCacheKey($app_id, $user_id);
        $result = \Cache::remember($cacheKey, \Config::get('df.default_cache_ttl'),
            function () use ($app_id, $user_id) {
                try {
                    return static::whereAppId($app_id)->whereUserId($user_id)->value('role_id');
                } catch (ModelNotFoundException $ex) {
                    return null;
                }
            });

        return $result;
    }
1025158
public function assign_role_to_user($roleid, $userid) {
        require_capability('moodle/role:assign', $this->context);
        if (!array_key_exists($roleid, $this->get_assignable_roles())) {
            if (defined('AJAX_SCRIPT')) {
                throw new moodle_exception('invalidrole');
            }
            return false;
        }
        return role_assign($roleid, $userid, $this->context->id, '', NULL);
    }
202009
public function removePermissionFromRole(int $permission_id, int $role_id)
    {

        $role = $this->getRole($role_id);
        $role->permissions()->detach($permission_id);

    }
620565
def _get_roles_query(self, session, identifier):
        
        return (session.query(Role).
                join(role_membership_table, Role.pk_id == role_membership_table.c.role_id).
                join(User, role_membership_table.c.user_id == User.pk_id).
                filter(User.identifier == identifier))
170999
def get(self, roleId):
        """"""
        role = db.Role.find_one(Role.role_id == roleId)

        if not role:
            return self.make_response('No such role found', HTTP.NOT_FOUND)

        return self.make_response({'role': role})
1228772
private function get_role_name($rid) {
        global $DB, $PAGE;
        $rec = $DB->get_record('role', array('id' => $rid));

        if ($rec) {
            return role_get_name($rec, $PAGE->context, ROLENAME_ALIAS);
        } else {
            return null;
        }
    }
342723
public function editRole($role_id)
    {

        // Get the role. We don't get the full one
        // as we need to mangle some of the data to
        // arrays for easier processing in the view
        $role = $this->getRole($role_id);

        $role_permissions = $role->permissions()->get()->pluck('title')->toArray();
        $role_affiliations = $role->affiliations();
        $role_groups = $role->groups()->get()->pluck('id')->toArray();
        $all_groups = $this->getAllGroups();
        $all_characters = $this->getAllCharacters();
        $all_corporations = $this->getAllCorporations();

        return view(
            'web::configuration.access.edit',
            compact(
                'role', 'role_permissions', 'role_groups', 'all_groups',
                'role_affiliations', 'all_characters', 'all_corporations'
            ));
    }
614907
public function Index($RoleID = NULL) {
		$this->Permission('Garden.Settings.Manage');

      $this->AddSideMenu('dashboard/role');
      $this->AddJsFile('jquery.tablednd.js');
      $this->AddJsFile('jquery-ui.js');
      $this->Title(T('Roles & Permissions'));
      
      if (!$RoleID)
         $RoleData = $this->RoleModel->Get()->ResultArray();
      else {
         $Role = $this->RoleModel->GetID($RoleID);
         $RoleData = array($Role);
      }
      
      $this->SetData('Roles', $RoleData);
      $this->Render();
   }
1045472
function fetchUserRole( $id )
    {
        $user = eZUser::fetch( $id );
        if ( $user instanceof eZUser )
            $roleList = $user->roles();
        else // user group or other non user classes:
            $roleList = eZRole::fetchByUser( array( $id ), true );

        $accessArray = array();
        foreach ( array_keys ( $roleList ) as $roleKey )
        {
            $role = $roleList[$roleKey];
            $accessArray = array_merge_recursive( $accessArray, $role->accessArray( true ) );
        }
        $resultArray = array();
        foreach ( $accessArray as $moduleKey => $module )
        {
            $moduleName = $moduleKey;
            if ( $moduleName != '*' )
            {
                foreach ( $module as $functionKey => $function )
                {
                    $functionName = $functionKey;
                    if ( $functionName != '*' )
                    {
                        $hasLimitation = true;
                        foreach ( $function as $limitationKey )
                        {
                            if ( $limitationKey == '*' )
                            {
                                $hasLimitation = false;
                                $limitationValue = '*';
                                $resultArray[] = array( 'moduleName' => $moduleName, 'functionName' => $functionName, 'limitation' =>  $limitationValue );
                            }
                        }
                        if ( $hasLimitation )
                        {
                            foreach ( $function as $limitationKey => $limitation )
                            {
                                if ( $limitationKey !== '*' )
                                {
                                    $policyID = str_replace( 'p_', '', $limitationKey );
                                    $userRoleIdSeperator = strpos( $policyID, '_' );

                                    if ( $userRoleIdSeperator !== false )
                                    {
                                        $policyID = substr( $policyID, 0, $userRoleIdSeperator );
                                    }

                                    $limitationValue = eZPolicyLimitation::fetchByPolicyID( $policyID );
                                    $resultArray[] = array( 'moduleName' => $moduleName, 'functionName' => $functionName, 'limitation' =>  $limitationValue );
                                }
                                else
                                {
                                    $limitationValue = '*';
                                    $resultArray[] = array( 'moduleName' => $moduleName, 'functionName' => $functionName, 'limitation' =>  $limitationValue );
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        $limitationValue = '*';
                        $resultArray[] = array( 'moduleName' => $moduleName, 'functionName' => $functionName, 'limitation' =>  $limitationValue );
                        break;
                    }
                }
            }
            else
            {
                $functionName = '*';
                $resultArray[] = array( 'moduleName' => '*', 'functionName' => $functionName, 'limitation' => '*' );
                break;
            }
        }
        return array( 'result' => $resultArray );
    }
743083
public function loadRoleDraftByRoleId($roleId)
    {
        $query = $this->handler->createSelectQuery();
        $query->select(
            $this->handler->aliasedColumn($query, 'id', 'ezrole'),
            $this->handler->aliasedColumn($query, 'name', 'ezrole'),
            $this->handler->aliasedColumn($query, 'version', 'ezrole'),
            $this->handler->aliasedColumn($query, 'id', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'function_name', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'module_name', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'original_id', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'identifier', 'ezpolicy_limitation'),
            $this->handler->aliasedColumn($query, 'value', 'ezpolicy_limitation_value')
        )->from(
            $this->handler->quoteTable('ezrole')
        )->leftJoin(
            $this->handler->quoteTable('ezpolicy'),
            $query->expr->eq(
                $this->handler->quoteColumn('role_id', 'ezpolicy'),
                $this->handler->quoteColumn('id', 'ezrole')
            )
        )->leftJoin(
            $this->handler->quoteTable('ezpolicy_limitation'),
            $query->expr->eq(
                $this->handler->quoteColumn('policy_id', 'ezpolicy_limitation'),
                $this->handler->quoteColumn('id', 'ezpolicy')
            )
        )->leftJoin(
            $this->handler->quoteTable('ezpolicy_limitation_value'),
            $query->expr->eq(
                $this->handler->quoteColumn('limitation_id', 'ezpolicy_limitation_value'),
                $this->handler->quoteColumn('id', 'ezpolicy_limitation')
            )
        )->where(
            $query->expr->eq(
                // Column name "version" is misleading as it stores originalId when creating a draft from an existing role.
                // But hey, this is legacy! :-)
                $this->handler->quoteColumn('version', 'ezrole'),
                $query->bindValue($roleId, null, \PDO::PARAM_STR)
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
639547
public function getRole($role) {
		
		if(false === is_string($role)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR);
		}

		foreach($this -> permissions as $type => $resources) {

			if($role === $type) {
				
				$p = new Resources();
				$p -> setResources($resources);

				return $p;
			}
		}

		return null;
	}
308838
public function GetForRole($RoleID = '', $Offset = '0', $Limit = '50') {
      if (!is_array($RoleID))
         $RoleID = array($RoleID);
      
      $Offset = is_numeric($Offset) ? $Offset : 0;
      if ($Offset < 0)
         $Offset = 0;

      $Limit = is_numeric($Limit) ? $Limit : 0;
      if ($Limit < 0)
         $Limit = 0;
      
      $this->ActivityQuery();
      $Result = $this->SQL
         ->Join('UserRole ur', 'a.ActivityUserID = ur.UserID')
         ->WhereIn('ur.RoleID', $RoleID)
         ->Where('t.Public', '1')
         ->OrderBy('a.DateInserted', 'desc')
         ->Limit($Limit, $Offset)
         ->Get();
         
      $this->EventArguments['Data'] =& $Result;
      $this->FireEvent('AfterGet');
      
      return $Result;
   }
254156
public function findAllUsersByRoleId($roleId)
    {
        $qb = $this->createQueryBuilder('user')
            ->leftJoin('user.userRoles', 'userRole')
            ->leftJoin('userRole.role', 'role')
            ->where('role=:roleId');

        $query = $qb->getQuery();
        $query->setParameter('roleId', $roleId);

        return $query->getResult();
    }
1105211
public function loadRoleDraftByRoleId($roleId)
    {
        $data = $this->roleGateway->loadRoleDraftByRoleId($roleId);

        if (empty($data)) {
            throw new RoleNotFound($roleId, Role::STATUS_DRAFT);
        }

        $role = $this->mapper->mapRole($data);
        foreach ($role->policies as $policy) {
            $this->limitationConverter->toSPI($policy);
        }

        return $role;
    }