/** * @param GridQueryDesignerInterface|AbstractQueryDesigner $value * @param QueryConstraint|Constraint $constraint */ public function validate($value, Constraint $constraint) { if (!$value instanceof GridQueryDesignerInterface) { return; } $gridPrefix = $value->getGridPrefix(); $builder = $this->getBuilder($gridPrefix); $builder->setGridName($gridPrefix); $builder->setSource($value); $message = $this->translator->trans($constraint->message); try { $dataGrid = $this->gridBuilder->build($builder->getConfiguration(), new ParameterBag()); $dataSource = $dataGrid->getDatasource(); if ($dataSource instanceof OrmDatasource) { $qb = $dataSource->getQueryBuilder(); $qb->setMaxResults(1); } $dataSource->getResults(); } catch (DBALException $e) { $this->context->addViolation($this->isDebug ? $e->getMessage() : $message); } catch (ORMException $e) { $this->context->addViolation($this->isDebug ? $e->getMessage() : $message); } catch (InvalidConfigurationException $e) { $this->context->addViolation($this->isDebug ? $e->getMessage() : $message); } }
/** * {@inheritDoc} */ public function getDatagrid($name, $parameters = null) { if (null === $parameters) { $parameters = new ParameterBag(); } elseif (is_array($parameters)) { $parameters = new ParameterBag($parameters); } elseif (!$parameters instanceof ParameterBag) { throw new InvalidArgumentException('$parameters must be an array or instance of ParameterBag.'); } $configuration = $this->getConfigurationForGrid($name); $datagrid = $this->datagridBuilder->build($configuration, $parameters); return $datagrid; }
/** * @param WidgetConfigurationLoadEvent $event */ public function onWidgetConfigurationLoad(WidgetConfigurationLoadEvent $event) { $configuration = $event->getConfiguration(); if (!isset($configuration['route'], $configuration['route_parameters'], $configuration['route_parameters']['gridName']) || $configuration['route'] !== 'oro_dashboard_grid') { return; } $gridName = $configuration['route_parameters']['gridName']; $gridConfiguration = $this->datagridManagerLink->getService()->getConfigurationForGrid($gridName); $datagrid = $this->datagridBuilder->build($gridConfiguration, new ParameterBag()); $metadata = $datagrid->getMetadata(); $choices = $metadata->offsetGetByPath('[gridViews][choices]', []); $viewChoices = []; foreach ($choices as $choice) { $viewChoices[$choice['value']] = $choice['label']; } if (!isset($configuration['fields'])) { $configuration['fields'] = []; } $configuration['configuration'] = array_merge($configuration['configuration'], ['gridView' => ['type' => 'choice', 'options' => ['label' => 'oro.dashboard.grid.fields.grid_view.label', 'choices' => $viewChoices], 'show_on_widget' => false]]); $event->setConfiguration($configuration); }