Commit e0b6541b authored by Simon Gadient's avatar Simon Gadient

[IMP] Preview error handling

refs KIME-4583
parent 79dc5c5a
......@@ -14,6 +14,7 @@ namespace WE\SpreadsheetImport;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Mvc\ActionRequest;
use WE\SpreadsheetImport\Annotations\Mapping;
use WE\SpreadsheetImport\Domain\Model\SpreadsheetImport;
/**
* Service class of basic FE mapping functionality for simple usage on separate implementations.
......@@ -46,6 +47,12 @@ class FrontendMappingService {
*/
protected $propertyMapper;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Validation\ValidatorResolver
*/
protected $validatorResolver;
/**
* @param string $context
* @param \TYPO3\Flow\Mvc\ActionRequest $request
......@@ -93,21 +100,30 @@ class FrontendMappingService {
}
/**
* @param array $mapping
* @param int $record
* @param \WE\SpreadsheetImport\Domain\Model\SpreadsheetImport $spreadsheetImport
* @param $record
*
* @return array
*/
public function getMappingPreview($mapping, $record) {
public function getMappingPreview(SpreadsheetImport $spreadsheetImport, $record) {
$mapping = $spreadsheetImport->getMapping();
$domain = $this->settings[$spreadsheetImport->getContext()]['domain'];
$record = max($record, 1);
$previewObject = $this->spreadsheetImportService->getObjectByRow($record);
$preview = array();
$hasErrors = FALSE;
$objectValidator = $this->validatorResolver->getBaseValidatorConjunction($domain);
$errors = $objectValidator->validate($previewObject)->getFlattenedErrors();
foreach ($mapping as $property => $columnMapping) {
/** @var Mapping $mapping */
$mapping = $columnMapping['mapping'];
$getter = empty($mapping->getter) ? 'get' . ucfirst($property) : $mapping->getter;
$preview[$property] = array('value' => $previewObject->$getter(), 'mapping' => $mapping);
if (isset($errors[$property])) {
$preview[$property]['error'] = $errors[$property];
$hasErrors = TRUE;
}
}
return $preview;
return array('preview' => $preview, 'hasErrors' => $hasErrors);
}
}
......@@ -340,6 +340,8 @@ class SpreadsheetImportService {
* @param \PHPExcel_Worksheet_Row $row
*/
private function setObjectPropertiesByRow($object, $row) {
// Set the arguments first as mapping property setters might be dependent on argument properties
$this->setObjectArgumentProperties($object);
$inverseSpreadsheetImportMapping = $this->getInverseSpreadsheetImportMapping();
/** @var \PHPExcel_Cell $cell */
foreach ($row->getCellIterator() as $cell) {
......@@ -355,7 +357,6 @@ class SpreadsheetImportService {
}
}
}
$this->setObjectArgumentProperties($object);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment