Loading Classes/WE/SpreadsheetImport/Annotations/Mapping.php +13 −0 Original line number Diff line number Diff line Loading @@ -20,16 +20,29 @@ namespace WE\SpreadsheetImport\Annotations; final class Mapping { /** * Label id for the property mapping * * @var string */ public $labelId = ''; /** * Flag if property is handled as an identifier for updates * * @var boolean */ public $identifier = FALSE; /** * Overwrite the default getter for previews * * @var string */ public $getter; /** * Overwrite the default setter * * @var string */ public $setter; Loading Classes/WE/SpreadsheetImport/SpreadsheetImportService.php +29 −6 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ class SpreadsheetImportService { */ protected $context; /** * @var array */ protected $mappingProperties; /** * @Flow\InjectConfiguration * @var array Loading Loading @@ -68,19 +73,37 @@ class SpreadsheetImportService { public function init(SpreadsheetImport $spreadsheetImport) { $this->spreadsheetImport = $spreadsheetImport; $this->context = $this->settings[$spreadsheetImport->getContext()]; $this->initDomainMappingProperties(); return $this; } /** * @return array * Initializes the properties declared by annotations. */ public function getDomainMappingProperties() { $domainMappingProperties = array(); private function initDomainMappingProperties() { $this->mappingProperties = array(); $properties = $this->reflectionService->getPropertyNamesByAnnotation($this->context['domain'], Mapping::class); foreach ($properties as $property) { $domainMappingProperties[$property] = $this->reflectionService->getPropertyAnnotation($this->context['domain'], $property, Mapping::class); $this->mappingProperties[$property] = $this->reflectionService->getPropertyAnnotation($this->context['domain'], $property, Mapping::class); } return $domainMappingProperties; } /** * Adds additional mapping properties to the domain mapping properties retrieved by annotations. This increases * flexibility for dynamic property mapping. * * @param array $additionalMappingProperties */ public function addAdditionalMappingProperties(array $additionalMappingProperties) { $this->mappingProperties = array_merge($this->mappingProperties, $additionalMappingProperties); } /** * @return array */ public function getMappingProperties() { return $this->mappingProperties; } /** Loading Loading @@ -244,7 +267,7 @@ class SpreadsheetImportService { */ private function setObjectPropertiesByRow($newObject, $row) { // TODO: Cache $domainMappingProperties and $mappings $domainMappingProperties = $this->getDomainMappingProperties(); $domainMappingProperties = $this->getMappingProperties(); $mappings = $this->spreadsheetImport->getMapping(); /** @var \PHPExcel_Cell $cell */ foreach ($row->getCellIterator() as $cell) { Loading Configuration/Testing/Settings.yaml +0 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ WE: SpreadsheetImport: testing: domain: WE\SpreadsheetImport\Tests\Functional\Fixtures\ImportTarget labelPackageKey: 'WE.SpreadsheetImport' Configuration: userProfileType: setter: convertUserProfileTypeBySysValue Loading Tests/Functional/SpreadsheetImportServiceTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class SpreadsheetImportServiceTest extends FunctionalTestCase { * @test */ public function getMappingPropertiesReturnsPropertiesWithMappingAnnotation() { $properties = $this->spreadsheetImportService->getDomainMappingProperties(); $properties = $this->spreadsheetImportService->getMappingProperties(); $this->assertArrayHasKey('id', $properties); $this->assertArrayHasKey('name', $properties); /** @var Mapping $id */ Loading Loading
Classes/WE/SpreadsheetImport/Annotations/Mapping.php +13 −0 Original line number Diff line number Diff line Loading @@ -20,16 +20,29 @@ namespace WE\SpreadsheetImport\Annotations; final class Mapping { /** * Label id for the property mapping * * @var string */ public $labelId = ''; /** * Flag if property is handled as an identifier for updates * * @var boolean */ public $identifier = FALSE; /** * Overwrite the default getter for previews * * @var string */ public $getter; /** * Overwrite the default setter * * @var string */ public $setter; Loading
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php +29 −6 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ class SpreadsheetImportService { */ protected $context; /** * @var array */ protected $mappingProperties; /** * @Flow\InjectConfiguration * @var array Loading Loading @@ -68,19 +73,37 @@ class SpreadsheetImportService { public function init(SpreadsheetImport $spreadsheetImport) { $this->spreadsheetImport = $spreadsheetImport; $this->context = $this->settings[$spreadsheetImport->getContext()]; $this->initDomainMappingProperties(); return $this; } /** * @return array * Initializes the properties declared by annotations. */ public function getDomainMappingProperties() { $domainMappingProperties = array(); private function initDomainMappingProperties() { $this->mappingProperties = array(); $properties = $this->reflectionService->getPropertyNamesByAnnotation($this->context['domain'], Mapping::class); foreach ($properties as $property) { $domainMappingProperties[$property] = $this->reflectionService->getPropertyAnnotation($this->context['domain'], $property, Mapping::class); $this->mappingProperties[$property] = $this->reflectionService->getPropertyAnnotation($this->context['domain'], $property, Mapping::class); } return $domainMappingProperties; } /** * Adds additional mapping properties to the domain mapping properties retrieved by annotations. This increases * flexibility for dynamic property mapping. * * @param array $additionalMappingProperties */ public function addAdditionalMappingProperties(array $additionalMappingProperties) { $this->mappingProperties = array_merge($this->mappingProperties, $additionalMappingProperties); } /** * @return array */ public function getMappingProperties() { return $this->mappingProperties; } /** Loading Loading @@ -244,7 +267,7 @@ class SpreadsheetImportService { */ private function setObjectPropertiesByRow($newObject, $row) { // TODO: Cache $domainMappingProperties and $mappings $domainMappingProperties = $this->getDomainMappingProperties(); $domainMappingProperties = $this->getMappingProperties(); $mappings = $this->spreadsheetImport->getMapping(); /** @var \PHPExcel_Cell $cell */ foreach ($row->getCellIterator() as $cell) { Loading
Configuration/Testing/Settings.yaml +0 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ WE: SpreadsheetImport: testing: domain: WE\SpreadsheetImport\Tests\Functional\Fixtures\ImportTarget labelPackageKey: 'WE.SpreadsheetImport' Configuration: userProfileType: setter: convertUserProfileTypeBySysValue Loading
Tests/Functional/SpreadsheetImportServiceTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class SpreadsheetImportServiceTest extends FunctionalTestCase { * @test */ public function getMappingPropertiesReturnsPropertiesWithMappingAnnotation() { $properties = $this->spreadsheetImportService->getDomainMappingProperties(); $properties = $this->spreadsheetImportService->getMappingProperties(); $this->assertArrayHasKey('id', $properties); $this->assertArrayHasKey('name', $properties); /** @var Mapping $id */ Loading