コード例 #1
0
 /**
  * @param string $datagridName
  * @param array  $datagridDefinition
  * @param bool   $recursion
  *
  * @return array
  */
 public function resolve($datagridName, $datagridDefinition, $recursion = false)
 {
     foreach ($datagridDefinition as $key => $val) {
         if (is_array($val)) {
             $this->parentNode = $val;
             $datagridDefinition[$key] = $this->resolve($datagridName, $val, true);
             continue;
         }
         $val = $this->resolveSystemCall($datagridName, $key, $val);
         if (!$recursion && self::KEY_EXTENDS === $key) {
             // get parent grid definition, resolved
             $definition = $this->container->get('oro_datagrid.datagrid.manager')->getConfigurationForGrid($val);
             // merge them and remove extend directive
             $datagridDefinition = ArrayUtils::arrayMergeRecursiveDistinct($definition->toArray(), $datagridDefinition);
             unset($datagridDefinition['extends']);
             $datagridDefinition[self::KEY_EXTENDED_FROM] = isset($datagridDefinition[self::KEY_EXTENDED_FROM]) ? $datagridDefinition[self::KEY_EXTENDED_FROM] : [];
             $datagridDefinition[self::KEY_EXTENDED_FROM][] = $val;
             // run resolve again on merged grid definition
             $datagridDefinition = $this->resolve($val, $datagridDefinition);
             // break current loop cause we've just extended grid definition
             break;
         }
         $datagridDefinition[$key] = $val;
     }
     return $datagridDefinition;
 }
コード例 #2
0
ファイル: ReplaceStrategy.php プロジェクト: Maksold/platform
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $sourceEntity = $fieldData->getSourceEntity();
     if ($masterEntity->getId() !== $sourceEntity->getId()) {
         $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $masterEntity->getId());
         $notes = $queryBuilder->getQuery()->getResult();
         if (!empty($notes)) {
             $entityManager = $this->doctrineHelper->getEntityManager(current($notes));
             foreach ($notes as $note) {
                 $entityManager->remove($note);
             }
         }
         $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $sourceEntity->getId());
         $notes = $queryBuilder->getQuery()->getResult();
         if (!empty($notes)) {
             foreach ($notes as $note) {
                 $note->setTarget($masterEntity);
             }
         }
         $fieldMetadata = $fieldData->getMetadata();
         $activityClass = $fieldMetadata->get('type');
         $entityClass = ClassUtils::getRealClass($sourceEntity);
         $queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass);
         $activityListItems = $queryBuilder->getQuery()->getResult();
         $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
     }
 }
コード例 #3
0
 /**
  * @param AbstractQueryDesigner         $value
  * @param GroupingConstraint|Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     $definition = json_decode($value->getDefinition(), true);
     if (empty($definition['columns'])) {
         return;
     }
     $columns = $definition['columns'];
     $aggregateColumns = array_filter($columns, function (array $column) {
         return !empty($column['func']);
     });
     if (empty($aggregateColumns)) {
         return;
     }
     $groupingColumns = [];
     if (!empty($definition['grouping_columns'])) {
         $groupingColumns = $definition['grouping_columns'];
     }
     $groupingColumnNames = ArrayUtils::arrayColumn($groupingColumns, 'name');
     $columnNames = ArrayUtils::arrayColumn($columns, 'name');
     $columnNamesToCheck = array_diff($columnNames, ArrayUtils::arrayColumn($aggregateColumns, 'name'));
     $columnsToGroup = array_diff($columnNamesToCheck, $groupingColumnNames);
     if (empty($columnsToGroup)) {
         return;
     }
     $columnLabels = [];
     foreach ($columns as $column) {
         if (in_array($column['name'], $columnsToGroup)) {
             $columnLabels[] = $column['label'];
         }
     }
     $this->context->addViolation($this->translator->trans($constraint->message, ['%columns%' => implode(', ', $columnLabels)]));
 }
コード例 #4
0
 /**
  * Sorts items by a value of "position" attribute
  *
  * @param array $items The array to be processed
  */
 protected function sortItemsByPosition(array &$items)
 {
     ArrayUtils::sortBy($items, false, 'position');
     foreach ($items as &$item) {
         unset($item['position']);
     }
 }
コード例 #5
0
 /**
  * @param array $response
  * @param string $container
  * @param string|null $key
  *
  * @return array
  */
 protected function getArrayData(array $response, $container, $key = null)
 {
     if (!empty($response[$container])) {
         if ($key) {
             return ArrayUtils::arrayColumn($response[$container], $key);
         }
         return $response[$container];
     }
     return [];
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     /** @var UniqueKeys $constraint */
     $names = ArrayUtils::arrayColumn($value, 'name');
     if ($names && $names != array_unique($names)) {
         $this->context->addViolation($constraint->message);
         return;
     }
     $keys = ArrayUtils::arrayColumn($value, 'key');
     if ($keys && $keys != array_unique($keys, SORT_REGULAR)) {
         $this->context->addViolation($constraint->message);
         return;
     }
 }
コード例 #7
0
ファイル: SortByExtension.php プロジェクト: Maksold/platform
 /**
  * Sorts an array by specified property.
  *
  * This method uses the stable sorting algorithm. See http://en.wikipedia.org/wiki/Sorting_algorithm#Stability
  *
  * Supported options:
  *  property     [string]  The path of the property by which the array should be sorted. Defaults to 'priority'
  *  reverse      [boolean] Indicates whether the sorting should be performed in reverse order. Defaults to FALSE
  *  sorting-type [string]  number, string or string-case (for case-insensitive sorting). Defaults to 'number'
  *
  * @param array $array   The array to be sorted
  * @param array $options The sorting options
  *
  * @return array The sorted array
  */
 public function sortBy(array $array, array $options = [])
 {
     $sortingType = self::getOption($options, 'sorting-type', 'number');
     if ($sortingType === 'number') {
         $sortingFlags = SORT_NUMERIC;
     } else {
         $sortingFlags = SORT_STRING;
         if ($sortingType === 'string-case') {
             $sortingFlags |= SORT_FLAG_CASE;
         }
     }
     ArrayUtils::sortBy($array, self::getOption($options, 'reverse', false), self::getOption($options, 'property', 'priority'), $sortingFlags);
     return $array;
 }
コード例 #8
0
 /**
  * @param DatagridConfiguration $configuration
  * @param string                $gridName
  *
  * @return DatagridConfiguration
  */
 public function extendConfiguration(DatagridConfiguration $configuration, $gridName)
 {
     $gridConfiguration = $this->configurationProvider->getConfiguration($gridName);
     $scopes = array_diff(array_keys($gridConfiguration->getIterator()->getArrayCopy()), ['name']);
     foreach ($scopes as $scope) {
         $path = sprintf('[%s]', $scope);
         $additionalParams = $gridConfiguration->offsetGetByPath($path);
         $baseParams = $configuration->offsetGetByPath($path, []);
         if (!is_array($additionalParams) || !is_array($baseParams)) {
             continue;
         }
         $configuration->offsetSetByPath($path, ArrayUtils::arrayMergeRecursiveDistinct($baseParams, $additionalParams));
     }
     return $configuration;
 }
コード例 #9
0
ファイル: ConfigurationPass.php プロジェクト: Kostel/platform
 /**
  * Collect datagrid configurations files and pass them to the configuration provider
  *
  * @param ContainerBuilder $container
  */
 protected function registerConfigFiles(ContainerBuilder $container)
 {
     if ($container->hasDefinition(self::PROVIDER_SERVICE_ID)) {
         $config = [];
         $configLoader = new CumulativeConfigLoader('oro_datagrid', new YamlCumulativeFileLoader('Resources/config/datagrid.yml'));
         $resources = $configLoader->load($container);
         foreach ($resources as $resource) {
             if (isset($resource->data[self::ROOT_PARAMETER]) && is_array($resource->data[self::ROOT_PARAMETER])) {
                 $config = ArrayUtils::arrayMergeRecursiveDistinct($config, $resource->data[self::ROOT_PARAMETER]);
             }
         }
         $configProviderDef = $container->getDefinition(self::PROVIDER_SERVICE_ID);
         $configProviderDef->replaceArgument(0, $config);
     }
 }
コード例 #10
0
ファイル: UniteStrategy.php プロジェクト: Maksold/platform
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $fieldMetadata = $fieldData->getMetadata();
     $entities = $fieldData->getEntityData()->getEntities();
     foreach ($entities as $sourceEntity) {
         if ($sourceEntity->getId() !== $masterEntity->getId()) {
             $entityClass = ClassUtils::getRealClass($masterEntity);
             $activityClass = $fieldMetadata->get('type');
             $queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass);
             $activityListItems = $queryBuilder->getQuery()->getResult();
             $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
             $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
             $activityIds = ArrayUtils::arrayColumn($activityListItems, 'relatedActivityId');
             $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId(), $activityClass);
         }
     }
 }
コード例 #11
0
 /**
  * @param DataInterface $data
  * @param array         $chartOptions
  *
  * @return DataInterface
  */
 public function transform(DataInterface $data, array $chartOptions)
 {
     $this->initialize($data, $chartOptions);
     if (!$data->toArray()) {
         return new ArrayData([]);
     }
     $keys = array_unique(ArrayUtils::arrayColumn($this->sourceData, $this->groupingOption));
     $values = array_combine($keys, array_fill(0, sizeof($keys), $this->getLabels()));
     foreach ($values as $group => &$value) {
         array_walk($value, function (&$label) use($group) {
             $counts = array_map(function ($item) use($label, $group) {
                 if ($item[$this->groupingOption] == $group && $item[$this->labelKey] == $label) {
                     return $item[$this->valueKey];
                 }
                 return 0;
             }, $this->sourceData);
             $label = ['label' => $label, 'value' => array_sum($counts)];
         });
     }
     return new ArrayData($values);
 }
コード例 #12
0
 /** {@inheritdoc} */
 public function process(array $data, Request $request)
 {
     if (empty($data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY]) || !is_array($data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY])) {
         return;
     }
     $data = $data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY];
     $shoppingListId = (int) $request->get(sprintf('%s[%s]', QuickAddType::NAME, QuickAddType::ADDITIONAL_FIELD_NAME), null, true);
     $shoppingList = $this->shoppingListLineItemHandler->getShoppingList($shoppingListId);
     $productSkus = ArrayUtils::arrayColumn($data, 'productSku');
     $productIds = $this->getProductRepository()->getProductsIdsBySku($productSkus);
     $productSkuQuantities = array_combine($productSkus, ArrayUtils::arrayColumn($data, 'productQuantity'));
     $productIdsQuantities = array_combine($productIds, $productSkuQuantities);
     /** @var Session $session */
     $session = $request->getSession();
     $flashBag = $session->getFlashBag();
     try {
         $entitiesCount = $this->shoppingListLineItemHandler->createForShoppingList($shoppingList, array_values($productIds), $productIdsQuantities);
         $flashBag->add('success', $this->messageGenerator->getSuccessMessage($shoppingListId, $entitiesCount));
     } catch (AccessDeniedException $e) {
         $flashBag->add('error', $this->messageGenerator->getFailedMessage());
     }
 }
コード例 #13
0
 /**
  * @param DatagridConfiguration $configuration
  * @param string                $gridName
  *
  * @return DatagridConfiguration
  */
 public function extendConfiguration(DatagridConfiguration $configuration, $gridName)
 {
     $gridConfiguration = $this->configurationProvider->getConfiguration($gridName);
     $basicAlias = $configuration->offsetGetByPath('[source][query][from][0][alias]');
     foreach ($this->pathsToFix as $path) {
         $forFix = $gridConfiguration->offsetGetByPath($path);
         if ($forFix) {
             $gridConfiguration->offsetSetByPath($path, $this->fixMixinAlias($basicAlias, $forFix));
         }
     }
     $scopes = array_diff(array_keys($gridConfiguration->getIterator()->getArrayCopy()), ['name']);
     foreach ($scopes as $scope) {
         $path = sprintf('[%s]', $scope);
         $additionalParams = $gridConfiguration->offsetGetByPath($path);
         $baseParams = $configuration->offsetGetByPath($path, []);
         if (!is_array($additionalParams) || !is_array($baseParams)) {
             continue;
         }
         $configuration->offsetSetByPath($path, ArrayUtils::arrayMergeRecursiveDistinct($baseParams, $additionalParams));
     }
     return $configuration;
 }
コード例 #14
0
ファイル: ReplaceStrategy.php プロジェクト: Maksold/platform
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $sourceEntity = $fieldData->getSourceEntity();
     if ($masterEntity->getId() !== $sourceEntity->getId()) {
         $fieldMetadata = $fieldData->getMetadata();
         $activityClass = $fieldMetadata->get('type');
         $activityListItems = $this->getActivitiesByEntity($masterEntity, $activityClass);
         $activityIds = ArrayUtils::arrayColumn($activityListItems, 'relatedActivityId');
         $activities = $this->doctrineHelper->getEntityRepository($activityClass)->findBy(['id' => $activityIds]);
         foreach ($activities as $activity) {
             $this->activityManager->removeActivityTarget($activity, $masterEntity);
         }
         $activityListItems = $this->getActivitiesByEntity($sourceEntity, $activityClass);
         $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
         $entityClass = ClassUtils::getRealClass($masterEntity);
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
         $activityIds = ArrayUtils::arrayColumn($activityListItems, 'relatedActivityId');
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId(), $activityClass);
     }
 }
コード例 #15
0
 /**
  * Add "in" expression as page limit to query builder
  *
  * @param QueryBuilder $dataQueryBuilder
  * @param ResultsObject $pageData
  * @param bool $perPage
  */
 protected function addPageLimits(QueryBuilder $dataQueryBuilder, $pageData, $perPage)
 {
     $rootIdentifiers = $this->getRootIds($dataQueryBuilder);
     if (!$perPage) {
         $query = clone $this->masterQB;
         $data = $query->getQuery()->setFirstResult(null)->setMaxResults(null)->getScalarResult();
     } else {
         $data = $pageData['data'];
     }
     foreach ($rootIdentifiers as $identifier) {
         $ids = ArrayUtils::arrayColumn($data, $identifier['alias']);
         $field = isset($identifier['entityAlias']) ? $identifier['entityAlias'] . '.' . $identifier['fieldAlias'] : $identifier['fieldAlias'];
         $filteredIds = array_filter($ids);
         if (empty($filteredIds)) {
             continue;
         }
         $dataQueryBuilder->andWhere($dataQueryBuilder->expr()->in($field, $ids));
     }
 }
コード例 #16
0
ファイル: Configuration.php プロジェクト: xamin123/platform
 /**
  * Sorts the given items by 'order' attribute
  *
  * @param array $items
  * @return mixed
  */
 protected function sortItems($items)
 {
     ArrayUtils::sortBy($items, false, 'order');
     return array_keys($items);
 }
コード例 #17
0
ファイル: CalendarManager.php プロジェクト: Maksold/platform
 /**
  * @param array $calendars
  */
 protected function normalizeCalendarData(array &$calendars)
 {
     // apply default values and remove redundant properties
     $defaultValues = $this->getCalendarDefaultValues();
     foreach ($calendars as &$calendar) {
         $this->applyCalendarDefaultValues($calendar, $defaultValues);
     }
     ArrayUtils::sortBy($calendars, false, 'position');
 }
コード例 #18
0
ファイル: Config.php プロジェクト: Maksold/platform
 /**
  * Goes across bundles and collects configurations
  *
  * @return array
  */
 public function collectConfigs()
 {
     if (!$this->collectedConfig) {
         $config = $this->container->getParameter('oro_require_js');
         $bundles = $this->container->getParameter('kernel.bundles');
         foreach ($bundles as $bundle) {
             $reflection = new \ReflectionClass($bundle);
             if (is_file($file = dirname($reflection->getFilename()) . '/Resources/config/requirejs.yml')) {
                 $requirejs = Yaml::parse(realpath($file));
                 $config = ArrayUtils::arrayMergeRecursiveDistinct($config, $requirejs);
             }
         }
         $this->collectedConfig = $config;
     }
     return $this->collectedConfig;
 }
コード例 #19
0
 /**
  * @param string $entity
  * @return array
  */
 protected function getEntityLevelContactInfoColumns($entity)
 {
     $contactInfoColumns = array();
     if ($this->configProvider->hasConfig($entity)) {
         $entityContactInformation = $this->configProvider->getConfig($entity)->get('contact_information');
         if ($entityContactInformation) {
             foreach ($entityContactInformation as $contactInfoType => $contactInfoFields) {
                 $entityColumns = ArrayUtils::arrayColumn($contactInfoFields, 'fieldName');
                 foreach ($entityColumns as $entityColumn) {
                     $contactInfoColumns[$entityColumn] = $contactInfoType;
                 }
             }
         }
     }
     return $contactInfoColumns;
 }
コード例 #20
0
ファイル: FormConfig.php プロジェクト: Maksold/platform
 protected function sortBlocks()
 {
     ArrayUtils::sortBy($this->blocks, true);
 }
コード例 #21
0
 /**
  * Merge configuration into one config
  *
  * @param ContainerBuilder $container
  * @param string $name
  * @param array $config
  *
  * @throws \RuntimeException
  */
 private function mergeConfigIntoOne(ContainerBuilder $container, $name, array $config = [])
 {
     if (!$container instanceof ExtendedContainerBuilder) {
         throw new \RuntimeException(sprintf('%s is expected to be passed into OroPlatformExtension', 'Oro\\Component\\DependencyInjection\\ExtendedContainerBuilder'));
     }
     $originalConfig = $container->getExtensionConfig($name);
     if (!count($originalConfig)) {
         $originalConfig[] = array();
     }
     $mergedConfig = ArrayUtils::arrayMergeRecursiveDistinct($originalConfig[0], $config);
     $originalConfig[0] = $mergedConfig;
     $container->setExtensionConfig($name, $originalConfig);
 }
コード例 #22
0
ファイル: ArrayUtilsTest.php プロジェクト: Maksold/platform
 /**
  * @dataProvider mergeDataProvider
  *
  * @param array $expected
  * @param array $first
  * @param array $second
  */
 public function testArrayMergeRecursiveDistinct(array $expected, array $first, array $second)
 {
     $this->assertEquals($expected, ArrayUtils::arrayMergeRecursiveDistinct($first, $second));
 }