Skip to content

Commit beecfd9

Browse files
committed
#1927 [QuestionGroup] add: question group
1 parent f979560 commit beecfd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3582
-314
lines changed

class/control.class.php

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,36 @@ public function create(User $user, bool $notrigger = false): int
306306
}
307307
}
308308

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;
317339

318340
$controlLine->create($user);
319341
}
@@ -1341,22 +1363,23 @@ class ControlLine extends SaturneObject
13411363
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor
13421364
*/
13431365
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'],
13601383
];
13611384

13621385
/**
@@ -1439,6 +1462,11 @@ class ControlLine extends SaturneObject
14391462
*/
14401463
public int $fk_question;
14411464

1465+
/**
1466+
* @var int Question group ID
1467+
*/
1468+
public int $fk_question_group;
1469+
14421470
/**
14431471
* Constructor
14441472
*
@@ -1457,9 +1485,9 @@ public function __construct(DoliDB $db)
14571485
* @return array|int Int <0 if KO, array of pages if OK
14581486
* @throws Exception
14591487
*/
1460-
public function fetchFromParentWithQuestion(int $controlID, int $questionID)
1488+
public function fetchFromParentWithQuestion(int $controlID, int $questionID, int $questionGroupId = 0)
14611489
{
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]);
14631491
}
14641492
}
14651493

class/question.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ public function selectQuestionList($selected = '', $htmlname = 'socid', $filter
535535
$num = $this->db->num_rows($resql);
536536
$i = 0;
537537

538+
if ($showempty)
539+
{
540+
if ($showempty === '1') $out .= '<option value="0" selected>'. dol_escape_htmltag('&nbsp;') . '</option>';
541+
else $out .= '<option value="0"></option>';
542+
}
538543
if ($num) {
539544
while ($i < $num) {
540545
$obj = $this->db->fetch_object($resql);

0 commit comments

Comments
 (0)