@@ -66,6 +66,9 @@ class PluginFormcreatorFormAnswer extends CommonDBTM
66
66
/** @var PluginFormcreatorForm $form The form attached to the object */
67
67
private $ form = null ;
68
68
69
+ /** @var array $answers set od answers */
70
+ private array $ answers = [];
71
+
69
72
public static function getStatuses () {
70
73
return [
71
74
self ::STATUS_WAITING => __ ('Waiting ' , 'formcreator ' ),
@@ -554,9 +557,9 @@ public function showForm($ID, $options = []) {
554
557
$ domain = PluginFormcreatorForm::getTranslationDomain ($ _SESSION ['glpilanguage ' ], $ form ->getID ());
555
558
556
559
// Get fields populated with answers
557
- $ answers = $ this ->getAnswers ( $ this -> getID () );
558
- $ answers ['plugin_formcreator_forms_id ' ] = $ form ->getID ();
559
- $ visibility = PluginFormcreatorFields::updateVisibility ($ answers );
560
+ $ this ->loadAnswers ( );
561
+ $ this -> answers ['plugin_formcreator_forms_id ' ] = $ form ->getID ();
562
+ $ visibility = PluginFormcreatorFields::updateVisibility ($ this -> answers );
560
563
561
564
$ sections = (new PluginFormcreatorSection )->getSectionsFromForm ($ form ->getID ());
562
565
foreach ($ sections as $ section ) {
@@ -596,7 +599,7 @@ public function showForm($ID, $options = []) {
596
599
}
597
600
}
598
601
}
599
- echo $ question ->getRenderedHtml ($ domain , $ editMode , $ answers , $ visibility [$ question ->getType ()][$ question ->getID ()]);
602
+ echo $ question ->getRenderedHtml ($ domain , $ editMode , $ this , $ visibility [$ question ->getType ()][$ question ->getID ()]);
600
603
$ lastQuestion = $ question ;
601
604
}
602
605
echo '</div> ' ;
@@ -878,24 +881,32 @@ public function generateTarget(): bool {
878
881
/**
879
882
* Gets answers of all fields of a form answer
880
883
*
881
- * @param int $formAnswerId
882
- * @return array
884
+ * @return void
883
885
*/
884
- public function getAnswers ( $ formAnswerId ): array {
886
+ public function loadAnswers ( ): void {
885
887
global $ DB ;
886
888
889
+ $ this ->answers = [];
890
+ if ($ this ->isNewItem ()) {
891
+ return ;
892
+ }
893
+
887
894
$ answers = $ DB ->request ([
888
895
'SELECT ' => ['plugin_formcreator_questions_id ' , 'answer ' ],
889
896
'FROM ' => PluginFormcreatorAnswer::getTable (),
890
897
'WHERE ' => [
891
- 'plugin_formcreator_formanswers_id ' => $ formAnswerId
898
+ 'plugin_formcreator_formanswers_id ' => $ this -> getID ()
892
899
]
893
900
]);
894
901
$ answers_values = [];
895
902
foreach ($ answers as $ found_answer ) {
896
903
$ answers_values ['formcreator_field_ ' . $ found_answer ['plugin_formcreator_questions_id ' ]] = $ found_answer ['answer ' ];
897
904
}
898
- return $ answers_values ;
905
+ $ this ->answers = $ answers_values ;
906
+ }
907
+
908
+ public function getAnswers () {
909
+ return $ this ->answers ;
899
910
}
900
911
901
912
/**
@@ -1650,7 +1661,8 @@ public function deserializeAnswers() : bool {
1650
1661
return false ;
1651
1662
}
1652
1663
1653
- $ answers_values = $ this ->getAnswers ($ this ->getID ());
1664
+ $ this ->loadAnswers ();
1665
+ $ answers_values = $ this ->getAnswers ();
1654
1666
foreach (array_keys ($ this ->questionFields ) as $ id ) {
1655
1667
if (!$ this ->questionFields [$ id ]->hasInput ($ answers_values )) {
1656
1668
continue ;
0 commit comments