/**
  * Executes the count on Query used for
  * pagination.
  *
  * @param CountEvent $event
  */
 public function count(CountEvent $event)
 {
     $query = $event->getQuery();
     $countQuery = QueryHelper::cloneQuery($query);
     $countQuery->setParameters($query->getParameters());
     QueryHelper::addCustomTreeWalker($countQuery, self::TREE_WALKER_COUNT);
     $countQuery->setHint(CountWalker::HINT_PAGINATOR_COUNT_DISTINCT, $event->isDistinct());
     $countQuery->setFirstResult(null)->setMaxResults(null);
     $event->stopPropagation();
     $countResult = $countQuery->getResult(Query::HYDRATE_ARRAY);
     $event->setCount(count($countResult) > 1 ? count($countResult) : current(current($countResult)));
 }
 /**
  * Executes the count on Query used for
  * pagination.
  *
  * @param CountEvent $event
  */
 public function count(CountEvent $event)
 {
     $query = $event->getQuery();
     $event->stopPropagation();
     $event->setCount($query->count());
 }