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
5207e2db
Commit
5207e2db
authored
8 years ago
by
Simon Gadient
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[IMP] Persist the mapping configuration
refs KIME-4583
parent
8185499e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
28 deletions
+29
-28
Classes/WE/SpreadsheetImport/FrontendMappingUtility.php
Classes/WE/SpreadsheetImport/FrontendMappingUtility.php
+2
-2
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
+24
-25
Tests/Functional/SpreadsheetImportServiceTest.php
Tests/Functional/SpreadsheetImportServiceTest.php
+3
-1
No files found.
Classes/WE/SpreadsheetImport/FrontendMappingUtility.php
View file @
5207e2db
...
...
@@ -29,8 +29,8 @@ class FrontendMappingUtility {
$mappings
=
array
();
$domainMappingProperties
=
$spreadsheetImportService
->
getMappingProperties
();
foreach
(
$domainMappingProperties
as
$property
=>
$mapping
)
{
$column
=
$request
->
getArgument
(
$property
);
$mappings
[
$property
]
=
$column
;
$column
Mapping
=
array
(
'column'
=>
$request
->
getArgument
(
$property
),
'mapping'
=>
$mapping
);
$mappings
[
$property
]
=
$column
Mapping
;
}
return
$mappings
;
}
...
...
This diff is collapsed.
Click to expand it.
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
View file @
5207e2db
...
...
@@ -38,7 +38,7 @@ class SpreadsheetImportService {
/**
* @var array
*/
protected
$
columnProperty
Mapping
;
protected
$
inverseSpreadsheetImport
Mapping
;
/**
* @Flow\InjectConfiguration
...
...
@@ -85,7 +85,6 @@ class SpreadsheetImportService {
$this
->
spreadsheetImport
=
$spreadsheetImport
;
$this
->
domain
=
$this
->
settings
[
$spreadsheetImport
->
getContext
()][
'domain'
];
$this
->
initDomainMappingProperties
();
$this
->
initColumnPropertyMapping
();
return
$this
;
}
...
...
@@ -102,25 +101,27 @@ class SpreadsheetImportService {
}
/**
* Flip mapping and return it as a 2-dim array in case the same column is assigned to multiple properties
* Return an inverse SpreadsheetImport mapping array. It flips the property and column attribute and returns it as a
* 3-dim array instead of a 2-dim array. The reason for that is the case when 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
;
private
function
getInverseSpreadsheetImportMapping
()
{
if
(
empty
(
$this
->
inverseSpreadsheetImportMapping
))
{
$this
->
inverseSpreadsheetImportMapping
=
array
();
foreach
(
$this
->
spreadsheetImport
->
getMapping
()
as
$property
=>
$columnMapping
)
{
$column
=
$columnMapping
[
'column'
];
$propertyMapping
=
array
(
'property'
=>
$property
,
'mapping'
=>
$columnMapping
[
'mapping'
]);
$this
->
inverseSpreadsheetImportMapping
[
$column
][]
=
$propertyMapping
;
}
}
return
$this
->
inverseSpreadsheetImportMapping
;
}
/**
* Adds additional mapping properties to the domain mapping properties retrieved by annotations. This increases
* flexibility for dynamic property mapping.
*
* This was implemented for the single use case to support the Flow package Radmiraal.CouchDB
*
* Note: Those additional property configurations are not persisted and need to be added after each initialization
* of the service. The persisted mappings in the SpreadsheetImport object only contain the property without any
* configuration. Therefore, the import works but only for the default setters and without identifiers. To support
* all, the additional mapping properties need to be persisted together with the mappings.
* This is implemented for the single use case to support the Flow package Radmiraal.CouchDB
*
* @param array $additionalMappingProperties
*/
...
...
@@ -274,6 +275,7 @@ class SpreadsheetImportService {
* @return array
*/
private
function
getDomainMappingIdentifierProperties
()
{
// TODO: Don't use the annotation properties but the SpreadsheetImport mapping since we store the Mapping object there as well
$domainMappingProperties
=
array
();
$properties
=
$this
->
reflectionService
->
getPropertyNamesByAnnotation
(
$this
->
domain
,
Mapping
::
class
);
foreach
(
$properties
as
$property
)
{
...
...
@@ -298,7 +300,7 @@ class SpreadsheetImportService {
$spreadsheetImportMapping
=
$this
->
spreadsheetImport
->
getMapping
();
/** @var Mapping $mapping */
foreach
(
$identifierProperties
as
$property
=>
$mapping
)
{
$column
=
$spreadsheetImportMapping
[
$property
];
$column
=
$spreadsheetImportMapping
[
$property
]
[
'column'
]
;
/** @var \PHPExcel_Worksheet_RowCellIterator $cellIterator */
$cellIterator
=
$row
->
getCellIterator
(
$column
,
$column
);
$value
=
$cellIterator
->
current
()
->
getValue
();
...
...
@@ -328,20 +330,17 @@ class SpreadsheetImportService {
* @param \PHPExcel_Worksheet_Row $row
*/
private
function
setObjectPropertiesByRow
(
$object
,
$row
)
{
$
domainMappingProperties
=
$this
->
mappingProperties
;
$
inverseSpreadsheetImportMapping
=
$this
->
getInverseSpreadsheetImportMapping
()
;
/** @var \PHPExcel_Cell $cell */
foreach
(
$row
->
getCellIterator
()
as
$cell
)
{
$column
=
$cell
->
getColumn
();
if
(
array_key_exists
(
$column
,
$this
->
columnPropertyMapping
))
{
$properties
=
$this
->
columnPropertyMapping
[
$column
];
foreach
(
$properties
as
$property
)
{
if
(
array_key_exists
(
$property
,
$domainMappingProperties
))
{
/** @var Mapping $mapping */
$mapping
=
$domainMappingProperties
[
$property
];
$setter
=
empty
(
$mapping
->
setter
)
?
'set'
.
ucfirst
(
$property
)
:
$mapping
->
setter
;
}
else
{
$setter
=
'set'
.
ucfirst
(
$property
);
}
if
(
array_key_exists
(
$column
,
$inverseSpreadsheetImportMapping
))
{
$properties
=
$inverseSpreadsheetImportMapping
[
$column
];
foreach
(
$properties
as
$propertyMapping
)
{
$property
=
$propertyMapping
[
'property'
];
/** @var Mapping $mapping */
$mapping
=
$propertyMapping
[
'mapping'
];
$setter
=
empty
(
$mapping
->
setter
)
?
'set'
.
ucfirst
(
$property
)
:
$mapping
->
setter
;
$object
->
$setter
(
$cell
->
getValue
());
}
}
...
...
This diff is collapsed.
Click to expand it.
Tests/Functional/SpreadsheetImportServiceTest.php
View file @
5207e2db
...
...
@@ -62,7 +62,9 @@ class SpreadsheetImportServiceTest extends FunctionalTestCase {
$spreadsheetImport
->
setContext
(
'testing'
);
$resource
=
$this
->
resourceManager
->
importResource
(
__DIR__
.
'/Fixtures/Resources/sample.xlsx'
);
$spreadsheetImport
->
setFile
(
$resource
);
$spreadsheetImport
->
setMapping
(
array
(
'id'
=>
'C'
,
'name'
=>
'A'
));
$idMapping
=
array
(
'column'
=>
'C'
,
'mapping'
=>
new
Mapping
());
$nameMapping
=
array
(
'column'
=>
'A'
,
'mapping'
=>
new
Mapping
());
$spreadsheetImport
->
setMapping
(
array
(
'id'
=>
$idMapping
,
'name'
=>
$nameMapping
));
$this
->
spreadsheetImportService
->
init
(
$spreadsheetImport
);
}
...
...
This diff is collapsed.
Click to expand it.
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