Converts a role object into an array for the rest service.

@param RoleInterface $role

@return array
10828
protected function convertRole(RoleInterface $role)
    {
        $roleData['id'] = $role->getId();
        $roleData['name'] = $role->getName();
        $roleData['identifier'] = $role->getIdentifier();
        $roleData['system'] = $role->getSystem();
        $roleData['permissions'] = [];

        $permissions = $role->getPermissions();
        if (!empty($permissions)) {
            foreach ($permissions as $permission) {
                /* @var Permission $permission */
                $roleData['permissions'][] = [
                    'id' => $permission->getId(),
                    'context' => $permission->getContext(),
                    'module' => $permission->getModule(),
                    'permissions' => $this->get('sulu_security.mask_converter')
                        ->convertPermissionsToArray($permission->getPermissions()),
                ];
            }
        }

        $securityType = $role->getSecurityType();
        if ($securityType) {
            $roleData['securityType'] = [
                'id' => $securityType->getId(),
                'name' => $securityType->getName(),
            ];
        }

        return $roleData;
    }
197854
public function getRole($role = null)
    {
        /* @var $roleItem RoleInterface */
        foreach ($this->roles as $roleItem) {
            if ($role == $roleItem->getRole()) {
                return $roleItem;
            }
        }

        return null;
    }
876229
public function getGroups($role = 'all')
	{
		static $groups;

		if (!isset($groups))
		{
			$groups = array(
				'applicants' => array(),
				'invitees'   => array(),
				'members'    => array(),
				'managers'   => array(),
				'all'        => array()
			);
			$groups['all'] = Helper::getGroups($this->get('uidNumber'), 'all', 1);

			if ($groups['all'])
			{
				foreach ($groups['all'] as $item)
				{
					if ($item->registered)
					{
						if (!$item->regconfirmed)
						{
							$groups['applicants'][] = $item;
						}
						else
						{
							if ($item->manager)
							{
								$groups['managers'][] = $item;
							}
							else
							{
								$groups['members'][] = $item;
							}
						}
					}
					else
					{
						$groups['invitees'][] = $item;
					}
				}
			}
		}

		if ($role)
		{
			return (isset($groups[$role])) ? $groups[$role] : false;
		}

		return $groups;
	}
501249
private function normalizeRoleList (array $roles)
    {
        $normalized = [];

        foreach ($roles as $role)
        {
            $roleKey = (is_object($role) && ($role instanceof BaseRole))
                ? $role->getRole()
                : (string) $role;

            if (isset($this->roleCollection[$roleKey]))
            {
                $normalized[] = $this->roleCollection[$roleKey];
            }
        }

        return $normalized;
    }
781384
protected function convertRoles($roles)
    {
        if ($roles instanceof Traversable) {
            $roles = iterator_to_array($roles);
        }

        $collectedRoles = [];
        $toCollect      = [];

        foreach ((array) $roles as $role) {
            // If it's already a RoleInterface, nothing to do as a RoleInterface contains everything already
            if ($role instanceof RoleInterface) {
                $collectedRoles[] = $role;
                continue;
            }

            // Otherwise, it's a string and hence we need to collect it
            $toCollect[] = (string) $role;
        }

        // Nothing to collect, we don't even need to hit the (potentially) costly role provider
        if (empty($toCollect)) {
            return $collectedRoles;
        }

        return array_merge($collectedRoles, $this->roleProvider->getRoles($toCollect));
    }
565871
public static function getRoleACL($role)
    {
        global $PPHP;
        $db = $PPHP['db'];

        $flat = $db->selectArray(
            "
            SELECT action, objectType, objectId
            FROM acl_roles
            WHERE role=?
            ",
            array($role)
        );
        return is_array($flat) ? $flat : array();
    }
1004792
public function permissionFetchByRole(Role $role)
    {
        $query = "
            SELECT
                p.permission_id, p.name, p.description
            FROM
                auth_permission p
            LEFT JOIN
                auth_role_permissions r ON r.permission_id = p.permission_id
            WHERE r.role_id = :role_id
        ";
        $cur = $this->db->prepare($query);
        $cur->bindParam(":role_id", $role->role_id, PDO::PARAM_INT);
        try {
            $cur->execute();
            $permissions = $cur->fetchAll(PDO::FETCH_CLASS, self::CLASS_PERMISSION);
        } catch (PDOException $db_err) {
            if ($this->logger) {
                $this->logger->error("Error trying to fetch role permissions", ['exception' => $db_err]);
            }
            return [];
        }
        return $permissions;
    }
293801
public function getByName(string $role): ?IRole
    {
        if (null === $this->roles) {
            $this->getAll();
        }

        if (!isset($this->names[$role])) {
            return null;
        }

        return $this->roles[$this->names[$role]];
    }
1158934
public function grantAccessByRole($role, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();
        return in_array($role, $user->getRoles());
    }
558616
public static function getRoleUsers($role)
    {
        global $PPHP;
        $db = $PPHP['db'];

        $out = $db->selectList(
            "
            SELECT userId FROM users_roles
            WHERE role=?
            ORDER BY userId ASC
            ",
            array($role)
        );
        return (is_array($out) ? $out : array());
    }
895525
public function getRole(string $id = null): array
    {
        if ($id) {
            if (is_numeric($id)) {
                $filter = array_filter($this->role, function ($row) use ($id) { return $row['id'] == $id; });
                return (array) array_pop($filter);
            }
            return (array) ($this->role[$id] ?? []);
        }
        return $this->role;
    }
625051
public function join(RoleInterface $role)
    {
        $this->roles()
            ->attach($role);

        return $this->is($role);
    }
1191852
public function addRole(RoleInterface $role)
    {
        $this->roles->add($role);

        if ($role->hasUser($this) === false)
            $role->addUser($this);

        return $this;
    }
878913
public static function fromAccount($role)
    {
        return $role instanceof RoleInterface
            ? new self(ClassUtils::getClass($role), $role->getName())
            : new self('role', $role);
    }
1266942
public function getUsersByRole($role)
    {
        if (is_array($role)) {
            $roles = $role;
        } else {
            $roles = array($role);
        }

        $qb = $this->getEntityManager()->createQueryBuilder();
        $qb->select('u')
            ->from('KunstmaanAdminBundle:User', 'u')
            ->innerJoin('u.groups', 'g')
            ->innerJoin('g.roles', 'r')
            ->where('u.enabled=1')
            ->andWhere('r.role IN (:roles)')
            ->setParameter('roles', $roles);

        return $qb->getQuery()->getResult();
    }
1364359
public function destroy(Role $role)
    {
        $role->delete();

        return intend([
            'url' => route('managerarea.roles.index'),
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/auth::common.role'), 'identifier' => $role->title])],
        ]);
    }
569749
public function getRolePermissions(Role $role)
    {
        $key = $this->getRoleKey($role);

        // If we've saved the caller permissions we don't need to fetch them again.
        if (array_key_exists($key, $this->rolePermissions)) {
            return $this->rolePermissions[$key];
        }

        $results = $this->getTable()->where('role', $role->getRoleName())->get()->toArray();

        return $this->rolePermissions[$key] = PermissionFactory::createFromData($results);
    }