Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function getFields(DatagridConfiguration $config)
 {
     $entityClassName = $this->entityClassResolver->getEntityClass($this->getEntityName($config));
     if (!$this->configManager->hasConfig($entityClassName)) {
         return [];
     }
     $entityConfigProvider = $this->configManager->getProvider('entity');
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $viewConfigProvider = $this->configManager->getProvider('view');
     $datagridConfigProvider = $this->configManager->getProvider('datagrid');
     $fields = [];
     $fieldIds = $entityConfigProvider->getIds($entityClassName);
     /** @var FieldConfigId $fieldId */
     foreach ($fieldIds as $fieldId) {
         $extendConfig = $extendConfigProvider->getConfigById($fieldId);
         if ($extendConfig->is('owner', ExtendScope::OWNER_CUSTOM) && ExtendHelper::isFieldAccessible($extendConfig) && $datagridConfigProvider->getConfigById($fieldId)->is('is_visible')) {
             $viewConfig = $viewConfigProvider->getConfig($entityClassName, $fieldId->getFieldName());
             $fields[] = ['id' => $fieldId, 'priority' => $viewConfig->get('priority', false, 0)];
         }
     }
     ArrayUtil::sortBy($fields, true);
     return array_map(function ($field) {
         return $field['id'];
     }, $fields);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (!$this->isApplicable($options)) {
         return;
     }
     $className = $options['data_class'];
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $viewConfigProvider = $this->configManager->getProvider('view');
     $fields = [];
     $formConfigs = $this->configManager->getProvider('form')->getConfigs($className);
     foreach ($formConfigs as $formConfig) {
         if (!$formConfig->is('is_enabled')) {
             continue;
         }
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $formConfig->getId();
         $fieldName = $fieldConfigId->getFieldName();
         $extendConfig = $extendConfigProvider->getConfig($className, $fieldName);
         if (!$this->isApplicableField($extendConfig, $extendConfigProvider)) {
             continue;
         }
         $fields[$fieldName] = ['priority' => $viewConfigProvider->getConfig($className, $fieldName)->get('priority', false, 0)];
     }
     ArrayUtil::sortBy($fields, true);
     foreach ($fields as $fieldName => $priority) {
         $builder->add($fieldName);
     }
 }
Пример #3
0
 /**
  * Sorts items by a value of "position" attribute
  *
  * @param array $items The array to be processed
  */
 protected function sortItemsByPosition(array &$items)
 {
     ArrayUtil::sortBy($items, false, 'position');
     foreach ($items as &$item) {
         unset($item['position']);
     }
 }
Пример #4
0
 /**
  * Sorts the routes by priority
  */
 public function sortByPriority()
 {
     $routes = $this->all();
     ArrayUtil::sortBy($routes, false, function (Route $route) {
         return $route->getOption('priority') ?: 0;
     });
     $this->setRoutes($routes);
 }
Пример #5
0
 /**
  * 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;
         }
     }
     ArrayUtil::sortBy($array, self::getOption($options, 'reverse', false), self::getOption($options, 'property', 'priority'), $sortingFlags);
     return $array;
 }
Пример #6
0
 /**
  * @param object      $entity
  * @param null|string $entityClass
  * @return array
  */
 public function getFields($entity, $entityClass = null)
 {
     $dynamicRow = [];
     if (null === $entityClass) {
         $entityClass = ClassUtils::getRealClass($entity);
     }
     $fields = $this->extendProvider->filter([$this, 'filterFields'], $entityClass);
     foreach ($fields as $field) {
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $field->getId();
         $fieldName = $fieldConfigId->getFieldName();
         $fieldType = $fieldConfigId->getFieldType();
         $value = $this->propertyAccessor->getValue($entity, $fieldName);
         $event = new ValueRenderEvent($entity, $value, $fieldConfigId);
         $this->eventDispatcher->dispatch(EntityExtendEvents::BEFORE_VALUE_RENDER, $event);
         $fieldConfig = $this->entityProvider->getConfigById($fieldConfigId);
         $dynamicRow[$fieldName] = ['type' => $fieldType, 'label' => $fieldConfig->get('label') ?: $fieldName, 'value' => $event->getFieldViewValue(), 'priority' => $this->viewProvider->getConfigById($fieldConfigId)->get('priority', false, 0)];
     }
     ArrayUtil::sortBy($dynamicRow, true);
     foreach ($dynamicRow as &$row) {
         unset($row['priority']);
     }
     return $dynamicRow;
 }
Пример #7
0
 /**
  * Sorts the given items by 'order' attribute
  *
  * @param array $items
  * @return mixed
  */
 protected function sortItems($items)
 {
     ArrayUtil::sortBy($items, false, 'order');
     return array_keys($items);
 }
Пример #8
0
 protected function sortSubBlocks()
 {
     ArrayUtil::sortBy($this->subBlocks, true);
 }
Пример #9
0
 public function testSortByCallable()
 {
     $obj1 = $this->createObject(['name' => '1', 'priority' => null]);
     $obj2 = $this->createObject(['name' => '2', 'priority' => 100]);
     $obj3 = $this->createObject(['name' => '3', 'priority' => 0]);
     $array = [$obj1, $obj2, $obj3];
     ArrayUtil::sortBy($array, false, [$this, 'getObjectPriority']);
     $this->assertSame([$obj1, $obj3, $obj2], $array);
 }
Пример #10
0
 /**
  * @param ConnectorInterface[] $connectors
  * @return ConnectorInterface[]
  */
 protected function getSortedConnectors(array $connectors)
 {
     $sortCallback = function ($connector) {
         return $connector instanceof OrderedConnectorInterface ? $connector->getOrder() : OrderedConnectorInterface::DEFAULT_ORDER;
     };
     ArrayUtil::sortBy($connectors, false, $sortCallback);
     return $connectors;
 }
Пример #11
0
 /**
  * @return array|StrategyInterface[]
  */
 protected function getElements()
 {
     if (!$this->ordered) {
         ArrayUtil::sortBy($this->elements, true, static::PRIORITY_KEY);
         $this->ordered = true;
     }
     return $this->elements;
 }
Пример #12
0
 /**
  * Sorts an array by specified property.
  *
  * This method uses the stable sorting algorithm. See http://en.wikipedia.org/wiki/Sorting_algorithm#Stability
  * Please use this method only if you really need stable sorting because this method is not so fast
  * as native PHP sort functions.
  *
  * @param array $array The array to be sorted
  * @param bool $reverse Indicates whether the sorting should be performed
  *                                                   in reverse order
  * @param string|PropertyPathInterface $propertyPath The path of the property by which the array should be sorted
  * @param int $sortingFlags The sorting type. Can be SORT_NUMERIC or SORT_STRING
  *                                                   Also SORT_STRING can be combined with SORT_FLAG_CASE to sort
  *                                                   strings case-insensitively
  *
  * @deprecated since 1.9. Use Oro\Component\PhpUtils\ArrayUtil::sortBy instead
  */
 public static function sortBy(array &$array, $reverse = false, $propertyPath = 'priority', $sortingFlags = SORT_NUMERIC)
 {
     ArrayUtil::sortBy($array, $reverse, $propertyPath, $sortingFlags);
 }
Пример #13
0
 /**
  * @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);
     }
     ArrayUtil::sortBy($calendars, false, 'position');
 }