Get acl.

@param string|null $idRole
@param string|null $idResource
@return array
494884
public function getAcl(string $idRole = null, string $idResource = null): array
    {
        if ($idRole) {
            $callback = function ($row) use ($idRole, $idResource) {
                if ($idRole && $idResource) {
                    return $row['id_role'] == $idRole && $row['id_resource'] == $idResource;
                }
                if ($idRole) {
                    return $row['id_role'] == $idRole;
                }
                return true;
            };
            return array_filter($this->acl, $callback);
        }
        return $this->acl;
    }
1354529
public function getRightsValues($id, $isRole = false)
    {
        $translator = $this->serviceLocator->get('translator');
        /** @var \MelisCore\Service\MelisCoreUserService $melisCoreUser */
        $melisCoreUser = $this->getServiceLocator()->get('MelisCoreUser');
        if (!$isRole) {

            $xml = $melisCoreUser->getUserXmlRights($id);
        } else {
            $xml = '';
            $tableUserRole = $this->serviceLocator->get('MelisCoreTableUserRole');
            $datasRole = $tableUserRole->getEntryById($id);
            if ($datasRole) {
                $datasRole = $datasRole->current();
                if (!empty($datasRole)) {
                    $xml = $datasRole->urole_rights;
                }
            }
        }

        $selectedRootInterface = $melisCoreUser->isItemRightChecked($xml, self::MELISCORE_PREFIX_INTERFACE, self::MELISCORE_PREFIX_INTERFACE . '_root');
        $selectedRootTools = $melisCoreUser->isItemRightChecked($xml, self::MELIS_PLATFORM_TOOLS_PREFIX, self::MELIS_PLATFORM_TOOLS_PREFIX . '_root');

        $rightsItems = [
            [
                'key' => self::MELISCORE_PREFIX_INTERFACE . '_root',
                'title' => $translator->translate('tr_meliscore_rights_Interface exclusion'),
                'lazy' => false,
                'selected' => $selectedRootInterface,
                'iconTab' => '',
                'melisData' => [
                    'colorSelected' => '#CB4040',
                ],
            ],
            [
                'key' => self::MELIS_PLATFORM_TOOLS_PREFIX . '_root',
                'title' => $translator->translate('tr_meliscore_rights_Tools'),
                'lazy' => false,
                'selected' => $selectedRootTools,
                'iconTab' => '',
                'melisData' => [
                    'colorSelected' => '#99C975',
                ],
            ],
        ];

        // interface rights
        $interfaceItems = [];
        $config = $this->getServiceLocator()->get('config');
        foreach ($config['plugins'] as $pluginName => $plugin) {
            $child = $this->getInterfaceKeysRecursive('/' . $pluginName, $xml);
            if ($child) {
                $interfaceItems[] = $child;
            }
        }
        $rightsItems[0]['children'] = $interfaceItems;


        // tools rights
        $toolsItems = $this->getToolsKeys($xml);
        $rightsItems[1]['children'] = $toolsItems;

        // Return values
        return $rightsItems;
    }
574850
public function actionAssignRole($idOrEmail, $role)
    {
        if (!$user = $this->findUser($idOrEmail)) {
            return self::EXIT_CODE_ERROR;
        }
        $rbac = Podium::getInstance()->getRbac();
        if (!$role = $rbac->getRole($role)) {
            $this->stderr('No such role.' . PHP_EOL);
            return self::EXIT_CODE_ERROR;
        }
        if (strpos($role->name, 'podium') === 0) {
            $this->setPodiumUserRole($user, $role);
        } else {
            $rbac->assign($role, $user->id);
        }
        $this->stdout("user#{$user->id} has role '{$role->name}'" . PHP_EOL);
    }
1115381
public function createXmlRightsValues($id, $datas, $isRole = false): array
    {
        /** @var \MelisCore\Service\MelisCoreConfigService $melisAppConfig */
        $melisAppConfig = $this->getServiceLocator()->get('MelisCoreConfig');
        $melisKeys = $melisAppConfig->getMelisKeys();

        /**
         * Core rights make no difference between user or userrole because
         * all nodes are shown, so we just need to check what was posted.
         * There's no lazy tree, so no need to compare whatever in the user or role xml
         * already existing.
         */
        $nodesSeen = Json::decode($datas['treeStatus']);
        $nodesSeen = $nodesSeen->treeStatus;
        $nodesInterface = Json::decode($datas[self::MELISCORE_PREFIX_INTERFACE . '_root']);
        $nodesTools = Json::decode($datas[self::MELIS_PLATFORM_TOOLS_PREFIX . '_root']);

        // Creating interface xml
        $interfaceNode = self::MELISCORE_PREFIX_INTERFACE . '_root';
        $xmlRights = '<' . self::MELISCORE_PREFIX_INTERFACE . '>' . self::XML_ENDLINE;
        if (!empty($nodesInterface) && !empty($nodesInterface->$interfaceNode)) {
            foreach ($nodesInterface->$interfaceNode as $idInterface) {
                if ($idInterface != $interfaceNode) {
                    $idUnPrefixed = str_replace(self::MELISCORE_PREFIX_INTERFACE . '_', '', $idInterface);
                } else {
                    $idUnPrefixed = $idInterface;
                }
                $xmlRights .= self::XML_SPACER . '<id>' . $idUnPrefixed . '</id>' . self::XML_ENDLINE;
            }
        }
        $xmlRights .= '</' . self::MELISCORE_PREFIX_INTERFACE . '>' . self::XML_ENDLINE;

        // Creating tools xml
        $toolsNode = self::MELIS_PLATFORM_TOOLS_PREFIX . '_root';
        $xmlRights .= '<' . self::MELIS_PLATFORM_TOOLS_PREFIX . '>' . self::XML_ENDLINE;

        // here we list all the available tool sections
        foreach ($this->getMelisKeyPaths() as $toolSection) {
            $xmlRights .=  self::XML_SPACER . '<' . $toolSection . '>' . self::XML_ENDLINE;
            if (!empty($nodesTools) && !empty($nodesTools->$toolsNode)) {
                foreach ($nodesTools->$toolsNode as $idTool) {
                    $parent = $this->getSectionParent($idTool) ?? null;

                    if (! $parent) {
                        // check if this tool ID exists in xml
                        if (! preg_match("/$idTool/", $xmlRights) && $idTool !== $toolsNode) {
                            $xmlRights .= self::XML_SPACER . self::XML_SPACER . '<noparent>' . $idTool . '</noparent>' . self::XML_ENDLINE;
                        }
                    } else {
                        if ($parent === $toolSection && $idTool !== $toolsNode) {
                            $id = $idTool === $parent ? $idTool . '_root' : $idTool;
                            $xmlRights .= self::XML_SPACER . self::XML_SPACER . '<id>' . $id . '</id>' . self::XML_ENDLINE;
                        }
                    }
                }
            }
            $xmlRights .=  self::XML_SPACER . '</' . $toolSection . '>' . self::XML_ENDLINE;
        }

        // for general business, if it's checked then we just saved its root
        if (!empty($nodesTools) && !empty($nodesTools->$toolsNode)) {
            foreach ($nodesTools->$toolsNode as $idTool) {
                if ($idTool === $toolsNode) {
                    $xmlRights .= self::XML_SPACER . '<id>' . $toolsNode . '</id>' . self::XML_ENDLINE;
                }
            }
        }

        $xmlRights .= '</' . self::MELIS_PLATFORM_TOOLS_PREFIX . '>' . self::XML_ENDLINE;

        return ['meliscore_rights' => $xmlRights];
    }
163223
public function getRoleId()
    {
        if ( null === $this->aclRoleId )
        {
            $this->aclRoleId = ( (int) $this->groupId )
                . '.' . ( (int) $this->id );
        }

        return $this->aclRoleId;
    }
358704
public function getRole(ConnectionInterface $con = null)
    {
        if ($this->aRole === null && ($this->role_id !== null)) {
            $this->aRole = ChildRoleQuery::create()->findPk($this->role_id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aRole->addUserRoles($this);
             */
        }

        return $this->aRole;
    }
211403
public function getRoles()
    {
        $roles = array();

        if ($this->acl) {
            foreach ($this->acl->getRoles() as $role) {
                //Do not translate, only make first one uppercase
                $roles[$role] = ucfirst($role);
            }
        }
        asort($roles);

        return $roles;
    }
626238
public function getId($idScope = null)
    {
        if (empty($idScope)) {
            if (!is_null($this->resourceLink)) {
                $idScope = $this->resourceLink->getConsumer()->id_scope;
            } else {
                $idScope = ToolProvider::ID_SCOPE_ID_ONLY;
            }
        }
        switch ($idScope) {
            case ToolProvider::ID_SCOPE_GLOBAL:
                $id = $this->resourceLink->getKey() . ToolProvider::ID_SCOPE_SEPARATOR . $this->id;
                break;
            case ToolProvider::ID_SCOPE_CONTEXT:
                $id = $this->resourceLink->getKey();
                if ($this->resourceLink->lti_context_id) {
                    $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->resourceLink->lti_context_id;
                }
                $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->id;
                break;
            case ToolProvider::ID_SCOPE_RESOURCE:
                $id = $this->resourceLink->getKey();
                if ($this->resourceLink->lti_resource_id) {
                    $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->resourceLink->lti_resource_id;
                }
                $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->id;
                break;
            default:
                $id = $this->id;
                break;
        }

        return $id;
    }
118533
protected function getAuthorizationRoles(AuthorizationContract $acl)
    {
        return collect($acl->roles()->get())->reject(function ($role) {
            return in_array($role, ['guest']);
        })->map(function ($slug) {
            $name = Str::humanize($slug);

            return compact('slug', 'name');
        });
    }
184898
@GET
  @Path("/db/{authorizerName}/roles")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  @ResourceFilters(BasicSecurityResourceFilter.class)
  public Response getAllRoles(
      @Context HttpServletRequest req,
      @PathParam("authorizerName") final String authorizerName
  )
  {
    return resourceHandler.getAllRoles(authorizerName);
  }
1344788
public function grantRoleAccess(RoleInterface $role, ResourceInterface $resource, string $action)
    {
        $resourcePermissions = $this->getGroupPermissions($resource);
        $matchedPermission = null;

        //
        // 1. Check to see if the role, or its parents already have access.  Don't pollute the database.
        //
        $examinedRole = $role;
        while ($examinedRole) {
            foreach ($resourcePermissions as $permission) {
                if ($role === $permission->getRole()) {
                    $matchedPermission = $permission;
                }

                if ($permission->can($action)) {
                    throw new ExistingAccessException($role, $resource, $action, $permission->getRole()->getName());
                }
            }
            $examinedRole = $examinedRole->getParent();
        }

        //
        // 2. Give access
        //
        if (!$matchedPermission) {
            $newPermission = $this->groupPermissions->create($role, $resource->getClass(), $resource->getId(), [$action]);
            $this->groupPermissions->save($newPermission);
        } else {
            $matchedPermission->addAction($action);
            $this->groupPermissions->update($matchedPermission);

        }
    }
843861
public function findUsersByRolesIncludingGroups(
        array $roles,
        $executeQuery = true
    )
    {
        $dql = "
            SELECT u, r1, g, r2, ws
            From Claroline\CoreBundle\Entity\User u
            LEFT JOIN u.roles r1
            LEFT JOIN u.personalWorkspace ws
            LEFT JOIN u.groups g
            LEFT JOIN g.roles r2
            WHERE (r1 in (:roles)
            OR r2 in (:roles))
            AND u.isEnabled = true
            ORDER BY u.lastName, u.firstName ASC";

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roles', $roles);

        return ($executeQuery) ? $query->getResult() : $query;
    }
517891
public function getResourcePermissions(ResourceInterface $resource) : array
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->getQuery();

        return $query->getResult();
    }
1193129
public function getRoleParents($role, $onlyParents = true) {
        $parents = array();
        if (Zend_Registry::isRegistered('Zend_Acl')) {
            $acl = Zend_Registry::get('Zend_Acl');
            $roles = $acl->getRoles();

            foreach ($roles as $potentialParent) {
                if ($acl->inheritsRole($role, $potentialParent, $onlyParents)) {
                    $parents[] = $potentialParent;
                }
            }
        }
        return $parents;
    }
799696
public function getByRole($role_id)
    {
        foreach ($this->getHandlers() as $filter) {
            if (in_array($role_id, (array) $filter['role_id'])) {
                return $filter;
            }
        }

        return array();
    }
858226
@Override
	public String[] getUsersInRole(String role) {
		if (role_list.containsKey(role)) {
			return role_list.get(role).toArray(new String[0]);
		} else {
			return new String[0];
		}
	}
798334
public function getFilterOptions($idList, $usedOnly, &$arrCount = null)
    {
        if (!$this->isFilterOptionRetrievingPossible($idList)) {
            return [];
        }

        $strDisplayValue    = $this->getValueColumn();
        $strSortingValue    = $this->getSortingColumn();
        $strCurrentLanguage = null;

        // Change language.
        if (TL_MODE == 'BE') {
            $strCurrentLanguage     = $GLOBALS['TL_LANGUAGE'];
            $GLOBALS['TL_LANGUAGE'] = $this->getMetaModel()->getActiveLanguage();
        }

        $filter = $this->getSelectMetaModel()->getEmptyFilter();

        $this->buildFilterRulesForFilterSetting($filter);

        // Add some more filter rules.
        if ($usedOnly || ($idList && \is_array($idList))) {
            $this->buildFilterRulesForUsedOnly($filter, $idList ?: []);
        }

        $objItems = $this->getSelectMetaModel()->findByFilter($filter, $strSortingValue);

        // Reset language.
        if (TL_MODE == 'BE') {
            $GLOBALS['TL_LANGUAGE'] = $strCurrentLanguage;
        }

        return $this->convertItemsToFilterOptions(
            $objItems,
            $strDisplayValue,
            $this->getAliasColumn(),
            $arrCount,
            $idList
        );
    }