public function countUsersByRole(Role $role, $restrictionRoleNames = null, $organizations = null)
    {
        $qb = $this->createQueryBuilder('user')
            ->select('COUNT(DISTINCT user.id)')
            ->leftJoin('user.roles', 'roles')
            ->andWhere('roles.id = :roleId')
            ->andWhere('user.isEnabled = :enabled')
            ->setParameter('roleId', $role->getId())
            ->setParameter('enabled', true);
        if (!empty($restrictionRoleNames)) {
            $qb->andWhere('user.id NOT IN (:userIds)')
                ->setParameter('userIds', $this->findUserIdsInRoles($restrictionRoleNames));
        }
        if (null !== $organizations) {
            $qb->join('user.userOrganizationReferences', 'orgaRef')
                ->andWhere('orgaRef.organization IN (:organizations)')
                ->setParameter('organizations', $organizations);
        }
        $query = $qb->getQuery();

        return $query->getSingleScalarResult();
    }
public function countUsersByRole(Role $role, $restrictionRoleNames = null, $organizations = null)
    {
        $qb = $this->createQueryBuilder('user')
            ->select('COUNT(DISTINCT user.id)')
            ->leftJoin('user.roles', 'roles')
            ->andWhere('roles.id = :roleId')
            ->andWhere('user.isEnabled = :enabled')
            ->setParameter('roleId', $role->getId())
            ->setParameter('enabled', true);
        if (!empty($restrictionRoleNames)) {
            $qb->andWhere('user.id NOT IN (:userIds)')
                ->setParameter('userIds', $this->findUserIdsInRoles($restrictionRoleNames));
        }
        if (null !== $organizations) {
            $qb->join('user.userOrganizationReferences', 'orgaRef')
                ->andWhere('orgaRef.organization IN (:organizations)')
                ->setParameter('organizations', $organizations);
        }
        $query = $qb->getQuery();

        return $query->getSingleScalarResult();
    }
public function countUsersByRole ( Role $ role , $ restrictionRoleNames = null , $ organizations = null ) { $ qb = $ this -> createQueryBuilder ( 'user' ) -> select ( 'COUNT(DISTINCT user.id)' ) -> leftJoin ( 'user.roles' , 'roles' ) -> andWhere ( 'roles.id = :roleId' ) -> andWhere ( 'user.isEnabled = :enabled' ) -> setParameter ( 'roleId' , $ role -> getId ( ) ) -> setParameter ( 'enabled' , true ) ; if ( ! empty ( $ restrictionRoleNames ) ) { $ qb -> andWhere ( 'user.id NOT IN (:userIds)' ) -> setParameter ( 'userIds' , $ this -> findUserIdsInRoles ( $ restrictionRoleNames ) ) ; } if ( null !== $ organizations ) { $ qb -> join ( 'user.userOrganizationReferences' , 'orgaRef' ) -> andWhere ( 'orgaRef.organization IN (:organizations)' ) -> setParameter ( 'organizations' , $ organizations ) ; } $ query = $ qb -> getQuery ( ) ; return $ query -> getSingleScalarResult ( ) ; }
Counts the users subscribed in a platform role.

@param Role $role
@param $restrictionRoleNames
@param null $organizations

@return int
Counts the users subscribed in a platform role .