/**
  * @param Column $column
  * @param null|string $value
  * @param QueryBuilder $qb
  * @param string $field
  * @param null|bool $empty
  * @throws \Exception
  */
 private function applyColumnFilter(Column $column, $value, QueryBuilder $qb, $field, $empty)
 {
     if (null === $value && false === $column->getOptions()['filter_empty']) {
         throw new \Exception('this is just wrong');
     }
     $parameter = ':' . $column->getName() . '_filter';
     if ($column->getOptions()['filter'] instanceof \Voelkel\DataTablesBundle\Table\Filter\AbstractColumnFilter) {
         if (isset($column->getOptions()['filter']->options['field']) && null !== $column->getOptions()['filter']->options['field']) {
             $field = $this->table->getPrefix() . '.' . $column->getOptions()['filter']->options['field'];
         }
         $column->getOptions()['filter']->setContainer($this->table->getContainer());
         $column->getOptions()['filter']->buildQuery($qb, $field, $parameter, $value);
     } elseif (false !== $column->getOptions()['filter']) {
         throw new \Exception(sprintf('invalid filter type "%s"', $column->getOptions()['filter']));
     }
     if (null !== $empty && is_bool($empty) && true === $empty && true === $column->getOptions()['filter_empty']) {
         $qb->andWhere($field . ' is ' . ($empty ? '' : 'not ') . 'null');
     }
 }
 /**
  * @return QueryBuilder
  */
 private function createQueryBuilder()
 {
     /** @var \Doctrine\ORM\EntityRepository $repository */
     $repository = $this->em->getRepository($this->table->getEntity());
     $qb = $repository->createQueryBuilder($this->table->getPrefix());
     foreach ($this->table->getColumns() as $column) {
         $column->__set('container', $this->table->getContainer());
         /** @var EntityColumn $column */
         if (get_class($column) === 'Voelkel\\DataTablesBundle\\Table\\Column\\EntityColumn') {
             $this->joinColumn($qb, $column);
         }
         if ($column instanceof EntitiesColumn) {
             $this->joinColumn($qb, $column);
         }
         if ($column instanceof EntitiesScalarColumn) {
             $this->joinColumn($qb, $column);
         }
     }
     $callback = $this->table->getConditionCallback();
     if (null !== $callback) {
         call_user_func($callback, $qb);
     }
     return $qb;
 }