Esempio n. 1
0
 /**
  * @see \Oro\Bundle\EntityBundle\Provider\EntityFieldProvider::getFields
  *
  * @param string $entityName
  * @param bool   $withRelations
  * @param bool   $withVirtualFields
  * @param bool   $withEntityDetails
  * @param bool   $withUnidirectional
  * @param bool   $applyExclusions
  * @param bool   $translate
  * @return array
  */
 public function getFields($entityName, $withRelations = false, $withVirtualFields = false, $withEntityDetails = false, $withUnidirectional = false, $applyExclusions = false, $translate = true)
 {
     $args = func_get_args();
     $cacheKey = implode(':', $args);
     if (!array_key_exists($cacheKey, $this->fieldsCache)) {
         $this->fieldsCache[$cacheKey] = $this->fieldProvider->getFields($entityName, $withRelations, $withVirtualFields, $withEntityDetails, $withUnidirectional, $applyExclusions, $translate);
     }
     return $this->fieldsCache[$cacheKey];
 }
Esempio n. 2
0
 /**
  * @return array
  */
 protected function getPropertyChoiceList()
 {
     $choices = [];
     if (!$this->entityClass) {
         return $choices;
     }
     $fields = $this->entityFieldProvider->getFields($this->entityClass);
     foreach ($fields as $field) {
         if (!in_array($field['type'], ['integer', 'string', 'smallint', 'decimal', 'bigint', 'text', 'money'])) {
             continue;
         }
         $choices[$field['name']] = $field['label'] ?: $field['name'];
     }
     return $choices;
 }
 /**
  * Returns a list of choices
  *
  * @param string $entityName             Entity name. Can be full class name or short form: Bundle:Entity.
  * @param bool   $withRelations          Indicates whether fields of related entities should be returned as well.
  * @param int    $deepLevel              The maximum deep level of related entities.
  * @param bool   $lastDeepLevelRelations The maximum deep level of related entities.
  * @return array of entity fields
  *                                       key = field name, value = ChoiceListItem
  */
 protected function getChoices($entityName, $withRelations, $deepLevel = 0, $lastDeepLevelRelations = false)
 {
     $choiceFields = array();
     $choiceRelations = array();
     $isRelationsWithFields = false;
     $fields = $this->provider->getFields($entityName, $withRelations, true, $deepLevel, $lastDeepLevelRelations);
     foreach ($fields as $field) {
         $attributes = [];
         foreach ($field as $key => $val) {
             if (!in_array($key, ['name'])) {
                 $attributes['data-' . str_replace('_', '-', $key)] = $val;
             }
         }
         if (!isset($field['related_entity_name'])) {
             $choiceFields[$field['name']] = new ChoiceListItem($field['label'], $attributes);
         } else {
             if (isset($field['related_entity_fields'])) {
                 $isRelationsWithFields = true;
                 $relatedFields = array();
                 foreach ($field['related_entity_fields'] as $relatedField) {
                     $attributes = [];
                     foreach ($relatedField as $key => $val) {
                         if (!in_array($key, ['related_entity_fields'])) {
                             $attributes['data-' . str_replace('_', '-', $key)] = $val;
                         }
                     }
                     $relatedFields[sprintf('%s,%s::%s', $field['name'], $field['related_entity_name'], $relatedField['name'])] = new ChoiceListItem($relatedField['label'], $attributes);
                 }
                 $choiceRelations[$field['label']] = $relatedFields;
             } else {
                 $choiceRelations[$field['name']] = new ChoiceListItem($field['label'], $attributes);
             }
         }
     }
     if (empty($choiceRelations)) {
         return $choiceFields;
     }
     $choices = array();
     if (!empty($choiceFields)) {
         $choices[$this->translator->trans('oro.entity.form.entity_fields')] = $choiceFields;
     }
     if ($isRelationsWithFields) {
         $choices = array_merge($choices, $choiceRelations);
     } else {
         $choices[$this->translator->trans('oro.entity.form.entity_related')] = $choiceRelations;
     }
     return $choices;
 }
 /**
  * Returns a list of choices
  *
  * @param string $entityName           Entity name. Can be full class name or short form: Bundle:Entity.
  * @param bool   $withRelations        Indicates whether association fields should be returned as well.
  * @param bool   $withVirtualFields    Indicates whether virtual fields should be returned as well.
  * @return array of entity fields
  *                                  key = field name, value = ChoiceListItem
  */
 protected function getChoices($entityName, $withRelations, $withVirtualFields)
 {
     $choiceFields = [];
     $choiceRelations = [];
     $fields = $this->entityFieldProvider->getFields($entityName, $withRelations, $withVirtualFields, true);
     foreach ($fields as $field) {
         $attributes = [];
         foreach ($field as $key => $val) {
             if (!in_array($key, ['name', 'related_entity_fields'])) {
                 $attributes['data-' . $key] = $val;
             }
         }
         if (!isset($field['relation_type'])) {
             $choiceFields[$field['name']] = new ChoiceListItem($field['label'], $attributes);
         } else {
             $choiceRelations[$field['name']] = new ChoiceListItem($field['label'], $attributes);
         }
     }
     if (empty($choiceRelations)) {
         return $choiceFields;
     }
     $choices = [];
     if (!empty($choiceFields)) {
         $choices[$this->translator->trans('oro.entity.form.entity_fields')] = $choiceFields;
     }
     $choices[$this->translator->trans('oro.entity.form.entity_related')] = $choiceRelations;
     return $choices;
 }
 /**
  * {@inheritdoc}
  */
 protected function getOptions(ConfigInterface $extendConfig, FieldConfigId $fieldConfigId)
 {
     $options = parent::getOptions($extendConfig, $fieldConfigId);
     $className = $fieldConfigId->getClassName();
     $fieldName = $fieldConfigId->getFieldName();
     switch ($fieldConfigId->getFieldType()) {
         case RelationType::TO_ONE:
             if (empty($this->fieldList) && $this->fieldProvider) {
                 $fieldList = $this->fieldProvider->getFields($className, true);
                 foreach ($fieldList as $entityField) {
                     $this->fieldList[$entityField['name']] = $entityField;
                 }
             }
             $options['class'] = $this->fieldList[$fieldName]['related_entity_name'];
             break;
     }
     return $options;
 }
 /**
  * @param array $expected
  *
  * @dataProvider getFieldsWithVirtualRelationsAndEnumsDataProvider
  */
 public function testGetFieldsWithVirtualRelationsAndEnums(array $expected)
 {
     $className = 'Acme\\Entity\\Test';
     $config = [$className => ['config' => ['label' => 'Test Label', 'plural_label' => 'Test Plural Label', 'icon' => 'icon-test'], 'fields' => ['field1' => ['type' => 'integer', 'identifier' => true, 'config' => ['label' => 'Field 1']]], 'relations' => ['rel1' => ['target_class' => 'Acme\\EnumValue1', 'type' => 'ref-one', 'config' => ['label' => 'Enum Field']], 'rel2' => ['target_class' => 'Acme\\EnumValue2', 'type' => 'ref-many', 'config' => ['label' => 'Multi Enum Field']]]]];
     $this->prepare($config);
     $this->virtualFieldProvider->expects($this->once())->method('getVirtualFields')->with($className)->will($this->returnValue(['rel1', 'rel2']));
     $this->virtualRelationProvider->expects($this->once())->method('getVirtualRelations')->with($className)->will($this->returnValue(['virtual_relation' => ['relation_type' => 'oneToMany', 'related_entity_name' => 'OtherEntity', 'query' => ['select' => ['select expression'], 'join' => ['join expression']]]]));
     $this->virtualFieldProvider->expects($this->exactly(2))->method('getVirtualFieldQuery')->will($this->returnValueMap([[$className, 'rel1', ['select' => ['return_type' => 'enum', 'filter_by_id' => true]]], [$className, 'rel2', ['select' => ['return_type' => 'multiEnum', 'filter_by_id' => true]]]]));
     $result = $this->provider->getFields('Acme:Test', true, true);
     $this->assertEquals($expected, $result);
 }
 /**
  * @param string $entity
  * @return array
  */
 public function getEntityContactInformationColumnsInfo($entity)
 {
     $fields = array();
     $contactInformationFields = $this->getEntityContactInformationColumns($entity);
     $entityFields = $this->fieldProvider->getFields($entity, false, true);
     foreach ($entityFields as $entityField) {
         if (array_key_exists($entityField['name'], $contactInformationFields)) {
             $entityField['contact_information_type'] = $contactInformationFields[$entityField['name']];
             $fields[] = $entityField;
         }
     }
     return $fields;
 }
 /**
  * Returns source data for the given entity
  *
  * @param string $entityName             Entity name. Can be full class name or short form: Bundle:Entity.
  * @param bool   $withRelations          Indicates whether association fields should be returned as well.
  * @param bool   $withVirtualFields      Indicates whether virtual fields should be returned as well.
  * @param bool   $withUnidirectional     Indicates whether Unidirectional association fields should be returned.
  *                                       should be returned.
  * @return array
  */
 protected function getData($entityName, $withRelations, $withVirtualFields, $withUnidirectional)
 {
     $fields = $this->entityFieldProvider->getFields($entityName, $withRelations, $withVirtualFields, true, $withUnidirectional);
     return $this->convertData($fields, $entityName, null);
 }