main/core/Repository/ResourceRightsRepository.php
public function findMaximumRights(array $roles, ResourceNode $resource)
    {
        //add the role anonymous for everyone !
        if (!in_array('ROLE_ANONYMOUS', $roles)) {
            $roles[] = 'ROLE_ANONYMOUS';
        }

        $dql = '
            SELECT rrw.mask
            FROM Claroline\CoreBundle\Entity\Resource\ResourceRights rrw
            JOIN rrw.role role
            JOIN rrw.resourceNode resource
            WHERE ';

        $index = 0;

        foreach ($roles as $key => $role) {
            $dql .= 0 !== $index ? ' OR ' : '';
            $dql .= "resource.id = {$resource->getId()} AND role.name = :role{$key}";
            ++$index;
        }

        $query = $this->_em->createQuery($dql);

        foreach ($roles as $key => $role) {
            $query->setParameter("role{$key}", $role);
        }

        $results = $query->getResult();
        $mask = 0;

        foreach ($results as $result) {
            $mask |= $result['mask'];
        }

        return $mask;
    }
public function findMaximumRights(array $roles, ResourceNode $resource)
    {
        //add the role anonymous for everyone !
        if (!in_array('ROLE_ANONYMOUS', $roles)) {
            $roles[] = 'ROLE_ANONYMOUS';
        }

        $dql = '
            SELECT rrw.mask
            FROM Claroline\CoreBundle\Entity\Resource\ResourceRights rrw
            JOIN rrw.role role
            JOIN rrw.resourceNode resource
            WHERE ';

        $index = 0;

        foreach ($roles as $key => $role) {
            $dql .= 0 !== $index ? ' OR ' : '';
            $dql .= "resource.id = {$resource->getId()} AND role.name = :role{$key}";
            ++$index;
        }

        $query = $this->_em->createQuery($dql);

        foreach ($roles as $key => $role) {
            $query->setParameter("role{$key}", $role);
        }

        $results = $query->getResult();
        $mask = 0;

        foreach ($results as $result) {
            $mask |= $result['mask'];
        }

        return $mask;
    }
public function findMaximumRights ( array $ roles , ResourceNode $ resource ) { //add the role anonymous for everyone ! if ( ! in_array ( 'ROLE_ANONYMOUS' , $ roles ) ) { $ roles [ ] = 'ROLE_ANONYMOUS' ; } $ dql = '
            SELECT rrw.mask
            FROM Claroline\CoreBundle\Entity\Resource\ResourceRights rrw
            JOIN rrw.role role
            JOIN rrw.resourceNode resource
            WHERE ' ; $ index = 0 ; foreach ( $ roles as $ key => $ role ) { $ dql .= 0 !== $ index ? ' OR ' : '' ; $ dql .= "resource.id = {$resource->getId()} AND role.name = :role{$key}" ; ++ $ index ; } $ query = $ this -> _em -> createQuery ( $ dql ) ; foreach ( $ roles as $ key => $ role ) { $ query -> setParameter ( "role{$key}" , $ role ) ; } $ results = $ query -> getResult ( ) ; $ mask = 0 ; foreach ( $ results as $ result ) { $ mask |= $ result [ 'mask' ] ; } return $ mask ; }
Returns the maximum rights on a given resource for a set of roles.
Used by the ResourceVoter.

@param array[string] $rights
@param ResourceNode  $resource

@return array
Returns the maximum rights on a given resource for a set of roles . Used by the ResourceVoter .