Returns the groups which are member of a workspace.

@param Workspace $workspace
@param bool      $executeQuery

@return array[Group]|Query
760505
public function findByWorkspace(Workspace $workspace, $executeQuery = true)
    {
        $dql = '
            SELECT g, wr
            FROM Claroline\CoreBundle\Entity\Group g
            LEFT JOIN g.roles wr WITH wr IN (
                SELECT pr from Claroline\CoreBundle\Entity\Role pr WHERE pr.type = :type
            )
            LEFT JOIN wr.workspace w
            WHERE w.id = :workspaceId
       ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('workspaceId', $workspace->getId());
        $query->setParameter('type', Role::WS_ROLE);

        return $executeQuery ? $query->getResult() : $query;
    }
948740
public function findAllUserRoles($executeQuery = true)
    {
        $dql = '
            SELECT r
            FROM Claroline\CoreBundle\Entity\Role r
            WHERE r.type = :type
        ';

        $query = $this->_em->createQuery($dql);
        $query->setParameter('type', Role::USER_ROLE);

        return $executeQuery ? $query->getResult() : $query;
    }
160966
public function workspaceEditFormAction(Workspace $workspace)
    {
        $user = $this->tokenStorage->getToken()->getUser();
        $this->checkAccess($workspace);
        $username = is_null($workspace->getCreator()) ? '' : $workspace->getCreator()->getUsername();
        $creationDate = is_null($workspace->getCreationDate()) ? null : $this->utilities->intlDateFormat(
            $workspace->getCreationDate()
        );
        $expDate = is_null($workspace->getEndDate()) ? null : $this->utilities->intlDateFormat(
            $workspace->getEndDate()
        );
        $count = $this->workspaceManager->countUsers($workspace, true);
        $storageUsed = $this->workspaceManager->getUsedStorage($workspace);
        $storageUsed = $this->utilities->formatFileSize($storageUsed);
        $countResources = $this->workspaceManager->countResources($workspace);
        $workspaceAdminTool = $this->toolManager->getAdminToolByName('workspace_management');
        $isAdmin = $this->authorization->isGranted('OPEN', $workspaceAdminTool);

        $form = $this->formFactory->create(
            FormFactory::TYPE_WORKSPACE_EDIT,
            array(
                $username,
                $creationDate,
                $count,
                $storageUsed,
                $countResources,
                $isAdmin,
                $expDate
            ),
            $workspace
        );

        if ($workspace->getSelfRegistration()) {
            $url = $this->router->generate(
                'claro_workspace_subscription_url_generate',
                array('workspace' => $workspace->getId()),
                true
            );
        } else {
            $url = '';
        }

        return array(
            'form' => $form->createView(),
            'workspace' => $workspace,
            'url' => $url,
            'user' => $user,
            'count' => $count
        );
    }
513052
public function findUserRoleByUsername($username, $executeQuery = true)
    {
        $query = $this->_em
            ->createQuery('
                SELECT r
                FROM Claroline\CoreBundle\Entity\Role r
                WHERE r.type = :type
                AND r.name = :name
                AND r.translationKey = :key
            ')
            ->setParameter('type', Role::USER_ROLE)
            ->setParameter('name', 'ROLE_USER_'.strtoupper($username))
            ->setParameter('key', $username);

        return $executeQuery ? $query->getOneOrNullResult() : $query;
    }
815449
public function getGroupsByWorkspaceAndName(Workspace $workspace, $search, $page, $max = 50)
    {
        $query = $this->groupRepo->findByWorkspaceAndName($workspace, $search, false);

        return $this->pagerFactory->createPager($query, $page, $max);
    }
1137886
public function findAllByGroupQuery(GroupInterface $group, bool $active = true): Query
    {
        $qb = $this->createQueryBuilder('r');

        return $qb
            ->join('r.groups', 'g')

            // Add conditions.
            ->andWhere($qb->expr()->eq('g', ':group'))
            ->andWhere($qb->expr()->eq('r.active', ':active'))

            // Add parameters.
            ->setParameter('group', $group)
            ->setParameter('active', $active)

            // Order by and get results.
            ->orderBy('r.pinned', 'DESC')
            ->addOrderBy('r.name', 'ASC')
            ->getQuery();
    }
122159
public function findByWorkspaceAndSearch(
        Workspace $workspace,
        $search = '',
        $orderedBy = 'id',
        $order = 'ASC'
    ) {
        $dql = "
            SELECT r FROM Claroline\CoreBundle\Entity\Role r
            JOIN r.workspace ws
            WHERE ws.id = :workspaceId
            AND UPPER(r.translationKey) LIKE :search
            ORDER BY r.{$orderedBy} {$order}
        ";
        $query = $this->_em->createQuery($dql);
        $query->setParameter('workspaceId', $workspace->getId());
        $upperSearch = strtoupper($search);
        $query->setParameter('search', "%{$upperSearch}%");

        return $query->getResult();
    }
127061
public function findSent(User $user, $executeQuery = true)
    {
        $dql = "
            SELECT um, m, u
            FROM Claroline\MessageBundle\Entity\UserMessage um
            JOIN um.user u
            JOIN um.message m
            WHERE u.id = {$user->getId()}
            AND um.isRemoved = false
            AND um.isSent = true
            ORDER BY m.date DESC
        ";
        $query = $this->_em->createQuery($dql);

        return $executeQuery ? $query->getResult() : $query;
    }
211558
public function getRolesByWorkspace(
        Workspace $workspace,
        $search = '',
        $orderedBy = 'id',
        $order = 'ASC'
    ) {
        if (empty($search)) {
            return $this->roleRepo->findByWorkspace($workspace, $orderedBy, $order);
        } else {
            return $this->roleRepo->findByWorkspaceAndSearch(
                $workspace,
                $search,
                $orderedBy,
                $order
            );
        }
    }
757211
public function findByType($type, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('w')
            ->andWhere($this->getWigetInstanceString($type))
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
710770
public function getResourceGroups(Query $query = null) {
        if (!$query) {
            $query = new Query();
        }

        return $this->getCommand('GetResourceGroups', array(
            'page' => $query->page(),
            'limit' => $query->limit(),
        ))->execute();
    }
859805
public function openDeniedAction(Workspace $workspace, $action)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        //check the expiration date first
        $now = new \DateTime();
        $dateValidity = true;

        if ($workspace->getEndDate()) {
            if ($now->getTimeStamp() > $workspace->getEndDate()->getTimeStamp()) {
                $dateValidity = false;
            }
        }

        if ($workspace->getStartDate()) {
            if ($now->getTimeStamp() < $workspace->getStartDate()->getTimeStamp()) {
                $dateValidity = false;
            }
        }

        return [
          'workspace' => $workspace,
          'action' => $action,
          'dateValidity' => $dateValidity,
          'isInQueue' => $this->workspaceManager->isUserInValidationQueue($workspace, $user),
        ];
    }
870984
public function getOrderedToolsByWorkspaceAndRoles(
        Workspace $workspace,
        array $roles,
        $type = 0
    )
    {
        if ($workspace->isPersonal()) {
            return $this->orderedToolRepo->findPersonalDisplayableByWorkspaceAndRoles(
                $workspace,
                $roles,
                $type
            );
        }

        return $this->orderedToolRepo->findByWorkspaceAndRoles($workspace, $roles, $type);
    }
1183092
public function findAllPersonalWorkspaces($orderedBy = 'name', $order = 'ASC')
    {
        $dql = "
            SELECT w
            FROM Claroline\CoreBundle\Entity\Workspace\Workspace w
            WHERE EXISTS (
                SELECT u
                FROM Claroline\CoreBundle\Entity\User u
                JOIN u.personalWorkspace pw
                WHERE pw = w
            )
            ORDER BY w.{$orderedBy} {$order}
        ";
        $query = $this->_em->createQuery($dql);

        return $query->getResult();
    }
1282318
public function findByNameAndGroup(
        $search,
        Group $group,
        $executeQuery = true,
        $orderedBy = 'id',
        $order = 'ASC'
    )
    {
        $dql = "
            SELECT DISTINCT u FROM Claroline\CoreBundle\Entity\User u
            JOIN u.groups g
            WHERE g.id = :groupId
            AND (UPPER(u.username) LIKE :search
            OR UPPER(u.lastName) LIKE :search
            OR UPPER(u.firstName) LIKE :search)
            AND u.isEnabled = true
            ORDER BY u.{$orderedBy} {$order}
        ";
        $upperSearch = strtoupper($search);
        $query = $this->_em->createQuery($dql);
        $query->setParameter('search', "%{$upperSearch}%");
        $query->setParameter('groupId', $group->getId());

        return $executeQuery ? $query->getResult() : $query;
    }
823355
protected function getNodeDataByNodeTypeAndWorkspace($nodeType, $workspaceName)
    {
        /** @var QueryBuilder $queryBuilder */
        $queryBuilder = $this->entityManager->createQueryBuilder();

        $queryBuilder->select('n')
            ->distinct()
            ->from(NodeData::class, 'n')
            ->where('n.nodeType = :nodeType')
            ->andWhere('n.workspace = :workspace')
            ->andWhere('n.movedTo IS NULL OR n.removed = :removed')
            ->setParameter('nodeType', $nodeType)
            ->setParameter('workspace', $workspaceName)
            ->setParameter('removed', false, \PDO::PARAM_BOOL);
        return $queryBuilder->getQuery()->getResult();
    }
787144
public function findUsersByWorkspace($workspace, $executeQuery = true)
    {
        $userQueryBuilder = $this->createQueryBuilder('u')
            ->select('u')
            ->join('u.roles', 'r')
            ->andWhere('u.isEnabled = true')
            ->orderBy('u.id');

        if (null === $workspace) {
            $userQueryBuilder->andWhere('r.workspace IS NULL');
        }
        else {
            $userQueryBuilder
                ->leftJoin('r.workspace', 'w')
                ->andWhere('r.workspace = :workspace')
                ->setParameter('workspace', $workspace);
        };

        return $executeQuery ? $userQueryBuilder->getQuery()->getResult() : $userQueryBuilder->getQuery();
    }