/**
  * @param Stage      $qa
  * @param array|null $order
  * @param array|null $descriptionEntity
  * @param boolean    $sortForGroup
  *
  * @return Stage
  */
 protected function generateFilterSort(Stage $qa, $order = null, $descriptionEntity = null, $sortForGroup = false)
 {
     $sortArgs = $this->generateArrayForFilterSort($order, $descriptionEntity, true, $sortForGroup);
     if (!empty($sortArgs)) {
         $qa->sort($sortArgs);
     }
     return $qa;
 }
 /**
  * @param Stage $qa
  *
  * @return array
  */
 protected function findLastVersionInLanguage(Stage $qa)
 {
     $elementName = 'node';
     $qa->sort(array('version' => 1));
     $qa->group(array('_id' => array('nodeId' => '$nodeId', 'language' => '$language'), $elementName => array('$last' => '$$ROOT')));
     return $this->hydrateAggregateQuery($qa, $elementName);
 }
 /**
  * @param Stage                            $qa
  * @param string                           $elementName
  * @param PaginateFinderConfiguration|null $configuration
  */
 protected function generateLastVersionFilter(Stage $qa, $elementName, $configuration = null)
 {
     $group = array();
     if (!is_null($configuration)) {
         $group = $this->generateGroupForFilterSort($configuration);
     }
     $group = array_merge($group, array('_id' => array('contentTypeId' => '$contentTypeId'), $elementName => array('$last' => '$$ROOT')));
     $qa->sort(array('version' => 1));
     $qa->group($group);
 }
 /**
  * @param Stage $qa
  *
  * @return int
  */
 protected function countDocumentAggregateQuery(Stage $qa)
 {
     $qa->group(array('_id' => null, 'count' => array('$sum' => 1)));
     $res = $qa->getQuery()->aggregate();
     return null !== $res[0]['count'] ? $res[0]['count'] : 0;
 }