/**
  * Dispatch datagrid mass action
  *
  * @param Request $request
  *
  * @throws \LogicException
  *
  * @return array
  */
 protected function prepareMassActionParameters(Request $request)
 {
     $parameters = $this->parametersParser->parse($request);
     $inset = $this->prepareInsetParameter($parameters);
     $values = $this->prepareValuesParameter($parameters);
     $filters = $this->prepareFiltersParameter($parameters);
     $actionName = $request->get('actionName');
     if ($inset && empty($values)) {
         throw new \LogicException(sprintf('There is nothing to do in mass action "%s"', $actionName));
     }
     $datagridName = $request->get('gridName');
     $datagrid = $this->manager->getDatagrid($datagridName);
     $massAction = $this->getMassActionByName($actionName, $datagrid);
     $this->requestParams->set(FilterExtension::FILTER_ROOT_PARAM, $filters);
     $qb = $datagrid->getAcceptedDatasource()->getQueryBuilder();
     if (self::FAMILY_GRID_NAME === $datagridName) {
         $qbLocaleParameter = $qb->getParameter('localeCode');
         if (null !== $qbLocaleParameter && null === $qbLocaleParameter->getValue()) {
             $qb->setParameter('localeCode', $request->query->get('dataLocale'));
         }
     }
     $repository = $datagrid->getDatasource()->getMassActionRepository();
     $repository->applyMassActionParameters($qb, $inset, $values);
     return ['datagrid' => $datagrid, 'massAction' => $massAction, 'inset' => $inset, 'values' => $values];
 }
 /**
  * Dispatch datagrid mass action
  *
  * @param Request $request
  *
  * @throws \LogicException
  *
  * @return MassActionResponseInterface
  */
 public function dispatch(Request $request)
 {
     $parameters = $this->parametersParser->parse($request);
     $datagridName = $request->get('gridName');
     $actionName = $request->get('actionName');
     $inset = isset($parameters['inset']) ? $parameters['inset'] : true;
     $values = isset($parameters['values']) ? $parameters['values'] : [];
     $filters = isset($parameters['filters']) ? $parameters['filters'] : [];
     if ($inset && empty($values)) {
         throw new \LogicException(sprintf('There is nothing to do in mass action "%s"', $actionName));
     }
     $datagrid = $this->manager->getDatagrid($datagridName);
     $massAction = $this->getMassActionByName($actionName, $datagrid);
     $this->requestParams->set(FilterExtension::FILTER_ROOT_PARAM, $filters);
     return $this->performMassAction($datagrid, $massAction, $inset, $values);
 }
 /**
  * Get the datagrid query parameters
  *
  * @return array
  */
 protected function getQueryParams()
 {
     $params = $this->parametersParser->parse($this->request);
     $params['gridName'] = $this->request->get('gridName');
     $params['actionName'] = $this->request->get('actionName');
     $params['values'] = implode(',', $params['values']);
     $params['filters'] = json_encode($params['filters']);
     $params['dataLocale'] = $this->request->get('dataLocale', null);
     return $params;
 }
 /**
  * Creates a query builder based on the grid
  *
  * @param Request $request
  * @param string  $datagridName
  *
  * @return QueryBuilder
  *
  * @throws \LogicException
  */
 public function createQueryBuilder(Request $request, $datagridName)
 {
     $parameters = $this->parametersParser->parse($request);
     if ($parameters['inset'] && empty($parameters['values'])) {
         throw new \LogicException(sprintf('This request is empty'));
     }
     $datagrid = $this->manager->getDatagrid($datagridName);
     $this->requestParams->set(OrmFilterExtension::FILTER_ROOT_PARAM, $parameters['filters']);
     $datasource = $datagrid->getDatasource();
     if (!$datasource instanceof Datasource) {
         throw new \LogicException("Mass actions applicable only for datagrids with ORM datasource.");
     }
     $qb = $datagrid->getAcceptedDatasource()->getQueryBuilder();
     if (count($parameters['values'])) {
         $valueWhereCondition = $parameters['inset'] ? $qb->expr()->in('o.id', $parameters['values']) : $qb->expr()->notIn('o.id', $parameters['values']);
         $qb->andWhere($valueWhereCondition);
     }
     $qb->setMaxResults(null);
     $qb->setFirstResult(null);
     return $qb;
 }
 /**
  * Get the datagrid query parameters
  *
  * @param Request $request
  *
  * @return array
  */
 protected function getQueryParams(Request $request)
 {
     $params = $this->parametersParser->parse($request);
     $params = array_merge($params, ['gridName' => $request->get('gridName'), 'actionName' => $request->get('actionName'), 'values' => implode(',', $params['values']), 'filters' => json_encode($params['filters']), 'dataLocale' => $request->get('dataLocale', null), 'itemsCount' => $request->get('itemsCount'), 'operationGroup' => $request->get('operationGroup')]);
     return $params;
 }