Skip to content

Commit

Permalink
fix(form_validator): manage deletion of all items for a level
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Apr 1, 2021
1 parent a5a6a6c commit 41320ba
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions inc/form_validator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 41320ba

Please sign in to comment.