public function findOpenWorkspaceIds(
        array $roleNames,
        array $workspaces,
        $toolName = null,
        $action = 'open',
        $orderedToolType = 0
    )
    {
        if (count($roleNames) === 0 || count($workspaces) === 0) {

            return array();
        } else {
            $dql = '
                SELECT DISTINCT w.id
                FROM Claroline\CoreBundle\Entity\Workspace\Workspace w
                JOIN w.orderedTools ot
                JOIN ot.tool t
                JOIN ot.rights r
                JOIN r.role rr
                WHERE w IN (:workspaces)
                AND rr.name IN (:roleNames)
                AND ot.type = :type
                AND EXISTS (
                    SELECT d
                    FROM Claroline\CoreBundle\Entity\Tool\ToolMaskDecoder d
                    WHERE d.tool = t
                    AND d.name = :action
                    AND BIT_AND(r.mask, d.value) = d.value
                )
            ';

            if ($toolName) {
                $dql .= 'AND t.name = :toolName';
            }

            $query = $this->_em->createQuery($dql);
            $query->setParameter('workspaces', $workspaces);
            $query->setParameter('roleNames', $roleNames);
            $query->setParameter('action', $action);
            $query->setParameter('type', $orderedToolType);

            if ($toolName) {
                $query->setParameter('toolName', $toolName);
            }

            return $query->getResult();
        }
    }