diff --git a/lib/Db/Row2Mapper.php b/lib/Db/Row2Mapper.php index 931098a2c..67a84740d 100644 --- a/lib/Db/Row2Mapper.php +++ b/lib/Db/Row2Mapper.php @@ -649,12 +649,10 @@ private function parseEntities(IResult $result, array $sleeves): array { $column = $this->columnMapper->find($rowData['column_id']); $columnType = $column->getType(); - $cellClassName = 'OCA\Tables\Db\RowCell' . ucfirst($columnType); - $entity = call_user_func($cellClassName . '::fromRowData', $rowData); // >5.2.3 if (!isset($cellMapperCache[$columnType])) { $cellMapperCache[$columnType] = $this->getCellMapperFromType($columnType); } - $value = $cellMapperCache[$columnType]->formatEntity($column, $entity); + $value = $cellMapperCache[$columnType]->formatRowData($column, $rowData); $compositeKey = (string)$rowData['row_id'] . ',' . (string)$rowData['column_id']; if ($cellMapperCache[$columnType]->hasMultipleValues()) { if (array_key_exists($compositeKey, $rowValues)) { diff --git a/lib/Db/RowCellMapperSuper.php b/lib/Db/RowCellMapperSuper.php index 28c75945f..a3389b310 100644 --- a/lib/Db/RowCellMapperSuper.php +++ b/lib/Db/RowCellMapperSuper.php @@ -27,14 +27,14 @@ public function __construct(IDBConnection $db, string $table, string $class) { } /** - * Format a row cell entity to API response array + * Format a row cell raw value from DB to API response array * - * @param T $cell + * @param array $row * @return TOutgoing */ - public function formatEntity(Column $column, RowCellSuper $cell) { + public function formatRowData(Column $column, array $row) { /** @var TOutgoing $value */ - $value = $cell->getValue(); + $value = $row['value']; return $value; } /* diff --git a/lib/Db/RowCellNumberMapper.php b/lib/Db/RowCellNumberMapper.php index 45a02531f..dd6a18163 100644 --- a/lib/Db/RowCellNumberMapper.php +++ b/lib/Db/RowCellNumberMapper.php @@ -18,17 +18,17 @@ public function __construct(IDBConnection $db) { parent::__construct($db, $this->table, RowCellNumber::class); } - public function formatEntity(Column $column, RowCellSuper $cell) { - $value = $cell->getValue(); + public function formatRowData(Column $column, array $row) { + $value = $row['value']; if ($value === '') { return null; } $decimals = $column->getNumberDecimals() ?? 0; if ($decimals === 0) { return (int)$value; - } else { - return round(floatval($value), $decimals); } + + return round(floatval($value), $decimals); } public function applyDataToEntity(Column $column, RowCellSuper $cell, $data): void { diff --git a/lib/Db/RowCellSelectionMapper.php b/lib/Db/RowCellSelectionMapper.php index 53021e876..be0be124a 100644 --- a/lib/Db/RowCellSelectionMapper.php +++ b/lib/Db/RowCellSelectionMapper.php @@ -27,8 +27,8 @@ public function applyDataToEntity(Column $column, RowCellSuper $cell, $data): vo $cell->setValue($this->valueToJsonDbValue($column, $data)); } - public function formatEntity(Column $column, RowCellSuper $cell) { - return json_decode($cell->getValue()); + public function formatRowData(Column $column, array $row) { + return json_decode($row['value']); } private function valueToJsonDbValue(Column $column, $value): string { diff --git a/lib/Db/RowCellSuper.php b/lib/Db/RowCellSuper.php index 89dc37980..db0f7f4d0 100644 --- a/lib/Db/RowCellSuper.php +++ b/lib/Db/RowCellSuper.php @@ -37,29 +37,9 @@ public function __construct() { $this->addType('rowId', 'integer'); } - /** - * Same as Entity::fromRow but ignoring unknown properties - */ - public static function fromRowData(array $row): RowCellSuper { - $instance = new static(); - - foreach ($row as $key => $value) { - $property = $instance->columnToProperty($key); - $setter = 'set' . ucfirst($property); - ; - if (property_exists($instance, $property)) { - $instance->$setter($value); - } - } - - $instance->resetUpdatedFields(); - - return $instance; - } - /** * @param float|null|string $value - * @param int $value_type + * @param int $valueType */ public function jsonSerializePreparation(string|float|null $value, int $valueType = 0): array { return [ diff --git a/lib/Db/RowCellUsergroupMapper.php b/lib/Db/RowCellUsergroupMapper.php index 5fcbdd4ea..41ed770c8 100644 --- a/lib/Db/RowCellUsergroupMapper.php +++ b/lib/Db/RowCellUsergroupMapper.php @@ -40,18 +40,20 @@ public function applyDataToEntity(Column $column, RowCellSuper $cell, $data): vo $cell->setValueWrapper($data); } - public function formatEntity(Column $column, RowCellSuper $cell) { - $displayName = $cell->getValue(); - if ($cell->getValueType() === UsergroupType::USER) { - $displayName = $this->userManager->getDisplayName($cell->getValue()) ?? $cell->getValue(); - } elseif ($cell->getValueType() === UsergroupType::CIRCLE) { - $displayName = $this->circleHelper->getCircleDisplayName($cell->getValue(), ($this->userSession->getUser()?->getUID() ?: '')) ?: $cell->getValue(); - } elseif ($cell->getValueType() === UsergroupType::GROUP) { - $displayName = $this->groupHelper->getGroupDisplayName($cell->getValue()) ?: $cell->getValue(); + public function formatRowData(Column $column, array $row) { + $value = $row['value']; + $valueType = (int)$row['value_type']; + $displayName = $value; + if ($valueType === UsergroupType::USER) { + $displayName = $this->userManager->getDisplayName($value) ?? $value; + } elseif ($valueType === UsergroupType::CIRCLE) { + $displayName = $this->circleHelper->getCircleDisplayName($value, ($this->userSession->getUser()?->getUID() ?: '')) ?: $value; + } elseif ($valueType === UsergroupType::GROUP) { + $displayName = $this->groupHelper->getGroupDisplayName($value) ?: $value; } return [ - 'id' => $cell->getValue(), - 'type' => $cell->getValueType(), + 'id' => $value, + 'type' => $valueType, 'displayName' => $displayName, ]; }