Skip to content

Commit

Permalink
fix(condition): compatibility with Advanced forms validation
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jul 25, 2022
1 parent 955dc96 commit 6685b94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
53 changes: 23 additions & 30 deletions inc/condition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,38 +310,31 @@ public static function getQuestionsExclusion(?PluginFormcreatorConditionnableInt
}

/** @var CommonDBTM $item */
$itemtype = $item->getType();
switch ($itemtype) {
case PluginFormcreatorForm::class:
return [];
break;

case PluginFormcreatorSection::class:
if ($item->isNewItem()) {
$formFk = PluginFormcreatorForm::getForeignKeyField();
$sections = (new PluginFormcreatorSection())->getSectionsFromForm($item->fields[$formFk]);
$sectionsList = [];
foreach ($sections as $section) {
$sectionsList[] = $section->getID();
}
$questionListExclusion = [];
if (count($sectionsList) > 0) {
$questionListExclusion[] = [
PluginFormcreatorSection::getForeignKeyField() => $sectionsList,
];
}
return $questionListExclusion;
if ($item instanceof PluginFormcreatorForm) {
return [];
} else if ($item instanceof PluginFormcreatorSection) {
if ($item->isNewItem()) {
$formFk = PluginFormcreatorForm::getForeignKeyField();
$sections = (new PluginFormcreatorSection())->getSectionsFromForm($item->fields[$formFk]);
$sectionsList = [];
foreach ($sections as $section) {
$sectionsList[] = $section->getID();
}
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
return [PluginFormcreatorQuestion::getTable() . '.' . $sectionFk => ['<>', $item->getID()]];
break;

case PluginFormcreatorQuestion::class:
if (!$item->isNewItem()) {
return [PluginFormcreatorQuestion::getTable() . '.id' => ['<>', $item->getID()]];
$questionListExclusion = [];
if (count($sectionsList) > 0) {
$questionListExclusion[] = [
PluginFormcreatorSection::getForeignKeyField() => $sectionsList,
];
}
return [];
break;
return $questionListExclusion;
}
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
return [PluginFormcreatorQuestion::getTable() . '.' . $sectionFk => ['<>', $item->getID()]];
} else if ($item instanceof PluginFormcreatorQuestion) {
if (!$item->isNewItem()) {
return [PluginFormcreatorQuestion::getTable() . '.id' => ['<>', $item->getID()]];
}
return [];
}
if (in_array($item::getType(), PluginFormcreatorForm::getTargetTypes())) {
// No question exclusion for targets
Expand Down
2 changes: 1 addition & 1 deletion inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ public function isPublicAccess() : bool {
public static function getByItem(?CommonDBTM $item): ?self {
global $DB;

if ($item::getType() == self::getType()) {
if ($item instanceof self) {
return $item;
}

Expand Down

0 comments on commit 6685b94

Please sign in to comment.