@@ -190,10 +190,10 @@ public function export($remove_uuid = false) {
190190 /**
191191 * get conditions applied to an item
192192 *
193- * @param PluginFormcreatorConditionnableInterface $item
193+ * @param CommonDBTM $item
194194 * @return array array of PluginFotrmcreatorCondition
195195 */
196- public function getConditionsFromItem (PluginFormcreatorConditionnableInterface $ item ) {
196+ public function getConditionsFromItem (CommonDBTM $ item ) {
197197 global $ DB ;
198198
199199 if ($ item ->isNewItem ()) {
@@ -222,69 +222,65 @@ public function getConditionsFromItem(PluginFormcreatorConditionnableInterface $
222222 /**
223223 * Display HTML for conditions applied on an item
224224 *
225- * @param PluginFormcreatorForm $form form of the item
226- * @param PluginFormcreatorConditionnableInterface $item item where conditions applies to
225+ * @param CommonDBTM $item item where conditions applies to
227226 * @return void
228227 */
229- public function showConditionsForItem (PluginFormcreatorConditionnableInterface $ item ) {
228+ public function showConditionsForItem (CommonDBTM $ item ) {
230229 $ rand = mt_rand ();
231230
232- echo '<tr" > ' ;
231+ echo '<tr> ' ;
233232 echo '<td colspan="4"> ' ;
234233 Dropdown::showFromArray (
235- 'show_rule ' ,
234+ 'show_rule ' ,
236235 $ this ->getEnumShowRule (),
237236 [
238237 'value ' => $ item ->fields ['show_rule ' ],
239- 'on_change ' => 'plugin_formcreator_toggleCondition(this); ' ,
238+ 'on_change ' => 'plugin_formcreator_toggleCondition(this, " ' . $ item -> getType () . ' " ); ' ,
240239 'rand ' => $ rand ,
241240 ]
242241 );
243242 echo '</td> ' ;
244243 echo '</tr> ' ;
245244
246- // Get conditionsexisting conditions for the item
245+ // Get existing conditions for the item
247246 $ conditions = $ this ->getConditionsFromItem ($ item );
248- reset ($ conditions );
249- $ condition = array_shift ($ conditions );
250- if ($ condition !== null ) {
251- echo $ condition ->getConditionHtml ($ item , true );
252- }
253247 foreach ($ conditions as $ condition ) {
254- echo $ condition ->getConditionHtml ($ item );
248+ echo $ condition ->getConditionHtml ($ item-> fields );
255249 }
256250 }
257251
258252 /**
259253 * return HTML to show a condition line for a question
260254 *
261- * @param PluginFormcreatorConditionnableInterface $item ID of the question (or 0 for a new question)
262- * @param boolean $isFirst true if this is the first condition in all conditions applied to a question
255+ * @param array $input
263256 *
264257 * @return string HTML to insert in a rendered web page
265258 */
266- public function getConditionHtml (PluginFormcreatorConditionnableInterface $ item , $ isFirst = false ) {
267- $ itemtype = $ item ->getType ();
268- $ itemId = $ item ->getID ();
259+ public function getConditionHtml ($ input ) {
269260 if ($ this ->isNewItem ()) {
270- $ questionId = '' ;
271- $ show_condition = static ::SHOW_CONDITION_EQ ;
272- $ show_value = '' ;
273- $ show_logic = '' ;
261+ $ this ->getEmpty ();
262+ $ itemtype = $ input ['itemtype ' ];
263+ $ itemId = $ input ['items_id ' ];
264+ $ questionId = '' ;
265+ $ show_condition = self ::SHOW_CONDITION_EQ ;
266+ $ show_value = '' ;
267+ $ show_logic = '' ;
274268 } else {
275- $ questionId = $ this ->fields ['plugin_formcreator_questions_id ' ];
276- $ show_condition = $ this ->fields ['show_condition ' ];
277- $ show_value = $ this ->fields ['show_value ' ];
278- $ show_logic = $ this ->fields ['show_logic ' ];
269+ $ itemtype = $ this ->fields ['itemtype ' ];
270+ $ itemId = $ this ->fields ['items_id ' ];
271+ $ questionId = $ this ->fields ['plugin_formcreator_questions_id ' ];
272+ $ show_condition = $ this ->fields ['show_condition ' ];
273+ $ show_value = $ this ->fields ['show_value ' ];
274+ $ show_logic = $ this ->fields ['show_logic ' ];
279275 }
280- $ rand = mt_rand ();
276+ $ item = new $ itemtype ();
281277
282278 // Get list of question in the form of the item
283- $ itemtype = $ item ->getType ();
284279 if (!is_subclass_of ($ item , PluginFormcreatorConditionnableInterface::class)) {
285280 throw new Exception ("$ itemtype is not a " . PluginFormcreatorConditionnableInterface::class);
286281 }
287282
283+ $ rand = mt_rand ();
288284 $ html = '' ;
289285 $ html .= '<tr '
290286 . ' data-itemtype=" ' . self ::class . '" '
@@ -294,10 +290,9 @@ public function getConditionHtml(PluginFormcreatorConditionnableInterface $item,
294290 $ html .= '<div class="div_show_condition"> ' ;
295291
296292 // Boolean operator
297- $ showLogic = $ isFirst ? 'style="display: none" ' : '' ;
298- $ html .= '<div class="div_show_condition_logic" ' . $ showLogic . '> ' ;
299- $ html .= Dropdown::showFromArray ('show_logic[] ' ,
300- static ::getEnumShowLogic (),
293+ $ html .= '<div class="div_show_condition_logic"> ' ;
294+ $ html .= Dropdown::showFromArray ('_conditions[show_logic][] ' ,
295+ self ::getEnumShowLogic (),
301296 [
302297 'display ' => false ,
303298 'value ' => $ show_logic ,
@@ -310,30 +305,45 @@ public function getConditionHtml(PluginFormcreatorConditionnableInterface $item,
310305 $ form = new PluginFormcreatorForm ();
311306 $ questionListExclusion = [];
312307 switch ($ itemtype ) {
313- case PluginFormcreatorQuestion::class:
314- $ questionListExclusion = [PluginFormcreatorQuestion::getTable () . '.id ' => ['<> ' , $ itemId ]];
315- $ form ->getFromDBByQuestion ($ item );
308+ case PluginFormcreatorForm::class:
309+ $ form ->getFromDB ($ itemId );
316310 break ;
311+
317312 case PluginFormcreatorSection::class:
318313 $ sectionFk = PluginFormcreatorSection::getForeignKeyField ();
319314 $ questionListExclusion = [PluginFormcreatorQuestion::getTable () . '. ' . $ sectionFk => ['<> ' , $ itemId ]];
320- $ form ->getFromDBBySection ($ item );
321- break ;
322315 case PluginFormcreatorTargetTicket::class:
323316 case PluginFormcreatorTargetChange::class:
324- $ form ->getFromDBByTarget ($ item );
317+ $ form ->getFromDB ($ input ['plugin_formcreator_forms_id ' ]);
318+ break ;
319+
320+ case PluginFormcreatorQuestion::class:
321+ if ($ item ->isNewID ($ itemId )) {
322+ $ parentItemtype = $ item ::$ itemtype ;;
323+ $ section = new $ parentItemtype ();
324+ $ section ->getFromDB ($ input [$ parentItemtype ::getForeignKeyField ()]);
325+ $ form ->getFromDBBySection ($ section );
326+ } else {
327+ $ item ->getFromDB ($ itemId );
328+ $ form ->getFromDBByQuestion ($ item );
329+ $ questionListExclusion = [PluginFormcreatorQuestion::getTable () . '.id ' => ['<> ' , $ itemId ]];
330+ }
325331 break ;
332+
326333 default :
327334 throw new RuntimeException ("Unsupported conditionnable " );
335+
328336 }
329- $ questionsInForm = (new PluginFormcreatorQuestion )->getQuestionsFromFormBySection ($ form ->getID (), $ questionListExclusion );
337+ $ questionsInForm = (new PluginFormcreatorQuestion () )->getQuestionsFromFormBySection ($ form ->getID (), $ questionListExclusion );
330338 $ html .= '<div class="div_show_condition_field"> ' ;
331- $ html .= Dropdown::showFromArray ('plugin_formcreator_questions_id[] ' , $ questionsInForm , [
332- 'display ' => false ,
333- 'used ' => [$ itemId => '' ],
334- 'value ' => $ questionId ,
335- 'rand ' => $ rand ,
336- ]);
339+ $ html .= Dropdown::showFromArray (
340+ '_conditions[plugin_formcreator_questions_id][] ' ,
341+ $ questionsInForm , [
342+ 'display ' => false ,
343+ 'value ' => $ questionId ,
344+ 'rand ' => $ rand ,
345+ ]
346+ );
337347 $ html .= '</div> ' ;
338348
339349 // Equality / inequality operator
@@ -346,7 +356,7 @@ function ($item) {
346356 );
347357
348358 $ html .= Dropdown::showFromArray (
349- 'show_condition[] ' ,
359+ '_conditions[ show_condition] [] ' ,
350360 $ showConditions , [
351361 'display ' => false ,
352362 'value ' => $ show_condition ,
@@ -357,7 +367,7 @@ function ($item) {
357367
358368 // Value of comparison
359369 $ html .= '<div class="div_show_condition_value"> ' ;
360- $ html .= Html::input ('show_value[] ' , [
370+ $ html .= Html::input ('_conditions[ show_value] [] ' , [
361371 'class ' => 'small_text ' ,
362372 'size ' => '8 ' ,
363373 'value ' => $ show_value ,
0 commit comments