Task #90847
closedDataMapper for array type
0%
Description
Sorry, I don't know how to choose the tracker, actually it's not a bug, but should be a suggestion.
I was working on an FE ext, and it involves in displaying the banners on the page with some access controls, like Anonymous, User Group 1, User Group 2, and etc. So, I was using array
to store the group IDs, 0 for Anonymous. I can save the access array to the DB like 0,1,2, but can not get it from the DB.
After digging the core files, I found the array
is mapped to string
with implode()
in the DataMapper::getPlainValue()
...
if (TypeHandlingUtility::isValidTypeForMultiValueComparison($input)) {
$plainValueArray = [];
foreach ($input as $inputElement) {
$plainValueArray[] = $this->getPlainValue($inputElement, $columnMap);
}
$parameter = implode(',', $plainValueArray);
}
...
while in DataMapper::thawProperties(), it is
...
case 'array':
// $propertyValue = $this->mapArray($row[$columnName]); // Not supported, yet!
break;
...
and it's not supported since v7, maybe even earlier.
So, my suggestion is, adding more detailed if conditions in getPlainValue()
, so the real array could be mapped correctly, you known like the index, the two dimensional arrays, and more.
...
if ($input instanceof \SplObjectStorage || $input instanceof Persistence\ObjectStorage) {
$plainValueArray = [];
foreach ($input as $inputElement) {
$plainValueArray[] = $this->getPlainValue($inputElement, $columnMap);
}
$parameter = implode(',', $plainValueArray);
} elseif (TypeHandlingUtility::isValidTypeForMultiValueComparison($input)) {
$parameter = serialize($input);
}
...
Thus, the array could be retrieved with unserialize()
in thawProperties()
.
Maybe the suggestion is not as good, but I think it worthes a try.
Thank you!