```php
public function countTotalOrders(array $baseIds = array())
{
    $qb = $this
        ->createQueryBuilder('o')
        ->select($qb->expr()->countDistinct('o.id')
        ->innerJoin('u.elements', 'e');

    if (!empty($baseIds)) {
        $qb->where($qb->expr()->in('e.base_id', $baseIds));
    }

    $qb->groupBy('o.id');

    return $qb->getQuery()->getSingleScalarResult();
}
```