Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
WE.SpreadsheetImport
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Labels
Merge Requests
0
Merge Requests
0
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
packages
WE.SpreadsheetImport
Commits
4dab0562
Commit
4dab0562
authored
Oct 26, 2016
by
Simon Gadient
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BUGFIX] Property mapping with same column
refs KIME-4583
parent
bfb16fff
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
15 deletions
+29
-15
Classes/WE/SpreadsheetImport/FrontendMappingUtility.php
Classes/WE/SpreadsheetImport/FrontendMappingUtility.php
+1
-1
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
+27
-12
Tests/Functional/SpreadsheetImportServiceTest.php
Tests/Functional/SpreadsheetImportServiceTest.php
+1
-2
No files found.
Classes/WE/SpreadsheetImport/FrontendMappingUtility.php
View file @
4dab0562
...
...
@@ -30,7 +30,7 @@ class FrontendMappingUtility {
$domainMappingProperties
=
$spreadsheetImportService
->
getMappingProperties
();
foreach
(
$domainMappingProperties
as
$property
=>
$mapping
)
{
$column
=
$request
->
getArgument
(
$property
);
$mappings
[
$
column
]
=
$property
;
$mappings
[
$
property
]
=
$column
;
}
return
$mappings
;
}
...
...
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
View file @
4dab0562
...
...
@@ -35,6 +35,11 @@ class SpreadsheetImportService {
*/
protected
$mappingProperties
;
/**
* @var array
*/
protected
$columnPropertyMapping
;
/**
* @Flow\InjectConfiguration
* @var array
...
...
@@ -74,6 +79,7 @@ class SpreadsheetImportService {
$this
->
spreadsheetImport
=
$spreadsheetImport
;
$this
->
context
=
$this
->
settings
[
$spreadsheetImport
->
getContext
()];
$this
->
initDomainMappingProperties
();
$this
->
initColumnPropertyMapping
();
return
$this
;
}
...
...
@@ -89,6 +95,16 @@ class SpreadsheetImportService {
}
}
/**
* Flip mapping and return it as a 2-dim array in case the same column is assigned to multiple properties
*/
private
function
initColumnPropertyMapping
()
{
$this
->
columnPropertyMapping
=
array
();
foreach
(
$this
->
spreadsheetImport
->
getMapping
()
as
$property
=>
$column
)
{
$this
->
columnPropertyMapping
[
$column
][]
=
$property
;
}
}
/**
* Adds additional mapping properties to the domain mapping properties retrieved by annotations. This increases
* flexibility for dynamic property mapping.
...
...
@@ -109,7 +125,7 @@ class SpreadsheetImportService {
/**
* @return array
*/
p
ublic
function
getDomainMappingIdentifierProperties
()
{
p
rivate
function
getDomainMappingIdentifierProperties
()
{
$domainMappingProperties
=
array
();
$properties
=
$this
->
reflectionService
->
getPropertyNamesByAnnotation
(
$this
->
context
[
'domain'
],
Mapping
::
class
);
foreach
(
$properties
as
$property
)
{
...
...
@@ -164,7 +180,6 @@ class SpreadsheetImportService {
* @return void
*/
public
function
import
()
{
// TODO: This simply creates the objects for now without update or delete
$totalInserted
=
0
;
$totalUpdated
=
0
;
$totalDeleted
=
0
;
...
...
@@ -233,7 +248,7 @@ class SpreadsheetImportService {
private
function
findObjectByIdentifierPropertiesPerRow
(
array
$identifierProperties
,
\PHPExcel_Worksheet_Row
$row
)
{
$query
=
$this
->
getDomainRepository
()
->
createQuery
();
$constraints
=
array
();
$spreadsheetImportMapping
=
array_flip
(
$this
->
spreadsheetImport
->
getMapping
()
);
$spreadsheetImportMapping
=
$this
->
spreadsheetImport
->
getMapping
(
);
/** @var Mapping $mapping */
foreach
(
$identifierProperties
as
$property
=>
$mapping
)
{
$column
=
$spreadsheetImportMapping
[
$property
];
...
...
@@ -266,14 +281,13 @@ class SpreadsheetImportService {
* @param \PHPExcel_Worksheet_Row $row
*/
private
function
setObjectPropertiesByRow
(
$newObject
,
$row
)
{
// TODO: Cache $domainMappingProperties and $mappings
$domainMappingProperties
=
$this
->
getMappingProperties
();
$mappings
=
$this
->
spreadsheetImport
->
getMapping
();
$domainMappingProperties
=
$this
->
mappingProperties
;
/** @var \PHPExcel_Cell $cell */
foreach
(
$row
->
getCellIterator
()
as
$cell
)
{
$column
=
$cell
->
getColumn
();
if
(
array_key_exists
(
$column
,
$mappings
))
{
$property
=
$mappings
[
$column
];
if
(
array_key_exists
(
$column
,
$this
->
columnPropertyMapping
))
{
$properties
=
$this
->
columnPropertyMapping
[
$column
];
foreach
(
$properties
as
$property
)
{
/** @var Mapping $mapping */
$mapping
=
$domainMappingProperties
[
$property
];
$setter
=
empty
(
$mapping
->
setter
)
?
'set'
.
ucfirst
(
$property
)
:
$mapping
->
setter
;
...
...
@@ -281,4 +295,5 @@ class SpreadsheetImportService {
}
}
}
}
}
Tests/Functional/SpreadsheetImportServiceTest.php
View file @
4dab0562
...
...
@@ -12,7 +12,6 @@ namespace WE\SpreadsheetImport\Tests\Functional;
* */
use
TYPO3\Flow\Reflection\ReflectionService
;
use
TYPO3\Flow\Resource\Resource
;
use
TYPO3\Flow\Resource\ResourceManager
;
use
TYPO3\Flow\Tests\FunctionalTestCase
;
use
WE\SpreadsheetImport\Annotations\Mapping
;
...
...
@@ -63,7 +62,7 @@ class SpreadsheetImportServiceTest extends FunctionalTestCase {
$spreadsheetImport
->
setContext
(
'testing'
);
$resource
=
$this
->
resourceManager
->
importResource
(
__DIR__
.
'/Fixtures/Resources/sample.xlsx'
);
$spreadsheetImport
->
setFile
(
$resource
);
$spreadsheetImport
->
setMapping
(
array
(
'
C'
=>
'id'
,
'A'
=>
'name
'
));
$spreadsheetImport
->
setMapping
(
array
(
'
id'
=>
'C'
,
'name'
=>
'A
'
));
$this
->
spreadsheetImportService
->
init
(
$spreadsheetImport
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment