/**
  * @param BuildBefore $event
  * @return bool
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $datagrid = $event->getDatagrid();
     $config = $event->getConfig();
     $entityClassName = $datagrid->getParameters()->get('class_name');
     $fieldName = $datagrid->getParameters()->get('field_name');
     $entityId = $datagrid->getParameters()->get('id');
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $extendFieldConfig = $extendConfigProvider->getConfig($entityClassName, $fieldName);
     $targetEntityName = $extendFieldConfig->get('target_entity');
     $targetFieldNames = $extendFieldConfig->get('target_grid');
     // build 'assigned' field expression
     if ($entityId) {
         $extendEntityConfig = $extendConfigProvider->getConfig($entityClassName);
         $relations = $extendEntityConfig->get('relation');
         $relation = $relations[$extendFieldConfig->get('relation_key')];
         $targetFieldName = $relation['target_field_id']->getFieldName();
         $fieldType = $extendFieldConfig->getId()->getFieldType();
         $operator = $fieldType == 'oneToMany' ? '=' : 'MEMBER OF';
         $whenExpr = '(:relation ' . $operator . ' o.' . $targetFieldName . ' OR o.id IN (:data_in))' . ' AND o.id NOT IN (:data_not_in)';
     } else {
         $whenExpr = 'o.id IN (:data_in) AND o.id NOT IN (:data_not_in)';
     }
     $assignedExpr = "CASE WHEN " . $whenExpr . " THEN true ELSE false END";
     // build a query skeleton
     $query = ['select' => ['o.id', $assignedExpr . ' as assigned'], 'from' => [['table' => $targetEntityName, 'alias' => 'o']]];
     $config->offsetSetByPath('[source][query]', $query);
     // enable AdditionalFieldsExtension to add all other fields
     $config->offsetSetByPath('[options][entity_name]', $targetEntityName);
     $config->offsetSetByPath('[options][additional_fields]', $targetFieldNames);
 }
 /**
  * Add dynamic fields
  *
  * @param BuildBefore $event
  * @param string|null $alias
  * @param string|null $itemType
  * @param bool        $dynamicFirst flag if true - dynamic columns will be placed before static, false - after
  */
 public function doBuildBefore(BuildBefore $event, $alias = null, $itemType = null, $dynamicFirst = true)
 {
     $config = $event->getConfig();
     // get dynamic columns and merge them with static columns from configuration
     $additionalColumnSettings = $this->getDynamicFields($alias, $itemType);
     $filtersSorters = $this->getDynamicSortersAndFilters($additionalColumnSettings);
     $additionalColumnSettings = ['columns' => $additionalColumnSettings, 'sorters' => $filtersSorters['sorters'], 'filters' => $filtersSorters['filters']];
     $additionalColumnSettings = $this->datagridResolver->resolve($config->getName(), $additionalColumnSettings);
     foreach (['columns', 'sorters', 'filters'] as $itemName) {
         $path = '[' . $itemName . ']';
         // get already defined items
         $items = $config->offsetGetByPath($path, []);
         // merge additional items with existing
         if ($dynamicFirst) {
             $items = array_merge_recursive($additionalColumnSettings[$itemName], $items);
         } else {
             $items = array_merge_recursive($items, $additionalColumnSettings[$itemName]);
         }
         // set new item set with dynamic columns/sorters/filters
         $config->offsetSetByPath($path, $items);
     }
     // add/configure entity config properties
     $this->addEntityConfigProperties($config, $itemType);
     // add/configure entity config actions
     $actions = $config->offsetGetByPath(self::PATH_ACTIONS, []);
     $this->prepareRowActions($actions, $itemType);
     $config->offsetSetByPath(self::PATH_ACTIONS, $actions);
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     // get root entity
     $rootEntity = null;
     $rootEntityAlias = null;
     $from = $config->offsetGetByPath('[source][query][from]');
     if ($from) {
         $firstFrom = current($from);
         if (!empty($firstFrom['table']) && !empty($firstFrom['alias'])) {
             $rootEntity = $this->updateEntityClass($firstFrom['table']);
             $rootEntityAlias = $firstFrom['alias'];
         }
     }
     $groupBy = $config->offsetGetByPath('[source][query][groupBy]', null);
     if (!$rootEntity || !$rootEntityAlias || $groupBy) {
         return;
     }
     // whether entity has active workflow and entity should render workflow step field
     $isShowWorkflowStep = $this->workflowManager->hasApplicableWorkflowByEntityClass($rootEntity) && $this->isShowWorkflowStep($rootEntity);
     // check whether grid contains workflow step column
     $columns = $config->offsetGetByPath('[columns]', array());
     $workflowStepColumns = array_intersect($this->workflowStepColumns, array_keys($columns));
     // remove workflow step if it must be hidden but there are workflow step columns
     if (!$isShowWorkflowStep && $workflowStepColumns) {
         $this->removeWorkflowStep($config, $workflowStepColumns);
     }
     // add workflow step if it must be shown and there are no workflow step columns
     if ($isShowWorkflowStep && empty($workflowStepColumns)) {
         $this->addWorkflowStep($config, $rootEntity, $rootEntityAlias);
     }
 }
Пример #4
0
 /**
  * Need to change data name depends to filter value
  *
  * Event: oro_datagrid.datagrid.build.before.orocrm_report-opportunities-won_by_period
  *
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $filters = $event->getDatagrid()->getParameters()->get(OrmFilterExtension::FILTER_ROOT_PARAM, []);
     $period = isset($filters[self::PERIOD_COLUMN_NAME]['value']) ? $filters[self::PERIOD_COLUMN_NAME]['value'] : self::PERIOD_FILTER_DEFAULT_VALUE;
     $config->offsetSetByPath(sprintf('%s[%s][%s]', FilterConfiguration::COLUMNS_PATH, self::PERIOD_COLUMN_NAME, FilterUtility::DATA_NAME_KEY), $period);
     $config->offsetSetByPath(sprintf('[%s][%s][%s]', FormatterConfiguration::COLUMNS_KEY, self::PERIOD_COLUMN_NAME, PropertyInterface::DATA_NAME_KEY), $period);
     // in order to meet sql standards on some RDBMS (e.g. Postgres)
     // unset columns not used in aggregation or group by statements
     $path = '[source][query][select]';
     $aliasFields = ['monthPeriod', 'monthPeriodSorting', 'quarterPeriod', 'quarterPeriodSorting', 'yearPeriod'];
     foreach ($aliasFields as $index => $alias) {
         // skip current period alias and it's sorting helper alias
         if ($alias == $period || str_replace('Sorting', '', $alias) == $period) {
             continue;
         }
         $config->offsetUnsetByPath(sprintf('%s[%s]', $path, $index));
     }
     // and setup separate sorting column, used as well in grouping, but not affecting grouping result
     // period will be always the first column, unless changed in datagrid.yml
     if ($period == 'yearPeriod') {
         $groupAlias = $period;
         $sortAlias = $period;
     } else {
         $groupAlias = $period;
         $sortAlias = sprintf('%sSorting', $period);
     }
     $config->offsetSetByPath('[source][query][groupBy]', $groupAlias);
     $config->offsetSetByPath(sprintf('%s[%s][%s]', OrmSorterConfiguration::COLUMNS_PATH, self::PERIOD_COLUMN_NAME, PropertyInterface::DATA_NAME_KEY), $sortAlias);
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBeforeFrontendItems(BuildBefore $event)
 {
     if (!$this->getUser() instanceof AccountUser) {
         return;
     }
     $config = $event->getConfig();
     if (null === $config->offsetGetByPath(self::ROOT_OPTIONS)) {
         return;
     }
     if ([] === ($from = $config->offsetGetByPath('[source][query][from]', []))) {
         return;
     }
     if (!$config->offsetGetByPath(ActionExtension::ACTION_CONFIGURATION_KEY)) {
         $config->offsetSetByPath(ActionExtension::ACTION_CONFIGURATION_KEY, $this->actionCallback);
     }
     $fromFirst = reset($from);
     $this->entityClass = $fromFirst['table'];
     $this->entityAlias = $fromFirst['alias'];
     if ($this->permissionShowAllAccountItems()) {
         $this->showAllAccountItems($config);
     }
     if (null !== ($accountUserColumn = $config->offsetGetByPath(self::ACCOUNT_USER_COLUMN))) {
         if (!$this->permissionShowAccountUserColumn()) {
             $this->removeAccountUserColumn($config, $accountUserColumn);
         }
     }
 }
 /**
  * @param BuildBefore $event
  * @return bool
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $entityClass = $this->getRequestParam('class_name');
     if (empty($entityClass)) {
         $entityClass = $this->request->attributes->get('id');
     }
     if (empty($this->entityClass) && $entityClass !== false) {
         $this->entityClass = str_replace('_', '\\', $entityClass);
     }
     if (empty($this->entityClass)) {
         return false;
     }
     $config = $event->getConfig();
     // get dynamic columns
     $additionalColumnSettings = $this->getDynamicFields($config->offsetGetByPath('[source][query][from][0][alias]', 'ce'));
     $filtersSorters = $this->getDynamicSortersAndFilters($additionalColumnSettings);
     $additionalColumnSettings = array_merge($additionalColumnSettings, ['sorters' => $filtersSorters['sorters'], 'filters' => $filtersSorters['filters']]);
     foreach (['columns', 'sorters', 'filters', 'source'] as $itemName) {
         $path = '[' . $itemName . ']';
         // get already defined items
         $items = $config->offsetGetByPath($path, []);
         $items = array_merge_recursive($items, $additionalColumnSettings[$itemName]);
         // set new item set with dynamic columns/sorters/filters
         $config->offsetSetByPath($path, $items);
     }
     // set entity to select from
     $from = $config->offsetGetByPath(self::PATH_FROM, []);
     $from[0] = array_merge($from[0], ['table' => $this->entityClass]);
     $config->offsetSetByPath('[source][query][from]', $from);
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $object = 'entity:Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit';
     $observer = new OneShotIsGrantedObserver();
     $this->aclVoter->addOneShotIsGrantedObserver($observer);
     $this->getSecurityContext()->isGranted('VIEW', $object);
     $user = $this->getSecurityContext()->getToken()->getUser();
     $organization = $this->getSecurityContext()->getToken()->getOrganizationContext();
     $accessLevel = $observer->getAccessLevel();
     $where = $config->offsetGetByPath('[source][query][where][and]', []);
     if ($accessLevel == AccessLevel::GLOBAL_LEVEL) {
         $leftJoins = $config->offsetGetByPath('[source][query][join][inner]', []);
         $leftJoins[] = ['join' => 'u.organization', 'alias' => 'org'];
         $config->offsetSetByPath('[source][query][join][inner]', $leftJoins);
         $where = array_merge($where, ['org.id in (' . $organization->getId() . ')']);
     } elseif ($accessLevel !== AccessLevel::SYSTEM_LEVEL) {
         $resultBuIds = [];
         if ($accessLevel == AccessLevel::LOCAL_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserBusinessUnitIds($user->getId(), $organization->getId());
         } elseif ($accessLevel == AccessLevel::DEEP_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserSubordinateBusinessUnitIds($user->getId(), $organization->getId());
         }
         if (count($resultBuIds)) {
             $where = array_merge($where, ['u.id in (' . implode(', ', $resultBuIds) . ')']);
         } else {
             // There are no records to show, make query to return empty result
             $where = array_merge($where, ['1 = 0']);
         }
     }
     if (count($where)) {
         $config->offsetSetByPath('[source][query][where][and]', $where);
     }
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $objectClassParameter = $this->getObjectClassParameter();
     $objectClass = $this->getObjectClass($objectClassParameter);
     $repositoryParameters = ['objectClass' => str_replace('_', '\\', $objectClass), 'objectId' => $this->requestParams->get(self::GRID_PARAM_OBJECT_ID, 0)];
     $config->offsetSetByPath(sprintf(ContextConfigurator::SOURCE_PATH, ContextConfigurator::REPOSITORY_PARAMETERS_KEY), $repositoryParameters);
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     // show 'public' column only if both public and system calendars are enabled
     if (!$this->calendarConfig->isPublicCalendarEnabled() || !$this->calendarConfig->isSystemCalendarEnabled()) {
         $config = $event->getConfig();
         $this->removeColumn($config, 'public');
     }
 }
 /**
  * Configure product columns, filters, sorters dynamically
  *
  * @param BuildBefore $event
  *
  * @throws \LogicException
  */
 public function buildBefore(BuildBefore $event)
 {
     $datagridConfig = $event->getConfig();
     $this->getContextConfigurator()->configure($datagridConfig);
     $this->getColumnsConfigurator()->configure($datagridConfig);
     $this->getSortersConfigurator()->configure($datagridConfig);
     $this->getFiltersConfigurator()->configure($datagridConfig);
 }
Пример #11
0
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $fieldName = $event->getDatagrid()->getParameters()->get(self::GRID_PARAM_FIELD_NAME);
     $leftJoins = $config->offsetGetByPath(self::GRID_LEFT_JOIN_PATH, []);
     $leftJoins[] = ['join' => 'attachment.' . $fieldName, 'alias' => 'entity'];
     $config->offsetSetByPath(self::GRID_LEFT_JOIN_PATH, $leftJoins);
 }
Пример #12
0
 /**
  * Need to change data name depends to filter value
  *
  * Event: oro_datagrid.datagrid.build.before.orocrm_report-opportunities-won_by_period
  *
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $filters = $event->getDatagrid()->getParameters()->get(OrmFilterExtension::FILTER_ROOT_PARAM, []);
     $period = isset($filters[self::PERIOD_COLUMN_NAME]['value']) ? $filters[self::PERIOD_COLUMN_NAME]['value'] : self::PERIOD_FILTER_DEFAULT_VALUE;
     $config->offsetSetByPath(sprintf('%s[%s][%s]', FilterConfiguration::COLUMNS_PATH, self::PERIOD_COLUMN_NAME, FilterUtility::DATA_NAME_KEY), $period);
     $config->offsetSetByPath(sprintf('%s[%s][%s]', OrmSorterConfiguration::COLUMNS_PATH, self::PERIOD_COLUMN_NAME, PropertyInterface::DATA_NAME_KEY), $period);
     $config->offsetSetByPath(sprintf('[%s][%s][%s]', FormatterConfiguration::COLUMNS_KEY, self::PERIOD_COLUMN_NAME, PropertyInterface::DATA_NAME_KEY), $period);
 }
Пример #13
0
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $datagrid = $event->getDatagrid();
     $config = $event->getConfig();
     // remember the current datagrid to further usage in getLinkProperty method
     $this->addVisitedDatagrid($datagrid);
     // enable DynamicFieldsExtension to add custom fields
     $config->offsetSet('extended_entity_name', $datagrid->getParameters()->get('class_name'));
 }
Пример #14
0
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $dataGrid = $event->getDatagrid();
     $dataGridName = $dataGrid->getName();
     $parameters = $dataGrid->getParameters();
     if ($this->isApplicable($dataGridName, $parameters)) {
         $event->stopPropagation();
     }
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     /*
      * Add generated entity name DQL to be selected under alias.
      * Aliases billingName and shippingName are added to query this way.
      */
     $config->offsetAddToArrayByPath('source.query.select', [$this->dqlNameFormatter->getFormattedNameDQL('ba', 'Marello\\Bundle\\AddressBundle\\Entity\\Address') . ' as billingName', $this->dqlNameFormatter->getFormattedNameDQL('sa', 'Marello\\Bundle\\AddressBundle\\Entity\\Address') . ' as shippingName']);
 }
Пример #16
0
 /**
  * @param BuildBefore $event
  */
 public function statusGridBuildBefore(BuildBefore $event)
 {
     $params = $event->getDatagrid()->getParameters();
     if ($params->has('integrationType')) {
         $type = $params->get('integrationType');
         $connectorChoices = $this->typesRegistry->getAvailableConnectorsTypesChoiceList($type);
         $event->getDatagrid()->getConfig()->offsetSetByPath('[filters][columns][connector][options][field_options][choices]', $connectorChoices);
     }
 }
 public function let(ActionFactory $actionFactory, ActionInterface $indexAction, BuildBefore $event, DatagridConfiguration $datagridConfig, ConfigurationInterface $customEntityConfig)
 {
     $this->beConstructedWith($actionFactory);
     $indexAction->implement('Pim\\Bundle\\CustomEntityBundle\\Action\\IndexActionInterface');
     $indexAction->getConfiguration()->willReturn($customEntityConfig);
     $customEntityConfig->getName()->willReturn('entity');
     $customEntityConfig->getEntityClass()->willReturn('entity_class');
     $actionFactory->getAction('entity', 'index')->willReturn($indexAction);
     $event->getConfig()->willReturn($datagridConfig);
 }
Пример #18
0
 public function testEventCreation()
 {
     $grid = $this->getMockForAbstractClass('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $config = DatagridConfiguration::create([]);
     $event = new BuildBefore($grid, $config);
     $this->assertSame($grid, $event->getDatagrid());
     $this->assertSame($config, $event->getConfig());
     // test config passed as link
     $event->getConfig()->offsetSet(self::TEST_STRING, self::TEST_STRING . 'value');
     $this->assertEquals(self::TEST_STRING . 'value', $config->offsetGet(self::TEST_STRING));
 }
 /**
  * {@inheritdoc}
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $datagrid = $event->getDatagrid();
     list($entityName, $alias) = $this->getEntityNameWithAlias($datagrid);
     $alias = $alias ?: 'e';
     if (!$this->isApplicable($event, $entityName)) {
         return;
     }
     // configure mass action
     $event->getConfig()->offsetSetByPath(sprintf(self::ACTION_CONFIGURATION_KEY, MassUpdateActionHandler::ACTION_NAME), ['type' => 'window', 'frontend_type' => 'update-mass', 'route' => 'oro_datagrid_mass_action', 'dialogWindowOptions' => ['route' => 'trustify_mass_update', 'route_parameters' => ['entityName' => str_replace('\\', '_', $entityName)]], 'data_identifier' => $alias . '.' . $this->doctrineHelper->getSingleEntityIdentifierFieldName($entityName), 'handler' => MassUpdateActionHandler::SERVICE_ID, 'label' => 'trustify.mass_update.dialog.title', 'success_message' => 'trustify.mass_update.success_message', 'error_message' => 'trustify.mass_update.error_message']);
 }
Пример #20
0
 /**
  * Remove useless fields in case of filtering
  *
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $parameters = $event->getDatagrid()->getParameters();
     if ($parameters->has('contactId')) {
         $this->removeColumn($config, 'contactName');
     }
     if ($parameters->has('accountId')) {
         $this->removeColumn($config, 'accountName');
     }
 }
Пример #21
0
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $entityClassName = $this->getEntity($config);
     $filters = $config->offsetGetByPath(self::GRID_FILTERS_PATH, []);
     if (empty($filters) || !is_a($entityClassName, 'Oro\\Bundle\\TagBundle\\Entity\\Taggable', true) || strpos($config->offsetGetByPath(self::GRID_NAME_PATH), 'oro_report') === 0) {
         return;
     }
     $filters[self::COLUMN_NAME] = ['type' => 'tag', 'label' => 'oro.tag.entity_plural_label', 'data_name' => 'tag.id', 'enabled' => false, 'options' => ['field_options' => ['entity_class' => $entityClassName]]];
     $config->offsetSetByPath(self::GRID_FILTERS_PATH, $filters);
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $user = $this->securityFacade->getLoggedUser();
     if ($user instanceof AccountUser && $user->getAccount() && $this->securityFacade->isGranted('orob2b_account_frontend_account_user_role_view')) {
         $andWhere = 'role.account IN (' . $user->getAccount()->getId() . ')';
         $this->addConfigElement($config, '[source][query][where][and]', $andWhere);
         $orWhere = 'role.account IS NULL';
         $this->addConfigElement($config, '[source][query][where][or]', $orWhere);
     } else {
         $this->addConfigElement($config, '[source][query][where][and]', '1=0');
     }
 }
Пример #23
0
 /**
  * Remove mass action if entity config mass action disabled
  *
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $massActions = isset($config['mass_actions']) ? $config['mass_actions'] : array();
     if (empty($massActions['merge']['entity_name'])) {
         return;
     }
     $entityName = $massActions['merge']['entity_name'];
     $entityMergeEnable = $this->metadataRegistry->getEntityMetadata($entityName)->is('enable');
     if (!$entityMergeEnable) {
         $config->offsetUnsetByPath('[mass_actions][merge]');
     }
 }
Пример #24
0
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $request = $this->requestStack->getCurrentRequest();
     if ($request) {
         $entityId = $request->get('entityId');
         $entityClass = $request->get('entityClass');
         $shareGridParams = $request->get('shared-datagrid');
         if ($shareGridParams) {
             $entityId = $shareGridParams['entityId'];
             $entityClass = $shareGridParams['entityClass'];
         }
         $event->getDatagrid()->getParameters()->add(['entityId' => $entityId, 'entityClass' => $entityClass]);
     }
 }
 /**
  * Check whenever grid is flexible and add flexible columns dynamically
  *
  * @param BuildBefore $event
  *
  * @throws \Exception
  */
 public function buildBefore(BuildBefore $event)
 {
     $datagridConfig = $event->getConfig();
     if ('custom_entity' !== $datagridConfig->offsetGetByPath('[extends]')) {
         return;
     }
     $indexAction = $this->actionFactory->getAction($datagridConfig->getName(), 'index');
     if (!$indexAction) {
         throw new \Exception(sprintf('No index action configured for %s', $datagridConfig->getName()));
     }
     $this->setSource($datagridConfig, $indexAction);
     $this->setRowActions($datagridConfig, $indexAction);
     $this->setMassActions($datagridConfig, $indexAction);
 }
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $currencies = $this->getCurrencies();
     if (!$currencies) {
         return;
     }
     $config = $event->getConfig();
     foreach ($currencies as $currencyIsoCode) {
         $columnName = $this->buildColumnName($currencyIsoCode);
         $column = ['label' => $this->translator->trans('orob2b.pricing.productprice.price_in_%currency%', ['%currency%' => $currencyIsoCode]), 'type' => 'twig', 'template' => 'OroB2BPricingBundle:Datagrid:Column/productPrice.html.twig', 'frontend_type' => 'html'];
         $config->offsetSetByPath(sprintf('[columns][%s]', $columnName), $column);
         $filter = ['type' => 'product-price', 'data_name' => $currencyIsoCode];
         $config->offsetSetByPath(sprintf('[filters][columns][%s]', $columnName), $filter);
     }
 }
Пример #27
0
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $parameters = $event->getDatagrid()->getParameters();
     $permission = $parameters->get('permission');
     $entityClass = str_replace('_', '\\', $parameters->get('entity'));
     $entityId = $parameters->get('entity_id');
     if ($entityId) {
         $object = $this->em->getRepository($entityClass)->find((int) $entityId);
     } else {
         $object = 'entity:' . $entityClass;
     }
     $observer = new OneShotIsGrantedObserver();
     $this->aclVoter->addOneShotIsGrantedObserver($observer);
     $this->getSecurityContext()->isGranted($permission, $object);
     $user = $this->getSecurityContext()->getToken()->getUser();
     $organization = $this->getSecurityContext()->getToken()->getOrganizationContext();
     $accessLevel = $observer->getAccessLevel();
     $where = $config->offsetGetByPath('[source][query][where][and]', []);
     /** todo: refactor this check usages */
     if ($accessLevel == AccessLevel::BASIC_LEVEL) {
         $where = array_merge($where, ['u.id = ' . $user->getId()]);
     } elseif ($accessLevel == AccessLevel::GLOBAL_LEVEL) {
         $leftJoins = $config->offsetGetByPath('[source][query][join][inner]', []);
         $leftJoins[] = ['join' => 'u.organizations', 'alias' => 'org'];
         $config->offsetSetByPath('[source][query][join][inner]', $leftJoins);
         $where = array_merge($where, ['org.id in (' . $organization->getId() . ')']);
     } elseif ($accessLevel !== AccessLevel::SYSTEM_LEVEL) {
         $resultBuIds = [];
         if ($accessLevel == AccessLevel::LOCAL_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserBusinessUnitIds($user->getId(), $organization->getId());
         } elseif ($accessLevel == AccessLevel::DEEP_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserSubordinateBusinessUnitIds($user->getId(), $organization->getId());
         }
         $leftJoins = $config->offsetGetByPath('[source][query][join][inner]', []);
         $leftJoins[] = ['join' => 'u.businessUnits', 'alias' => 'bu'];
         $config->offsetSetByPath('[source][query][join][inner]', $leftJoins);
         $where = array_merge($where, ['bu.id in (' . implode(', ', $resultBuIds) . ')']);
     }
     if (count($where)) {
         $config->offsetSetByPath('[source][query][where][and]', $where);
     }
 }
 /**
  * Reconfigure sorters
  *
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $sortersPath = sprintf('%s[%s]', SorterConfiguration::SORTERS_PATH, Configuration::COLUMNS_KEY);
     $sorters = $config->offsetGetByPath($sortersPath);
     $datasourceType = $config->offsetGetByPath(Builder::DATASOURCE_TYPE_PATH);
     $sorterType = null;
     if (DatasourceTypes::DATASOURCE_PRODUCT === $datasourceType) {
         $sorterType = 'product_field';
     } elseif (DatasourceSupportResolver::DATASOURCE_SUPPORT_MONGODB === $this->supportResolver->getSupport($datasourceType)) {
         $sorterType = 'mongodb_field';
     }
     if (null === $sorterType) {
         return;
     }
     foreach ($sorters as $sorterName => $sorterConfig) {
         if (!isset($sorterConfig['sorter'])) {
             $config->offsetSetByPath(sprintf('%s[%s][sorter]', $sortersPath, $sorterName), $sorterType);
         }
     }
 }
Пример #29
0
 /**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $parameters = $event->getDatagrid()->getParameters();
     $permission = $parameters->get('permission');
     if ($parameters->get('entity')) {
         $entityClass = str_replace('_', '\\', $parameters->get('entity'));
     } else {
         $entityClass = 'Oro\\Bundle\\UserBundle\\Entity\\User';
     }
     $entityId = $parameters->get('entity_id');
     if ($entityId) {
         $object = $this->em->getRepository($entityClass)->find((int) $entityId);
     } else {
         $object = 'entity:' . $entityClass;
     }
     $observer = new OneShotIsGrantedObserver();
     $this->aclVoter->addOneShotIsGrantedObserver($observer);
     $this->getSecurityContext()->isGranted($permission, $object);
     $accessLevel = $observer->getAccessLevel();
     $config = $event->getConfig();
     $user = $this->getSecurityContext()->getToken()->getUser();
     $organization = $this->getSecurityContext()->getToken()->getOrganizationContext();
     $this->applyACL($config, $accessLevel, $user, $organization);
 }
Пример #30
0
 /**
  * Used only for auditfield-log-grid grid (subscribed in services.yml)
  *
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     $fieldName = $event->getDatagrid()->getParameters()->get(self::GRID_PARAM_FIELD_NAME, false);
     $config->offsetSetByPath('[columns][diffs][context][field_name]', $fieldName);
 }