From 41320baf021a5324d29697903b19e65b50e9635b Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 26 Mar 2021 13:19:30 +0100 Subject: [PATCH] fix(form_validator): manage deletion of all items for a level Signed-off-by: Thierry Bugier --- inc/form_validator.class.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/inc/form_validator.class.php b/inc/form_validator.class.php index f2ea2dcb7..fb4063f6a 100644 --- a/inc/form_validator.class.php +++ b/inc/form_validator.class.php @@ -255,6 +255,39 @@ class='submit'>"; Html::closeForm(); } + public function post_deleteItem() { + $formFk = PluginFormcreatorForm::getForeignKeyField(); + $rows = $this->find( + [ + $formFk => $this->fields[$formFk], + ], [ + 'level ASC' + ] + ); + + // count items with the same level as the deleted item + $currentLevelCount = 0; + foreach ($rows as $row) { + if ($row['level'] == $this->fields['level']) { + $currentLevelCount++; + } + } + + if ($currentLevelCount < 1) { + // No more items for this level. Moving decreasing level of above levels + foreach ($rows as $row) { + if ($row['level'] < $this->fields['level']) { + continue; + } + $toUpdate = new self(); + $toUpdate->update([ + 'id' => $row['id'], + 'level' => $row['level'] - 1, + ]); + } + } + } + public static function import(PluginFormcreatorLinker $linker, $input = [], $forms_id = 0) { $formFk = PluginFormcreatorForm::getForeignKeyField(); $input[$formFk] = $forms_id;