Пример #1
0
 /**
  * @param mixed $expected
  * @param string $entityName
  * @param string $fieldName
  * @param string $parameter
  * @param mixed|null $default
  * @dataProvider getConfigValueDataProvider
  */
 public function testGetConfigValue($expected, $entityName, $fieldName, $parameter, $default = null)
 {
     if (!is_null($expected)) {
         $this->assertTrue($this->helper->hasConfig($entityName, $fieldName));
     }
     $this->assertSame($expected, $this->helper->getConfigValue($entityName, $fieldName, $parameter, $default));
 }
Пример #2
0
 /**
  * @param mixed $expected
  * @param string $entityName
  * @param string $fieldName
  * @param string $parameter
  * @param mixed|null $default
  * @param bool $hasConfig
  * @dataProvider getConfigValueDataProvider
  */
 public function testGetConfigValue($expected, $entityName, $fieldName, $parameter, $default, $hasConfig = true)
 {
     if (!is_null($expected)) {
         $this->assertTrue($this->helper->hasConfig($entityName, $fieldName));
     }
     $value = $this->helper->getConfigValue($entityName, $fieldName, $parameter, $default);
     $this->assertSame($expected, $value);
     $this->assertSame($value, $this->helper->getConfigValue($entityName, $fieldName, $parameter, $default));
     // has config from caches
     $this->assertEquals($hasConfig, $this->helper->hasConfig($entityName, $fieldName));
 }
 /**
  * @param string $entityName
  * @return bool
  */
 protected function hasIdentityFields($entityName)
 {
     $fields = $this->fieldHelper->getFields($entityName, true);
     foreach ($fields as $field) {
         $fieldName = $field['name'];
         if ($this->fieldHelper->getConfigValue($entityName, $fieldName, 'identity')) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param string $entityName
  * @param bool $fullData
  * @param int $singleRelationDeepLevel
  * @param int $multipleRelationDeepLevel
  * @return array
  */
 protected function getEntityRulesAndBackendHeaders($entityName, $fullData = false, $singleRelationDeepLevel = 0, $multipleRelationDeepLevel = 0)
 {
     // get fields data
     $fields = $this->fieldHelper->getFields($entityName, true);
     $rules = array();
     $backendHeaders = array();
     $defaultOrder = 10000;
     // generate conversion rules and backend header
     foreach ($fields as $field) {
         $fieldName = $field['name'];
         if ($this->fieldHelper->getConfigValue($entityName, $fieldName, 'excluded')) {
             continue;
         }
         // get import/export config parameters
         $fieldHeader = $this->fieldHelper->getConfigValue($entityName, $fieldName, 'header', $field['label']);
         $fieldOrder = $this->fieldHelper->getConfigValue($entityName, $fieldName, 'order');
         if ($fieldOrder === null || $fieldOrder === '') {
             $fieldOrder = $defaultOrder;
             $defaultOrder++;
         }
         $fieldOrder = (int) $fieldOrder;
         // process relations
         if ($this->fieldHelper->isRelation($field) && !$this->fieldHelper->processRelationAsScalar($entityName, $fieldName)) {
             $isSingleRelation = $this->fieldHelper->isSingleRelation($field) && $singleRelationDeepLevel > 0;
             $isMultipleRelation = $this->fieldHelper->isMultipleRelation($field) && $multipleRelationDeepLevel > 0;
             // if relation must be included
             if ($fullData && ($isSingleRelation || $isMultipleRelation)) {
                 $relatedEntityName = $field['related_entity_name'];
                 $fieldFullData = $this->fieldHelper->getConfigValue($entityName, $fieldName, 'full', false);
                 // process and merge relation rules and backend header for relation
                 list($relationRules, $relationBackendHeaders) = $this->getEntityRulesAndBackendHeaders($relatedEntityName, $fieldFullData, $singleRelationDeepLevel - 1, $multipleRelationDeepLevel - 1);
                 $relationRules = $this->buildRelationRules($relationRules, $isSingleRelation, $isMultipleRelation, $fieldName, $fieldHeader, $fieldOrder);
                 $rules = array_merge($rules, $relationRules);
                 $relationBackendHeaders = $this->buildBackendHeaders($relationBackendHeaders, $isSingleRelation, $isMultipleRelation, $entityName, $fieldName, $fieldOrder);
                 $backendHeaders = array_merge($backendHeaders, $relationBackendHeaders);
             }
         } else {
             // process scalars
             if ($fullData || $this->fieldHelper->getConfigValue($entityName, $fieldName, 'identity')) {
                 $rules[$fieldHeader] = array('value' => $fieldName, 'order' => $fieldOrder);
                 $backendHeaders[] = $rules[$fieldHeader];
             }
         }
     }
     return array($this->sortData($rules), $this->sortData($backendHeaders));
 }
 /**
  * @param string $entityName
  * @param bool $fullData
  * @param int $singleRelationDeepLevel
  * @param int $multipleRelationDeepLevel
  * @param array $field
  * @param string $fieldHeader
  * @param int $fieldOrder
  *
  * @return array
  */
 protected function getRelatedEntityRulesAndBackendHeaders($entityName, $fullData, $singleRelationDeepLevel, $multipleRelationDeepLevel, $field, $fieldHeader, $fieldOrder, $isIdentifier = false)
 {
     $fieldName = $field['name'];
     $relationRules = [];
     $relationBackendHeaders = [];
     $isSingleRelation = $this->fieldHelper->isSingleRelation($field) && $singleRelationDeepLevel > 0;
     $isMultipleRelation = $this->fieldHelper->isMultipleRelation($field) && $multipleRelationDeepLevel > 0;
     // if relation must be included
     if ($fullData && ($isSingleRelation || $isMultipleRelation)) {
         $relatedEntityName = $field['related_entity_name'];
         $fieldFullData = $this->fieldHelper->getConfigValue($entityName, $fieldName, 'full', false);
         // process and merge relation rules and backend header for relation
         list($relationRules, $relationBackendHeaders) = $this->getEntityRulesAndBackendHeaders($relatedEntityName, $fieldFullData, $singleRelationDeepLevel - 1, $multipleRelationDeepLevel - 1);
         $relationRules = $this->buildRelationRules($relationRules, $isSingleRelation, $isMultipleRelation, $fieldName, $fieldHeader, $fieldOrder);
         $relationBackendHeaders = $this->buildBackendHeaders($relationBackendHeaders, $isSingleRelation, $isMultipleRelation, $entityName, $fieldName, $fieldOrder);
     }
     return [$relationRules, $relationBackendHeaders];
 }