@@ -130,12 +130,14 @@ public function showScheme(int $id): DataResponse {
130130 * @param string $description description
131131 * @param list<TablesColumn> $columns columns
132132 * @param list<TablesView> $views views
133+ * @param list<array{columnId: int, order: int, readonly: bool}> $columnOrder Default column order settings
134+ * @param list<array{columnId: int, mode: 'ASC'|'DESC'}> $sort Default sort rules
133135 * @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
134136 *
135137 * 200: Tables returned
136138 */
137139 #[NoAdminRequired]
138- public function createFromScheme (string $ title , string $ emoji , string $ description , array $ columns , array $ views ): DataResponse {
140+ public function createFromScheme (string $ title , string $ emoji , string $ description , array $ columns , array $ views, array $ columnOrder = [], array $ sort = [] ): DataResponse {
139141 try {
140142 $ this ->db ->beginTransaction ();
141143 $ table = $ this ->service ->create ($ title , 'custom ' , $ emoji , $ description );
@@ -175,6 +177,21 @@ public function createFromScheme(string $title, string $emoji, string $descripti
175177 );
176178 $ colMap [$ column ['id ' ]] = $ col ->getId ();
177179 }
180+ if (!empty ($ columnOrder ) || !empty ($ sort )) {
181+ $ remappedColumnOrder = !empty ($ columnOrder ) ? array_map (static function (array $ entry ) use ($ colMap ): array {
182+ if (isset ($ entry ['columnId ' ]) && $ entry ['columnId ' ] > 0 ) {
183+ $ entry ['columnId ' ] = $ colMap [$ entry ['columnId ' ]] ?? $ entry ['columnId ' ];
184+ }
185+ return $ entry ;
186+ }, $ columnOrder ) : null ;
187+ $ remappedSort = !empty ($ sort ) ? array_map (static function (array $ entry ) use ($ colMap ): array {
188+ if (isset ($ entry ['columnId ' ]) && $ entry ['columnId ' ] > 0 ) {
189+ $ entry ['columnId ' ] = $ colMap [$ entry ['columnId ' ]] ?? $ entry ['columnId ' ];
190+ }
191+ return $ entry ;
192+ }, $ sort ) : null ;
193+ $ table = $ this ->service ->update ($ table ->getId (), null , null , null , null , $ this ->userId , $ remappedColumnOrder , $ remappedSort );
194+ }
178195 foreach ($ views as $ view ) {
179196 $ newView = $ this ->viewService ->create (
180197 $ view ['title ' ],
@@ -262,6 +279,8 @@ public function create(string $title, ?string $emoji, ?string $description, stri
262279 * @param string|null $emoji New table emoji
263280 * @param bool $archived whether the table is archived
264281 * @param string $description the tables description
282+ * @param list<array{columnId: int, order: int, readonly: bool}>|string|null $columnSettings Default column order settings (array or JSON string)
283+ * @param list<array{columnId: int, mode: 'ASC'|'DESC'}>|string|null $sort Default sort rules (array or JSON string)
265284 * @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
266285 *
267286 * 200: Tables returned
@@ -270,9 +289,15 @@ public function create(string $title, ?string $emoji, ?string $description, stri
270289 */
271290 #[NoAdminRequired]
272291 #[RequirePermission(permission: Application::PERMISSION_MANAGE , type: Application::NODE_TYPE_TABLE , idParam: 'id ' )]
273- public function update (int $ id , ?string $ title = null , ?string $ emoji = null , ?string $ description = null , ?bool $ archived = null ): DataResponse {
292+ public function update (int $ id , ?string $ title = null , ?string $ emoji = null , ?string $ description = null , ?bool $ archived = null , null |array |string $ columnSettings = null , null |array |string $ sort = null ): DataResponse {
293+ if (is_string ($ columnSettings )) {
294+ $ columnSettings = json_decode ($ columnSettings , true ) ?? null ;
295+ }
296+ if (is_string ($ sort )) {
297+ $ sort = json_decode ($ sort , true ) ?? null ;
298+ }
274299 try {
275- return new DataResponse ($ this ->service ->update ($ id , $ title , $ emoji , $ description , $ archived , $ this ->userId )->jsonSerialize ());
300+ return new DataResponse ($ this ->service ->update ($ id , $ title , $ emoji , $ description , $ archived , $ this ->userId , $ columnSettings , $ sort )->jsonSerialize ());
276301 } catch (PermissionError $ e ) {
277302 return $ this ->handlePermissionError ($ e );
278303 } catch (InternalError $ e ) {
0 commit comments