diff --git a/lib/Controller/Api1Controller.php b/lib/Controller/Api1Controller.php index 92f3fdc8a..4f630d806 100644 --- a/lib/Controller/Api1Controller.php +++ b/lib/Controller/Api1Controller.php @@ -13,6 +13,7 @@ use OCA\Tables\Api\V1Api; use OCA\Tables\AppInfo\Application; use OCA\Tables\Db\ViewMapper; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -816,34 +817,30 @@ public function createColumn( $this->userId, $tableId, $viewId, - $type, - $subtype, - $title, - $mandatory, - $description, - - $textDefault, - $textAllowedPattern, - $textMaxLength, - - $numberPrefix, - $numberSuffix, - $numberDefault, - $numberMin, - $numberMax, - $numberDecimals, - - $selectionOptions, - $selectionDefault, - - $datetimeDefault, - - $usergroupDefault, - $usergroupMultipleItems, - $usergroupSelectUsers, - $usergroupSelectGroups, - $usergroupShowUserStatus, - + new ColumnDto( + title: $title, + type: $type, + subtype: $subtype, + mandatory: $mandatory, + description: $description, + textDefault: $textDefault, + textAllowedPattern: $textAllowedPattern, + textMaxLength: $textMaxLength, + numberDefault: $numberDefault, + numberMin: $numberMin, + numberMax: $numberMax, + numberDecimals: $numberDecimals, + numberPrefix: $numberPrefix, + numberSuffix: $numberSuffix, + selectionOptions: $selectionOptions, + selectionDefault: $selectionDefault, + datetimeDefault: $datetimeDefault, + usergroupDefault: $usergroupDefault, + usergroupMultipleItems: $usergroupMultipleItems, + usergroupSelectUsers: $usergroupSelectUsers, + usergroupSelectGroups: $usergroupSelectGroups, + showUserStatus: $usergroupShowUserStatus + ), $selectedViewIds )->jsonSerialize()); } catch (PermissionError $e) { @@ -930,32 +927,29 @@ public function updateColumn( $columnId, null, $this->userId, - null, - $subtype, - $title, - $mandatory, - $description, - - $textDefault, - $textAllowedPattern, - $textMaxLength, - - $numberPrefix, - $numberSuffix, - $numberDefault, - $numberMin, - $numberMax, - $numberDecimals, - - $selectionOptions, - $selectionDefault, - $datetimeDefault, - - $usergroupDefault, - $usergroupMultipleItems, - $usergroupSelectUsers, - $usergroupSelectGroups, - $usergroupShowUserStatus, + new ColumnDto( + title: $title, + subtype: $subtype, + mandatory: $mandatory, + description: $description, + textDefault: $textDefault, + textAllowedPattern: $textAllowedPattern, + textMaxLength: $textMaxLength, + numberDefault: $numberDefault, + numberMin: $numberMin, + numberMax: $numberMax, + numberDecimals: $numberDecimals, + numberPrefix: $numberPrefix, + numberSuffix: $numberSuffix, + selectionOptions: $selectionOptions, + selectionDefault: $selectionDefault, + datetimeDefault: $datetimeDefault, + usergroupDefault: $usergroupDefault, + usergroupMultipleItems: $usergroupMultipleItems, + usergroupSelectUsers: $usergroupSelectUsers, + usergroupSelectGroups: $usergroupSelectGroups, + showUserStatus: $usergroupShowUserStatus + ) ); return new DataResponse($item->jsonSerialize()); } catch (InternalError $e) { @@ -1533,34 +1527,30 @@ public function createTableColumn( $this->userId, $tableId, null, - $type, - $subtype, - $title, - $mandatory, - $description, - - $textDefault, - $textAllowedPattern, - $textMaxLength, - - $numberPrefix, - $numberSuffix, - $numberDefault, - $numberMin, - $numberMax, - $numberDecimals, - - $selectionOptions, - $selectionDefault, - - $datetimeDefault, - - $usergroupDefault, - $usergroupMultipleItems, - $usergroupSelectUsers, - $usergroupSelectGroups, - $usergroupShowUserStatus, - + new ColumnDto( + title: $title, + type: $type, + subtype: $subtype, + mandatory: $mandatory, + description: $description, + textDefault: $textDefault, + textAllowedPattern: $textAllowedPattern, + textMaxLength: $textMaxLength, + numberDefault: $numberDefault, + numberMin: $numberMin, + numberMax: $numberMax, + numberDecimals: $numberDecimals, + numberPrefix: $numberPrefix, + numberSuffix: $numberSuffix, + selectionOptions: $selectionOptions, + selectionDefault: $selectionDefault, + datetimeDefault: $datetimeDefault, + usergroupDefault: $usergroupDefault, + usergroupMultipleItems: $usergroupMultipleItems, + usergroupSelectUsers: $usergroupSelectUsers, + usergroupSelectGroups: $usergroupSelectGroups, + showUserStatus: $usergroupShowUserStatus + ), $selectedViewIds ); return new DataResponse($item->jsonSerialize()); diff --git a/lib/Controller/ApiColumnsController.php b/lib/Controller/ApiColumnsController.php index 85fda2615..d126b833a 100644 --- a/lib/Controller/ApiColumnsController.php +++ b/lib/Controller/ApiColumnsController.php @@ -6,6 +6,7 @@ */ namespace OCA\Tables\Controller; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -127,28 +128,19 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe $this->userId, $tableId, $viewId, - 'number', - $subtype, - $title, - $mandatory, - $description, - null, - null, - null, - $numberPrefix, - $numberSuffix, - $numberDefault, - $numberMin, - $numberMax, - $numberDecimals, - null, - null, - null, - null, - null, - null, - null, - null, + new ColumnDto( + title: $title, + type: 'number', + subtype: $subtype, + mandatory: $mandatory, + description: $description, + numberDefault: $numberDefault, + numberMin: $numberMin, + numberMax: $numberMax, + numberDecimals: $numberDecimals, + numberPrefix: $numberPrefix, + numberSuffix: $numberSuffix + ), $selectedViewIds ); return new DataResponse($column->jsonSerialize()); @@ -187,28 +179,16 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe $this->userId, $tableId, $viewId, - 'text', - $subtype, - $title, - $mandatory, - $description, - $textDefault, - $textAllowedPattern, - $textMaxLength, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, + new ColumnDto( + title: $title, + type: 'text', + subtype: $subtype, + mandatory: $mandatory, + description: $description, + textDefault: $textDefault, + textAllowedPattern: $textAllowedPattern, + textMaxLength: $textMaxLength + ), $selectedViewIds ); return new DataResponse($column->jsonSerialize()); @@ -246,28 +226,15 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se $this->userId, $tableId, $viewId, - 'selection', - $subtype, - $title, - $mandatory, - $description, - null, - null, - null, - null, - null, - null, - null, - null, - null, - $selectionOptions, - $selectionDefault, - null, - null, - null, - null, - null, - null, + new ColumnDto( + title: $title, + type: 'selection', + subtype: $subtype, + mandatory: $mandatory, + description: $description, + selectionOptions: $selectionOptions, + selectionDefault: $selectionDefault + ), $selectedViewIds ); return new DataResponse($column->jsonSerialize()); @@ -304,28 +271,14 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da $this->userId, $tableId, $viewId, - 'text', - $subtype, - $title, - $mandatory, - $description, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - $datetimeDefault, - null, - null, - null, - null, - null, + new ColumnDto( + title: $title, + type: 'datetime', + subtype: $subtype, + mandatory: $mandatory, + description: $description, + datetimeDefault: $datetimeDefault + ), $selectedViewIds ); return new DataResponse($column->jsonSerialize()); @@ -363,28 +316,17 @@ public function createUsergroupColumn(int $baseNodeId, string $title, ?string $u $this->userId, $tableId, $viewId, - 'usergroup', - null, - $title, - $mandatory, - $description, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - $usergroupDefault, - $usergroupMultipleItems, - $usergroupSelectUsers, - $usergroupSelectGroups, - $showUserStatus, + new ColumnDto( + title: $title, + type: 'usergroup', + mandatory: $mandatory, + description: $description, + usergroupDefault: $usergroupDefault, + usergroupMultipleItems: $usergroupMultipleItems, + usergroupSelectUsers: $usergroupSelectUsers, + usergroupSelectGroups: $usergroupSelectGroups, + showUserStatus: $showUserStatus + ), $selectedViewIds ); return new DataResponse($column->jsonSerialize()); diff --git a/lib/Controller/ApiTablesController.php b/lib/Controller/ApiTablesController.php index 2dccd742a..8c4b2aed1 100644 --- a/lib/Controller/ApiTablesController.php +++ b/lib/Controller/ApiTablesController.php @@ -8,6 +8,7 @@ namespace OCA\Tables\Controller; use Exception; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -141,35 +142,30 @@ public function createFromScheme(string $title, string $emoji, string $descripti $this->userId, $table->getId(), null, - $column['type'], - $column['subtype'], - $column['title'], - $column['mandatory'], - $column['description'], - - $column['textDefault'], - $column['textAllowedPattern'], - $column['textMaxLength'], - - $column['numberPrefix'], - $column['numberSuffix'], - $column['numberDefault'], - $column['numberMin'], - $column['numberMax'], - $column['numberDecimals'], - - $column['selectionOptions'] == [] ? '' : $column['selectionOptions'], - $column['selectionDefault'], - - $column['datetimeDefault'], - - $column['usergroupDefault'], - $column['usergroupMultipleItems'], - $column['usergroupSelectUsers'], - $column['usergroupSelectGroups'], - $column['showUserStatus'], - - [], + new ColumnDto( + title: $column['title'], + type: $column['type'], + subtype: $column['subtype'], + mandatory: $column['mandatory'], + description: $column['description'], + textDefault: $column['textDefault'], + textAllowedPattern: $column['textAllowedPattern'], + textMaxLength: $column['textMaxLength'], + numberDefault: $column['numberDefault'], + numberMin: $column['numberMin'], + numberMax: $column['numberMax'], + numberDecimals: $column['numberDecimals'], + numberPrefix: $column['numberPrefix'], + numberSuffix: $column['numberSuffix'], + selectionOptions: $column['selectionOptions'], + selectionDefault: $column['selectionDefault'], + datetimeDefault: $column['datetimeDefault'], + usergroupDefault: $column['usergroupDefault'], + usergroupMultipleItems: $column['usergroupMultipleItems'], + usergroupSelectUsers: $column['usergroupSelectUsers'], + usergroupSelectGroups: $column['usergroupSelectGroups'], + showUserStatus: $column['showUserStatus'], + ) ); }; foreach ($views as $view) { diff --git a/lib/Controller/ColumnController.php b/lib/Controller/ColumnController.php index d533f9c88..42f760cad 100644 --- a/lib/Controller/ColumnController.php +++ b/lib/Controller/ColumnController.php @@ -8,6 +8,7 @@ namespace OCA\Tables\Controller; use OCA\Tables\AppInfo\Application; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\Service\ColumnService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; @@ -142,35 +143,32 @@ public function create( $this->userId, $tableId, $viewId, - $type, - $subtype, - $title, - $mandatory, - $description, - - $textDefault, - $textAllowedPattern, - $textMaxLength, - - $numberPrefix, - $numberSuffix, - $numberDefault, - $numberMin, - $numberMax, - $numberDecimals, - - $selectionOptions, - $selectionDefault, - - $datetimeDefault, - - $usergroupDefault, - $usergroupMultipleItems, - $usergroupSelectUsers, - $usergroupSelectGroups, - $showUserStatus, - - $selectedViewIds); + new ColumnDto( + title: $title, + type: $type, + subtype: $subtype, + mandatory: $mandatory, + description: $description, + textDefault: $textDefault, + textAllowedPattern: $textAllowedPattern, + textMaxLength: $textMaxLength, + numberDefault: $numberDefault, + numberMin: $numberMin, + numberMax: $numberMax, + numberDecimals: $numberDecimals, + numberPrefix: $numberPrefix, + numberSuffix: $numberSuffix, + selectionOptions: $selectionOptions, + selectionDefault: $selectionDefault, + datetimeDefault: $datetimeDefault, + usergroupDefault: $usergroupDefault, + usergroupMultipleItems: $usergroupMultipleItems, + usergroupSelectUsers: $usergroupSelectUsers, + usergroupSelectGroups: $usergroupSelectGroups, + showUserStatus: $showUserStatus + ), + $selectedViewIds + ); }); } @@ -243,33 +241,30 @@ public function update( $id, $tableId, $this->userId, - $type, - $subtype, - $title, - $mandatory, - $description, - - $textDefault, - $textAllowedPattern, - $textMaxLength, - - $numberPrefix, - $numberSuffix, - $numberDefault, - $numberMin, - $numberMax, - $numberDecimals, - - $selectionOptions, - $selectionDefault, - - $datetimeDefault, - - $usergroupDefault, - $usergroupMultipleItems, - $usergroupSelectUsers, - $usergroupSelectGroups, - $showUserStatus + new ColumnDto( + title: $title, + type: $type, + subtype: $subtype, + mandatory: $mandatory, + description: $description, + textDefault: $textDefault, + textAllowedPattern: $textAllowedPattern, + textMaxLength: $textMaxLength, + numberDefault: $numberDefault, + numberMin: $numberMin, + numberMax: $numberMax, + numberDecimals: $numberDecimals, + numberPrefix: $numberPrefix, + numberSuffix: $numberSuffix, + selectionOptions: $selectionOptions, + selectionDefault: $selectionDefault, + datetimeDefault: $datetimeDefault, + usergroupDefault: $usergroupDefault, + usergroupMultipleItems: $usergroupMultipleItems, + usergroupSelectUsers: $usergroupSelectUsers, + usergroupSelectGroups: $usergroupSelectGroups, + showUserStatus: $showUserStatus + ) ); }); } diff --git a/lib/Db/Column.php b/lib/Db/Column.php index 3c7a04f2d..04d1f65a6 100644 --- a/lib/Db/Column.php +++ b/lib/Db/Column.php @@ -9,6 +9,7 @@ use JsonSerializable; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\ResponseDefinitions; use OCP\AppFramework\Db\Entity; @@ -152,6 +153,33 @@ public function __construct() { $this->addType('showUserStatus', 'boolean'); } + public static function fromDto(ColumnDto $data): self { + $column = new self(); + $column->setTitle($data->getTitle()); + $column->setType($data->getType()); + $column->setSubtype($data->getSubtype() ?? ''); + $column->setMandatory($data->isMandatory() ?? false); + $column->setDescription($data->getDescription() ?? ''); + $column->setTextDefault($data->getTextDefault()); + $column->setTextAllowedPattern($data->getTextAllowedPattern()); + $column->setTextMaxLength($data->getTextMaxLength()); + $column->setNumberDefault($data->getNumberDefault()); + $column->setNumberMin($data->getNumberMin()); + $column->setNumberMax($data->getNumberMax()); + $column->setNumberDecimals($data->getNumberDecimals()); + $column->setNumberPrefix($data->getNumberPrefix() ?? ''); + $column->setNumberSuffix($data->getNumberSuffix() ?? ''); + $column->setSelectionOptions($data->getSelectionOptions()); + $column->setSelectionDefault($data->getSelectionDefault()); + $column->setDatetimeDefault($data->getDatetimeDefault()); + $column->setUsergroupDefault($data->getUsergroupDefault()); + $column->setUsergroupMultipleItems($data->getUsergroupMultipleItems()); + $column->setUsergroupSelectUsers($data->getUsergroupSelectUsers()); + $column->setUsergroupSelectGroups($data->getUsergroupSelectGroups()); + $column->setShowUserStatus($data->getShowUserStatus()); + return $column; + } + public function getUsergroupDefaultArray():array { $default = $this->getUsergroupDefault(); if ($default !== "" && $default !== null) { diff --git a/lib/Dto/Column.php b/lib/Dto/Column.php new file mode 100644 index 000000000..1c240b4ec --- /dev/null +++ b/lib/Dto/Column.php @@ -0,0 +1,151 @@ +type; + } + + public function getSubtype(): ?string { + return $this->subtype; + } + + public function isMandatory(): ?bool { + return $this->mandatory; + } + + public function getTitle(): ?string { + return $this->title; + } + + public function getDescription(): ?string { + return $this->description; + } + + public function getTextDefault(): ?string { + return $this->textDefault; + } + + public function getTextAllowedPattern(): ?string { + return $this->textAllowedPattern; + } + + public function getTextMaxLength(): ?int { + return $this->textMaxLength; + } + + public function getNumberDefault(): ?float { + return $this->numberDefault; + } + + public function getNumberMin(): ?float { + return $this->numberMin; + } + + public function getNumberMax(): ?float { + return $this->numberMax; + } + + public function getNumberDecimals(): ?int { + return $this->numberDecimals; + } + + public function getNumberPrefix(): ?string { + return $this->numberPrefix; + } + + public function getNumberSuffix(): ?string { + return $this->numberSuffix; + } + + public function getSelectionOptions(): ?string { + return $this->selectionOptions; + } + + public function getSelectionDefault(): ?string { + return $this->selectionDefault; + } + + public function getDatetimeDefault(): ?string { + return $this->datetimeDefault; + } + + public function getUsergroupDefault(): ?string { + return $this->usergroupDefault; + } + + public function getUsergroupMultipleItems(): ?bool { + return $this->usergroupMultipleItems; + } + + public function getUsergroupSelectUsers(): ?bool { + return $this->usergroupSelectUsers; + } + + public function getUsergroupSelectGroups(): ?bool { + return $this->usergroupSelectGroups; + } + + public function getShowUserStatus(): ?bool { + return $this->showUserStatus; + } +} diff --git a/lib/Service/ColumnService.php b/lib/Service/ColumnService.php index 7d80e6de2..31908b413 100644 --- a/lib/Service/ColumnService.php +++ b/lib/Service/ColumnService.php @@ -12,6 +12,7 @@ use OCA\Tables\Db\Column; use OCA\Tables\Db\ColumnMapper; use OCA\Tables\Db\TableMapper; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -142,28 +143,7 @@ public function find(int $id, ?string $userId = null): Column { * @param string|null $userId * @param int|null $tableId * @param int|null $viewId - * @param string $type - * @param string|null $subtype - * @param string $title - * @param bool $mandatory - * @param string|null $description - * @param string|null $textDefault - * @param string|null $textAllowedPattern - * @param int|null $textMaxLength - * @param string|null $numberPrefix - * @param string|null $numberSuffix - * @param float|null $numberDefault - * @param float|null $numberMin - * @param float|null $numberMax - * @param int|null $numberDecimals - * @param string|null $selectionOptions - * @param string|null $selectionDefault - * @param string|null $datetimeDefault - * @param string|null $usergroupDefault - * @param bool|null $usergroupMultipleItems - * @param bool|null $usergroupSelectUsers - * @param bool|null $usergroupSelectGroups - * @param bool|null $showUserStatus + * @param ColumnDto $columnDto * @param array $selectedViewIds * @return Column * @@ -174,34 +154,7 @@ public function create( ?string $userId, ?int $tableId, ?int $viewId, - string $type, - ?string $subtype, - string $title, - bool $mandatory, - ?string $description, - - ?string $textDefault, - ?string $textAllowedPattern, - ?int $textMaxLength, - - ?string $numberPrefix, - ?string $numberSuffix, - ?float $numberDefault, - ?float $numberMin, - ?float $numberMax, - ?int $numberDecimals, - - ?string $selectionOptions, - ?string $selectionDefault, - - ?string $datetimeDefault, - - ?string $usergroupDefault, - ?bool $usergroupMultipleItems, - ?bool $usergroupSelectUsers, - ?bool $usergroupSelectGroups, - ?bool $showUserStatus, - + ColumnDto $columnDto, array $selectedViewIds = [] ):Column { // security @@ -247,7 +200,7 @@ public function create( // Add number to title to avoid duplicate $columns = $this->mapper->findAllByTable($table->getId()); $i = 1; - $newTitle = $title; + $newTitle = $columnDto->getTitle(); while (true) { $found = false; foreach ($columns as $column) { @@ -259,36 +212,15 @@ public function create( if (!$found) { break; } - $newTitle = $title . ' (' . $i . ')'; + $newTitle = $columnDto->getTitle() . ' (' . $i . ')'; $i++; } $time = new DateTime(); - $item = new Column(); + $item = Column::fromDto($columnDto); $item->setTitle($newTitle); $item->setTableId($table->getId()); - $item->setType($type); - $item->setSubtype($subtype !== null ? $subtype: ''); - $item->setMandatory($mandatory); - $item->setDescription($description ?? ''); - $item->setTextDefault($textDefault); - $item->setTextAllowedPattern($textAllowedPattern); - $item->setTextMaxLength($textMaxLength); - $item->setNumberDefault($numberDefault); - $item->setNumberMin($numberMin); - $item->setNumberMax($numberMax); - $item->setNumberDecimals($numberDecimals); - $item->setNumberPrefix($numberPrefix !== null ? $numberPrefix: ''); - $item->setNumberSuffix($numberSuffix !== null ? $numberSuffix: ''); $this->updateMetadata($item, $userId, true); - $item->setSelectionOptions($selectionOptions); - $item->setSelectionDefault($selectionDefault); - $item->setDatetimeDefault($datetimeDefault); - $item->setUsergroupDefault($usergroupDefault); - $item->setUsergroupMultipleItems($usergroupMultipleItems); - $item->setUsergroupSelectUsers($usergroupSelectUsers); - $item->setUsergroupSelectGroups($usergroupSelectGroups); - $item->setShowUserStatus($showUserStatus); try { $entity = $this->mapper->insert($item); @@ -322,28 +254,7 @@ public function create( * @param int $columnId * @param int|null $tableId * @param string|null $userId - * @param string|null $type - * @param string|null $subtype - * @param string|null $title - * @param bool $mandatory - * @param string|null $description - * @param string|null $textDefault - * @param string|null $textAllowedPattern - * @param int|null $textMaxLength - * @param string|null $numberPrefix - * @param string|null $numberSuffix - * @param float|null $numberDefault - * @param float|null $numberMin - * @param float|null $numberMax - * @param int|null $numberDecimals - * @param string|null $selectionOptions - * @param string|null $selectionDefault - * @param string|null $datetimeDefault - * @param string|null $usergroupDefault - * @param bool|null $usergroupMultipleItems - * @param bool|null $usergroupSelectUsers - * @param bool|null $usergroupSelectGroups - * @param bool|null $showUserStatus + * @param ColumnDto $columnDto * @return Column * @throws InternalError */ @@ -351,33 +262,7 @@ public function update( int $columnId, ?int $tableId, ?string $userId, - ?string $type, - ?string $subtype, - ?string $title, - ?bool $mandatory, - ?string $description, - - ?string $textDefault, - ?string $textAllowedPattern, - ?int $textMaxLength, - - ?string $numberPrefix, - ?string $numberSuffix, - ?float $numberDefault, - ?float $numberMin, - ?float $numberMax, - ?int $numberDecimals, - - ?string $selectionOptions, - ?string $selectionDefault, - - ?string $datetimeDefault, - - ?string $usergroupDefault, - ?bool $usergroupMultipleItems, - ?bool $usergroupSelectUsers, - ?bool $usergroupSelectGroups, - ?bool $showUserStatus, + ColumnDto $columnDto ):Column { try { /** @var Column $item */ @@ -388,50 +273,50 @@ public function update( throw new PermissionError('update column id = '.$columnId.' is not allowed.'); } - if ($title !== null) { - $item->setTitle($title); + if ($columnDto->getTitle() !== null) { + $item->setTitle($columnDto->getTitle()); } if ($tableId !== null) { $item->setTableId($tableId); } - if ($type !== null) { - $item->setType($type); + if ($columnDto->getType() !== null) { + $item->setType($columnDto->getType()); } - if ($subtype !== null) { - $item->setSubtype($subtype); + if ($columnDto->getSubtype() !== null) { + $item->setSubtype($columnDto->getSubtype()); } - if ($numberPrefix !== null) { - $item->setNumberPrefix($numberPrefix); + if ($columnDto->getNumberPrefix() !== null) { + $item->setNumberPrefix($columnDto->getNumberPrefix()); } - if ($numberSuffix !== null) { - $item->setNumberSuffix($numberSuffix); + if ($columnDto->getNumberSuffix() !== null) { + $item->setNumberSuffix($columnDto->getNumberSuffix()); } - if ($mandatory !== null) { - $item->setMandatory($mandatory); + if ($columnDto->isMandatory() !== null) { + $item->setMandatory($columnDto->isMandatory()); } - $item->setDescription($description); - $item->setTextDefault($textDefault); - $item->setTextAllowedPattern($textAllowedPattern); - $item->setTextMaxLength($textMaxLength); - $item->setNumberDefault($numberDefault); - $item->setNumberMin($numberMin); - $item->setNumberMax($numberMax); - $item->setNumberDecimals($numberDecimals); - if ($selectionOptions !== null) { - $item->setSelectionOptions($selectionOptions); + $item->setDescription($columnDto->getDescription()); + $item->setTextDefault($columnDto->getTextDefault()); + $item->setTextAllowedPattern($columnDto->getTextAllowedPattern()); + $item->setTextMaxLength($columnDto->getTextMaxLength()); + $item->setNumberDefault($columnDto->getNumberDefault()); + $item->setNumberMin($columnDto->getNumberMin()); + $item->setNumberMax($columnDto->getNumberMax()); + $item->setNumberDecimals($columnDto->getNumberDecimals()); + if ($columnDto->getSelectionOptions() !== null) { + $item->setSelectionOptions($columnDto->getSelectionOptions()); } - if ($selectionDefault !== null) { - $item->setSelectionDefault($selectionDefault); + if ($columnDto->getSelectionDefault() !== null) { + $item->setSelectionDefault($columnDto->getSelectionDefault()); } - $item->setDatetimeDefault($datetimeDefault); + $item->setDatetimeDefault($columnDto->getDatetimeDefault()); - if ($usergroupDefault !== null) { - $item->setUsergroupDefault($usergroupDefault); + if ($columnDto->getUsergroupDefault() !== null) { + $item->setUsergroupDefault($columnDto->getUsergroupDefault()); } - $item->setUsergroupMultipleItems($usergroupMultipleItems); - $item->setUsergroupSelectUsers($usergroupSelectUsers); - $item->setUsergroupSelectGroups($usergroupSelectGroups); - $item->setShowUserStatus($showUserStatus); + $item->setUsergroupMultipleItems($columnDto->getUsergroupMultipleItems()); + $item->setUsergroupSelectUsers($columnDto->getUsergroupSelectUsers()); + $item->setUsergroupSelectGroups($columnDto->getUsergroupSelectGroups()); + $item->setShowUserStatus($columnDto->getShowUserStatus()); $this->updateMetadata($item, $userId); return $this->enhanceColumn($this->mapper->update($item)); @@ -574,29 +459,17 @@ public function findOrCreateColumnsByTitleForTableAsArray(?int $tableId, ?int $v $userId, $tableId, $viewId, - $dataTypes[$i]['type'], - $dataTypes[$i]['subtype'] ?? '', - $title, - false, - $description, - null, - null, - null, - $dataTypes[$i]['number_prefix'] ?? null, - $dataTypes[$i]['number_suffix'] ?? null, - null, - null, - null, - $dataTypes[$i]['number_decimals'] ?? null, - null, - $dataTypes[$i]['selection_default'] ?? null, - null, - null, - null, - null, - null, - null, - [] + new ColumnDto( + title: $title, + type: $dataTypes[$i]['type'], + subtype: $dataTypes[$i]['subtype'] ?? '', + mandatory: false, + description: $description, + numberDecimals: $dataTypes[$i]['number_decimals'] ?? null, + numberPrefix: $dataTypes[$i]['number_prefix'] ?? null, + numberSuffix: $dataTypes[$i]['number_suffix'] ?? null, + selectionDefault: $dataTypes[$i]['selection_default'] ?? null + ), ); $countCreatedColumns++; } diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index f83a09b37..4f9d012de 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -9,6 +9,7 @@ use OC\User\NoUserException; use OCA\Tables\Db\Column; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -419,28 +420,7 @@ private function getColumns(Row $firstRow, Row $secondRow): void { $this->userId, $this->tableId, $this->viewId, - $this->columnsConfig[$index]['type'], - $this->columnsConfig[$index]['subtype'], - $this->columnsConfig[$index]['title'], - $this->columnsConfig[$index]['mandatory'] ?? false, - $this->columnsConfig[$index]['description'] ?? '', - $this->columnsConfig[$index]['textDefault'] ?? '', - $this->columnsConfig[$index]['textAllowedPattern'] ?? '', - $this->columnsConfig[$index]['textMaxLength'] ?? null, - $this->columnsConfig[$index]['numberPrefix'] ?? '', - $this->columnsConfig[$index]['numberSuffix'] ?? '', - $this->columnsConfig[$index]['numberDefault'] ?? null, - $this->columnsConfig[$index]['numberMin'] ?? null, - $this->columnsConfig[$index]['numberMax'] ?? null, - $this->columnsConfig[$index]['numberDecimals'] ?? 0, - $this->columnsConfig[$index]['selectionOptions'] ?? '', - $this->columnsConfig[$index]['selectionDefault'] ?? '', - $this->columnsConfig[$index]['datetimeDefault'] ?? '', - $this->columnsConfig[$index]['usergroupDefault'] ?? null, - $this->columnsConfig[$index]['usergroupMultipleItems'] ?? null, - $this->columnsConfig[$index]['usergroupSelectUsers'] ?? null, - $this->columnsConfig[$index]['usergroupSelectGroups'] ?? null, - $this->columnsConfig[$index]['showUserStatus'] ?? null, + ColumnDto::createFromArray($this->columnsConfig[$index]), $this->columnsConfig[$index]['selectedViewIds'] ?? [] ); $title = $column->getTitle(); diff --git a/lib/Service/TableTemplateService.php b/lib/Service/TableTemplateService.php index 81aebb76d..8237d1a1d 100644 --- a/lib/Service/TableTemplateService.php +++ b/lib/Service/TableTemplateService.php @@ -9,6 +9,7 @@ use OCA\Tables\Db\Column; use OCA\Tables\Db\Table; +use OCA\Tables\Dto\Column as ColumnDto; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -797,84 +798,10 @@ private function createColumn(int $tableId, array $parameters): ?Column { } return $this->columnService->create( - - // userId $this->userId, - - // tableId $tableId, - - // viewId null, - - // column type - (isset($parameters['type'])) ? $parameters['type'] : 'text', - - // column subtype - (isset($parameters['subtype'])) ? $parameters['subtype'] : '', - - // title - (isset($parameters['title']) && $parameters['title'] != '') ? $parameters['title'] : $this->l->t('No title given'), - - // mandatory - isset($parameters['mandatory']) && !!$parameters['mandatory'], - - // description - (isset($parameters['description'])) ? $parameters['description'] : '', - - // textDefault - (isset($parameters['textDefault'])) ? $parameters['textDefault'] : '', - - // textAllowedPattern - (isset($parameters['textAllowedPattern'])) ? $parameters['textAllowedPattern'] : '', - - // textMaxLength - (isset($parameters['textMaxLength'])) ? $parameters['textMaxLength'] : -1, - - // numberPrefix - (isset($parameters['numberPrefix'])) ? $parameters['numberPrefix'] : '', - - // numberSuffix - (isset($parameters['numberSuffix'])) ? $parameters['numberSuffix'] : '', - - // numberDefault - (isset($parameters['numberDefault'])) ? $parameters['numberDefault'] : null, - - // numberMin - (isset($parameters['numberMin'])) ? $parameters['numberMin'] : null, - - // numberMax - (isset($parameters['numberMax'])) ? $parameters['numberMax'] : null, - - // numberDecimals - (isset($parameters['numberDecimals'])) ? $parameters['numberDecimals'] : null, - - // selectionOptions - (isset($parameters['selectionOptions'])) ? $parameters['selectionOptions'] : '', - - // selectionDefault - (isset($parameters['selectionDefault'])) ? $parameters['selectionDefault'] : '', - - // datetimeDefault - (isset($parameters['datetimeDefault'])) ? $parameters['datetimeDefault'] : '', - - // usergroupDefault - (isset($parameters['usergroupDefault'])) ? $parameters['usergroupDefault'] : '', - - // usergroupMultipleItems - (isset($parameters['usergroupMultipleItems'])) ? $parameters['usergroupMultipleItems'] : null, - - // usergroupSelectUsers - (isset($parameters['usergroupSelectUsers'])) ? $parameters['usergroupSelectUsers'] : null, - - // usergroupSelectGroups - (isset($parameters['usergroupSelectGroups'])) ? $parameters['usergroupSelectGroups'] : null, - - // showUserStatus - (isset($parameters['showUserStatus'])) ? $parameters['showUserStatus'] : null, - - // additional view ids - [] + ColumnDto::createFromArray($parameters) ); }