@@ -306,14 +306,36 @@ public function create(User $user, bool $notrigger = false): int
306
306
}
307
307
}
308
308
309
- $ sheet ->fetchObjectLinked ($ this ->fk_sheet , 'digiquali_ ' . $ sheet ->element );
310
- if (!empty ($ sheet ->linkedObjects ['digiquali_question ' ])) {
311
- foreach ($ sheet ->linkedObjects ['digiquali_question ' ] as $ question ) {
312
- $ controlLine ->ref = $ controlLine ->getNextNumRef ();
313
- $ controlLine ->entity = $ this ->entity ;
314
- $ controlLine ->status = 1 ;
315
- $ controlLine ->{'fk_ ' . $ this ->element } = $ this ->id ;
316
- $ controlLine ->fk_question = $ question ->id ;
309
+ $ questionAndGroups = $ sheet ->fetchQuestionsAndGroups ();
310
+
311
+ $ questions = [];
312
+ if (is_array ($ questionAndGroups ) && !empty ($ questionAndGroups )) {
313
+ foreach ($ questionAndGroups as $ questionOrGroup ) {
314
+ if ($ questionOrGroup ->element == 'questiongroup ' ) {
315
+ $ groupQuestions = $ questionOrGroup ->fetchQuestionsOrderedByPosition ();
316
+ if (is_array ($ groupQuestions ) && !empty ($ groupQuestions )) {
317
+ foreach ($ groupQuestions as $ groupQuestion ) {
318
+ $ groupQuestion ->fk_question_group = $ questionOrGroup ->id ;
319
+ $ questions [] = $ groupQuestion ;
320
+ }
321
+ }
322
+ } else {
323
+ $ questionOrGroup ->fk_question_group = 0 ;
324
+ $ questions [] = $ questionOrGroup ;
325
+ }
326
+ }
327
+ }
328
+ if (!empty ($ questions )) {
329
+ foreach ($ questions as $ question ) {
330
+ $ controlLine ->ref = $ controlLine ->getNextNumRef ();
331
+ $ fk_element = 'fk_ ' . $ object ->element ;
332
+ $ controlLine ->fk_control = $ this ->id ;
333
+ $ controlLine ->fk_question = $ question ->id ;
334
+ $ controlLine ->fk_question_group = $ question ->fk_question_group ;
335
+ $ controlLine ->answer = '' ;
336
+ $ controlLine ->comment = '' ;
337
+ $ controlLine ->entity = $ conf ->entity ;
338
+ $ controlLine ->status = 1 ;
317
339
318
340
$ controlLine ->create ($ user );
319
341
}
@@ -1341,22 +1363,23 @@ class ControlLine extends SaturneObject
1341
1363
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor
1342
1364
*/
1343
1365
public $ fields = [
1344
- 'rowid ' => ['type ' => 'integer ' , 'label ' => 'TechnicalID ' , 'enabled ' => 1 , 'position ' => 1 , 'notnull ' => 1 , 'visible ' => 0 , 'noteditable ' => 1 , 'index ' => 1 , 'comment ' => 'Id ' ],
1345
- 'ref ' => ['type ' => 'varchar(128) ' , 'label ' => 'Ref ' , 'enabled ' => 1 , 'position ' => 10 , 'notnull ' => 1 , 'visible ' => 1 , 'noteditable ' => 1 , 'default ' => '(PROV) ' , 'index ' => 1 , 'searchall ' => 1 , 'showoncombobox ' => 1 , 'validate ' => 1 , 'comment ' => 'Reference of object ' ],
1346
- 'ref_ext ' => ['type ' => 'varchar(128) ' , 'label ' => 'RefExt ' , 'enabled ' => 1 , 'position ' => 20 , 'notnull ' => 0 , 'visible ' => 0 ],
1347
- 'entity ' => ['type ' => 'integer ' , 'label ' => 'Entity ' , 'enabled ' => 1 , 'position ' => 30 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 ],
1348
- 'date_creation ' => ['type ' => 'datetime ' , 'label ' => 'DateCreation ' , 'enabled ' => 1 , 'position ' => 40 , 'notnull ' => 1 , 'visible ' => 0 ],
1349
- 'tms ' => ['type ' => 'timestamp ' , 'label ' => 'DateModification ' , 'enabled ' => 1 , 'position ' => 50 , 'notnull ' => 0 , 'visible ' => 0 ],
1350
- 'import_key ' => ['type ' => 'varchar(14) ' , 'label ' => 'ImportId ' , 'enabled ' => 1 , 'position ' => 60 , 'notnull ' => 0 , 'visible ' => 0 , 'index ' => 0 ],
1351
- 'status ' => ['type ' => 'smallint ' , 'label ' => 'Status ' , 'enabled ' => 1 , 'position ' => 70 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 , 'default ' => 1 ],
1352
- 'type ' => ['type ' => 'varchar(128) ' , 'label ' => 'Type ' , 'enabled ' => 0 , 'position ' => 80 , 'notnull ' => 0 , 'visible ' => 0 ],
1353
- 'answer ' => ['type ' => 'text ' , 'label ' => 'Answer ' , 'enabled ' => 1 , 'position ' => 90 , 'notnull ' => 0 , 'visible ' => 0 ],
1354
- 'answer_photo ' => ['type ' => 'text ' , 'label ' => 'AnswerPhoto ' , 'enabled ' => 0 , 'position ' => 100 , 'notnull ' => 0 , 'visible ' => 0 ],
1355
- 'comment ' => ['type ' => 'text ' , 'label ' => 'Comment ' , 'enabled ' => 1 , 'position ' => 110 , 'notnull ' => 0 , 'visible ' => 0 ],
1356
- 'fk_user_creat ' => ['type ' => 'integer:User:user/class/user.class.php ' , 'label ' => 'UserAuthor ' , 'picto ' => 'user ' , 'enabled ' => 1 , 'position ' => 120 , 'notnull ' => 1 , 'visible ' => 0 , 'foreignkey ' => 'user.rowid ' ],
1357
- 'fk_user_modif ' => ['type ' => 'integer:User:user/class/user.class.php ' , 'label ' => 'UserModif ' , 'picto ' => 'user ' , 'enabled ' => 1 , 'position ' => 130 , 'notnull ' => 0 , 'visible ' => 0 , 'foreignkey ' => 'user.rowid ' ],
1358
- 'fk_control ' => ['type ' => 'integer:Control:digiquali/class/survey.class.php ' , 'label ' => 'Control ' , 'picto ' => 'fontawesome_fa-tasks_fas_#d35968 ' , 'enabled ' => 1 , 'position ' => 140 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 , 'css ' => 'maxwidth500 widthcentpercentminusxx ' , 'foreignkey ' => 'digiquali_survey.rowid ' ],
1359
- 'fk_question ' => ['type ' => 'integer:Question:digiquali/class/question.class.php ' , 'label ' => 'Question ' , 'picto ' => 'fontawesome_fa-question_fas_#d35968 ' , 'enabled ' => 1 , 'position ' => 150 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 , 'css ' => 'maxwidth500 widthcentpercentminusxx ' , 'foreignkey ' => 'digiquali_question.rowid ' ],
1366
+ 'rowid ' => ['type ' => 'integer ' , 'label ' => 'TechnicalID ' , 'enabled ' => 1 , 'position ' => 1 , 'notnull ' => 1 , 'visible ' => 0 , 'noteditable ' => 1 , 'index ' => 1 , 'comment ' => 'Id ' ],
1367
+ 'ref ' => ['type ' => 'varchar(128) ' , 'label ' => 'Ref ' , 'enabled ' => 1 , 'position ' => 10 , 'notnull ' => 1 , 'visible ' => 1 , 'noteditable ' => 1 , 'default ' => '(PROV) ' , 'index ' => 1 , 'searchall ' => 1 , 'showoncombobox ' => 1 , 'validate ' => 1 , 'comment ' => 'Reference of object ' ],
1368
+ 'ref_ext ' => ['type ' => 'varchar(128) ' , 'label ' => 'RefExt ' , 'enabled ' => 1 , 'position ' => 20 , 'notnull ' => 0 , 'visible ' => 0 ],
1369
+ 'entity ' => ['type ' => 'integer ' , 'label ' => 'Entity ' , 'enabled ' => 1 , 'position ' => 30 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 ],
1370
+ 'date_creation ' => ['type ' => 'datetime ' , 'label ' => 'DateCreation ' , 'enabled ' => 1 , 'position ' => 40 , 'notnull ' => 1 , 'visible ' => 0 ],
1371
+ 'tms ' => ['type ' => 'timestamp ' , 'label ' => 'DateModification ' , 'enabled ' => 1 , 'position ' => 50 , 'notnull ' => 0 , 'visible ' => 0 ],
1372
+ 'import_key ' => ['type ' => 'varchar(14) ' , 'label ' => 'ImportId ' , 'enabled ' => 1 , 'position ' => 60 , 'notnull ' => 0 , 'visible ' => 0 , 'index ' => 0 ],
1373
+ 'status ' => ['type ' => 'smallint ' , 'label ' => 'Status ' , 'enabled ' => 1 , 'position ' => 70 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 , 'default ' => 1 ],
1374
+ 'type ' => ['type ' => 'varchar(128) ' , 'label ' => 'Type ' , 'enabled ' => 0 , 'position ' => 80 , 'notnull ' => 0 , 'visible ' => 0 ],
1375
+ 'answer ' => ['type ' => 'text ' , 'label ' => 'Answer ' , 'enabled ' => 1 , 'position ' => 90 , 'notnull ' => 0 , 'visible ' => 0 ],
1376
+ 'answer_photo ' => ['type ' => 'text ' , 'label ' => 'AnswerPhoto ' , 'enabled ' => 0 , 'position ' => 100 , 'notnull ' => 0 , 'visible ' => 0 ],
1377
+ 'comment ' => ['type ' => 'text ' , 'label ' => 'Comment ' , 'enabled ' => 1 , 'position ' => 110 , 'notnull ' => 0 , 'visible ' => 0 ],
1378
+ 'fk_user_creat ' => ['type ' => 'integer:User:user/class/user.class.php ' , 'label ' => 'UserAuthor ' , 'picto ' => 'user ' , 'enabled ' => 1 , 'position ' => 120 , 'notnull ' => 1 , 'visible ' => 0 , 'foreignkey ' => 'user.rowid ' ],
1379
+ 'fk_user_modif ' => ['type ' => 'integer:User:user/class/user.class.php ' , 'label ' => 'UserModif ' , 'picto ' => 'user ' , 'enabled ' => 1 , 'position ' => 130 , 'notnull ' => 0 , 'visible ' => 0 , 'foreignkey ' => 'user.rowid ' ],
1380
+ 'fk_control ' => ['type ' => 'integer:Control:digiquali/class/survey.class.php ' , 'label ' => 'Control ' , 'picto ' => 'fontawesome_fa-tasks_fas_#d35968 ' , 'enabled ' => 1 , 'position ' => 140 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 , 'css ' => 'maxwidth500 widthcentpercentminusxx ' , 'foreignkey ' => 'digiquali_survey.rowid ' ],
1381
+ 'fk_question ' => ['type ' => 'integer:Question:digiquali/class/question.class.php ' , 'label ' => 'Question ' , 'picto ' => 'fontawesome_fa-question_fas_#d35968 ' , 'enabled ' => 1 , 'position ' => 150 , 'notnull ' => 1 , 'visible ' => 0 , 'index ' => 1 , 'css ' => 'maxwidth500 widthcentpercentminusxx ' , 'foreignkey ' => 'digiquali_question.rowid ' ],
1382
+ 'fk_question_group ' => ['type ' => 'integer:QuestionGroup:digiquali/class/questiongroup.class.php ' , 'label ' => 'QuestionGroup ' , 'picto ' => 'fontawesome_fa-folder_fas_#d35968 ' , 'enabled ' => 1 , 'position ' => 160 , 'notnull ' => 1 , 'default ' => 0 , 'visible ' => 0 , 'index ' => 1 , 'css ' => 'maxwidth500 widthcentpercentminusxx ' ],
1360
1383
];
1361
1384
1362
1385
/**
@@ -1439,6 +1462,11 @@ class ControlLine extends SaturneObject
1439
1462
*/
1440
1463
public int $ fk_question ;
1441
1464
1465
+ /**
1466
+ * @var int Question group ID
1467
+ */
1468
+ public int $ fk_question_group ;
1469
+
1442
1470
/**
1443
1471
* Constructor
1444
1472
*
@@ -1457,9 +1485,9 @@ public function __construct(DoliDB $db)
1457
1485
* @return array|int Int <0 if KO, array of pages if OK
1458
1486
* @throws Exception
1459
1487
*/
1460
- public function fetchFromParentWithQuestion (int $ controlID , int $ questionID )
1488
+ public function fetchFromParentWithQuestion (int $ controlID , int $ questionID, int $ questionGroupId = 0 )
1461
1489
{
1462
- return $ this ->fetchAll ('' , '' , 1 , 0 , ['customsql ' => 't.fk_control = ' . $ controlID . ' AND t.fk_question = ' . $ questionID . ' AND t.status > 0 ' ]);
1490
+ return $ this ->fetchAll ('' , '' , 1 , 0 , ['customsql ' => 't.fk_control = ' . $ controlID . ' AND t.fk_question = ' . $ questionID . ' AND t.status > 0 AND t.fk_question_group = ' . $ questionGroupId ]);
1463
1491
}
1464
1492
}
1465
1493
0 commit comments