/**
  * @param DatagridInterface $grid
  * @param array $config
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $this->grid = $grid;
     if ($pagerParameters = $grid->getParameters()->get('_pager')) {
         $this->requestPagerParameters = $pagerParameters;
     }
     $grid->setDatasource(clone $this);
 }
 /**
  * @return ResultsObject
  */
 protected function getGridData()
 {
     if (null !== $this->gridDataSource) {
         $this->grid->setDatasource(clone $this->gridDataSource);
     } else {
         $this->gridDataSource = clone $this->grid->getDatasource();
     }
     $this->grid->getParameters()->set(PagerInterface::PAGER_ROOT_PARAM, [PagerInterface::PAGE_PARAM => $this->page, PagerInterface::PER_PAGE_PARAM => $this->pageSize]);
     return $this->grid->getData();
 }
 /**
  * @param DatagridInterface $datagrid
  *
  * @return array
  */
 protected function getEntityNameWithAlias(DatagridInterface $datagrid)
 {
     $fromItems = $datagrid->getConfig()->offsetGetByPath('[source][query][from]', false);
     if (empty($fromItems[0]['table'])) {
         return [$datagrid->getParameters()->get('class_name'), null];
     } else {
         $alias = empty($fromItems[0]['alias']) ? null : $fromItems[0]['alias'];
         return [$fromItems[0]['table'], $alias];
     }
 }
Esempio n. 4
0
 /**
  * Binds datagrid parameters to datasource query.
  *
  * Example of usage:
  * <code>
  *  // get parameter "name" from datagrid parameter bag and add it to datasource query
  *  $queryParameterBinder->bindParameters($datagrid, ['name']);
  *
  *  // get parameter "id" from datagrid parameter bag and add it to datasource query as parameter "client_id"
  *  $queryParameterBinder->bindParameters($datagrid, ['client_id' => 'id']);
  *
  *  // get parameter "email" from datagrid parameter bag and add it to datasource query, all other existing query
  *  // parameters will be cleared
  *  $queryParameterBinder->bindParameters($datagrid, ['email'], false);
  *
  *  // get parameter with path "_parameters.data_in" from datagrid parameter
  *  // and add it to datasource query as parameter "data_in"
  *  $queryParameterBinder->bindParameters($datagrid, ['data_in' => '_parameters.data_in']);
  *
  *  // get parameter with path "_parameters.data_in" from datagrid parameter
  *  // and add it to datasource query as parameter "data_in",
  *  // if parameter is not exist, set default value - empty array,
  *  // and do the same for data_not_in
  *  $queryParameterBinder->bindParameters(
  *      $datagrid,
  *      [
  *          'data_in' => [
  *              'path' => '_parameters.data_in',
  *              'default' => [],
  *          ],
  *          [
  *              'name' => 'data_not_in'
  *              'path' => '_parameters.data_not_in',
  *              'default' => [],
  *          ]
  *      ]
  *  );
  * </code>
  *
  * @param DatagridInterface $datagrid
  * @param array $datasourceToDatagridParameters
  * @param bool $append
  * @throws InvalidArgumentException When datasource of grid is not ORM
  * @throws NoSuchPropertyException When datagrid has no parameter with specified name or path
  */
 public function bindParameters(DatagridInterface $datagrid, array $datasourceToDatagridParameters, $append = true)
 {
     if (!$datasourceToDatagridParameters) {
         return;
     }
     $datasource = $datagrid->getDatasource();
     if (!$datasource instanceof OrmDatasource) {
         throw new InvalidArgumentException(sprintf('Datagrid datasource has unexpected type "%s", "%s" is expected.', get_class($datasource), 'Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource'));
     }
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $datasource->getQueryBuilder();
     $queryParameters = $queryBuilder->getParameters();
     if (!$append) {
         $queryParameters->clear();
     }
     $datagridParameters = $datagrid->getParameters()->all();
     foreach ($datasourceToDatagridParameters as $index => $value) {
         $config = $this->parseArrayParameterConfig($index, $value);
         $value = $this->getParameterValue($datagridParameters, $config);
         $type = isset($config['type']) ? $config['type'] : null;
         $this->addOrReplaceParameter($queryParameters, new Parameter($config['name'], $value, $type));
     }
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $parameters = $grid->getParameters();
     $this->object = $this->routingHelper->getEntity($parameters->get('entityClass'), $parameters->get('entityId'));
     $grid->setDatasource(clone $this);
 }
 /**
  * @return ResultsObject
  */
 protected function getGridData()
 {
     $this->grid->getParameters()->set(PagerInterface::PAGER_ROOT_PARAM, [PagerInterface::PAGE_PARAM => $this->page, PagerInterface::PER_PAGE_PARAM => $this->pageSize]);
     return $this->grid->getData();
 }