@@ -193,7 +193,12 @@ protected function createTestColumn(int $tableId, array $data = []) {
193193 'mandatory ' => false ,
194194 'order_weight ' => 0 ,
195195 'number_prefix ' => '' ,
196- 'number_suffix ' => ''
196+ 'number_suffix ' => '' ,
197+ 'text_default ' => '' ,
198+ 'number_default ' => null ,
199+ 'datetime_default ' => '' ,
200+ 'selection_default ' => '' ,
201+ 'usergroup_default ' => '' ,
197202 ];
198203
199204 $ testIdent = $ data ['test_ident ' ] ?? null ;
@@ -318,27 +323,32 @@ protected function addCellsToRow(int $rowId, array $cellsData, array $columnMapp
318323 */
319324 protected function insertCellData (int $ rowId , int $ columnId , $ value ): void {
320325 $ qb = $ this ->connection ->getQueryBuilder ();
321- $ result = $ qb ->select ('type ' )
326+ $ result = $ qb ->select ('type ' , ' subtype ' )
322327 ->from ('tables_columns ' )
323328 ->where ($ qb ->expr ()->eq ('id ' , $ qb ->createNamedParameter ($ columnId )))
324329 ->executeQuery ();
325330
326- $ columnType = $ result ->fetchOne ();
331+ $ column = $ result ->fetch ();
327332 $ result ->closeCursor ();
328333
329- if (!$ columnType ) {
334+ if (!$ column ) {
330335 throw new \InvalidArgumentException ("Column with ID $ columnId not found " );
331336 }
332337
333- $ this ->insertCellIntoTypeTable ($ rowId , $ columnId , $ value , $ columnType );
338+ $ this ->insertCellIntoTypeTable ($ rowId , $ columnId , $ value , $ column [ ' type ' ], $ column [ ' subtype ' ] );
334339 }
335340
336341 /**
337342 * Inserts cell data into the appropriate type-specific table
338343 */
339- protected function insertCellIntoTypeTable (int $ rowId , int $ columnId , $ value , string $ columnType ): void {
344+ protected function insertCellIntoTypeTable (int $ rowId , int $ columnId , $ value , string $ columnType, string $ columnSubtype ): void {
340345 $ tableName = 'tables_row_cells_ ' . $ columnType ;
341346
347+ // Handle selection type - convert values to IDs based on selection_options
348+ if ($ columnType === 'selection ' && $ columnSubtype !== 'check ' ) {
349+ $ value = $ this ->convertSelectionValuesToIds ($ columnId , $ value );
350+ }
351+
342352 $ qb = $ this ->connection ->getQueryBuilder ();
343353 $ qb ->insert ($ tableName )
344354 ->setValue ('row_id ' , $ qb ->createNamedParameter ($ rowId ))
@@ -403,6 +413,53 @@ protected function extractTestIdentMapping(array $results): array {
403413 return $ mapping ;
404414 }
405415
416+ /**
417+ * Converts selection values to IDs based on selection_options
418+ */
419+ protected function convertSelectionValuesToIds (int $ columnId , $ value ) {
420+ // Get column configuration to find selection_options
421+ $ qb = $ this ->connection ->getQueryBuilder ();
422+ $ result = $ qb ->select ('selection_options ' )
423+ ->from ('tables_columns ' )
424+ ->where ($ qb ->expr ()->eq ('id ' , $ qb ->createNamedParameter ($ columnId )))
425+ ->executeQuery ();
426+
427+ $ selectionOptions = $ result ->fetchOne ();
428+ $ result ->closeCursor ();
429+
430+ if (!$ selectionOptions ) {
431+ throw new \InvalidArgumentException ("Column with ID $ columnId not found " );
432+ }
433+
434+ $ selectionOptions = json_decode ($ selectionOptions , true );
435+
436+ // Create mapping from label to id
437+ $ optionMapping = [];
438+ foreach ($ selectionOptions as $ option ) {
439+ if (isset ($ option ['label ' ]) && isset ($ option ['id ' ])) {
440+ $ optionMapping [$ option ['label ' ]] = $ option ['id ' ];
441+ }
442+ }
443+
444+ // Convert single value or array of values
445+ if (is_array ($ value )) {
446+ // Multiple selection - convert each value to ID and return as JSON
447+ $ convertedValues = [];
448+ foreach ($ value as $ optionText ) {
449+ if (isset ($ optionMapping [$ optionText ])) {
450+ $ convertedValues [] = $ optionMapping [$ optionText ];
451+ }
452+ }
453+ return json_encode ($ convertedValues );
454+ } else {
455+ // Single selection - convert to ID
456+ if (isset ($ optionMapping [$ value ])) {
457+ return $ optionMapping [$ value ];
458+ }
459+ return null ;
460+ }
461+ }
462+
406463 /**
407464 * Gets ID by test_ident from creation results
408465 * @param array $results Array of creation results
0 commit comments