/**
  * {@inheritDoc}
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $queryConfig = array_intersect_key($config, array_flip(['query']));
     $converter = new YamlConverter();
     $this->qb = $converter->parse($queryConfig, $this->em->createQueryBuilder());
     $grid->setDatasource(clone $this);
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $this->datagrid = $grid;
     if (isset($config['query'])) {
         $queryConfig = array_intersect_key($config, array_flip(['query']));
         $converter = new YamlConverter();
         $this->qb = $converter->parse($queryConfig, $this->em->createQueryBuilder());
     } elseif (isset($config['entity']) && isset($config['repository_method'])) {
         $entity = $config['entity'];
         $method = $config['repository_method'];
         $repository = $this->em->getRepository($entity);
         if (method_exists($repository, $method)) {
             $qb = $repository->{$method}();
             if ($qb instanceof QueryBuilder) {
                 $this->qb = $qb;
             } else {
                 throw new DatasourceException(sprintf('%s::%s() must return an instance of Doctrine\\ORM\\QueryBuilder, %s given', get_class($repository), $method, is_object($qb) ? get_class($qb) : gettype($qb)));
             }
         } else {
             throw new DatasourceException(sprintf('%s has no method %s', get_class($repository), $method));
         }
     } else {
         throw new DatasourceException(get_class($this) . ' expects to be configured with query or repository method');
     }
     if (isset($config['hints'])) {
         $this->queryHints = $config['hints'];
     }
     $grid->setDatasource(clone $this);
 }
 /**
  * @param DatagridInterface $grid
  * @param array             $config
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $this->config = $config;
     $this->grid = $grid;
     $queryConfig = array_intersect_key($this->config, array_flip(['query']));
     $converter = new YamlConverter();
     $this->qbOroAudit = $converter->parse($queryConfig, $this->doctrineRegistry->getManager()->createQueryBuilder('a'));
     if (isset($config['hints'])) {
         $this->queryHints = $config['hints'];
     }
     parent::process($grid, $config);
 }