/**
  * {@inheritdoc}
  */
 public function visit($operator, CriteriaCollection $criteriaCollection)
 {
     if (!$operator instanceof Operator) {
         throw new \Exception('OperatorVisitor accepts only Operator instance');
     }
     $dqlParts = array();
     foreach ($operator->getCriterias() as $criteria) {
         if ($criteria instanceof Operator) {
             $visitor = new OperatorVisitor();
         } elseif ($criteria instanceof Asserter) {
             $visitor = new AsserterVisitor();
         } else {
             throw new \Exception('Not supported');
         }
         $visitor->visit($criteria, $criteriaCollection);
         $dqlParts[] = $visitor->getDql();
     }
     $this->dql = sprintf('(%s)', implode(' ' . $operator->getType() . ' ', $dqlParts));
 }
 /**
  * @param QueryBuilder $qb qb
  */
 protected function filterCriterias($qb)
 {
     if ($this->criterias instanceof Operator) {
         $visitor = new OperatorVisitor();
     } elseif ($this->criterias instanceof Asserter) {
         $visitor = new AsserterVisitor();
     }
     $criteriaCollection = new CriteriaCollection();
     $visitor->visit($this->criterias, $criteriaCollection);
     $parameters = array();
     foreach ($criteriaCollection as $criteria) {
         $parameters = array_merge($criteria->getParameters(), $parameters);
         $aliasNumber = $criteria->getAliasNumber();
         switch ($criteria->getLocation()) {
             case 'timeline':
                 $timelineKey = sprintf('timeline%s', $aliasNumber);
                 $qb->leftJoin('action.timelines', $timelineKey, Expr\Join::WITH, $criteria->getDql());
                 break;
             case 'actionComponent':
                 $actionComponentKey = sprintf('actionComponent%s', $aliasNumber);
                 $qb->leftJoin('action.actionComponents', $actionComponentKey, Expr\Join::WITH, $criteria->getDql());
                 break;
             case 'component':
                 $actionComponentKey = sprintf('actionComponent%s', $aliasNumber);
                 $componentKey = sprintf('component%s', $aliasNumber);
                 $qb->leftJoin('action.actionComponents', $actionComponentKey)->leftJoin(sprintf('%s.component', $actionComponentKey), $componentKey, Expr\Join::WITH, $criteria->getDql());
                 break;
         }
     }
     $qb->andWhere($visitor->getDql());
     foreach ($parameters as $key => $value) {
         $qb->setParameter($key, $value);
     }
 }