Skip to content

Commit

Permalink
fix(glpiselectfield): tree settings of entity question
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Oct 15, 2021
1 parent 88d9d34 commit 48053f5
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,32 +318,33 @@ public function buildParams($rand = null) {
}
}

// Set specific root if defined (CommonTreeDropdown)
$baseLevel = 0;
if (isset($decodedValues['show_tree_root'])
&& (int) $decodedValues['show_tree_root'] > 0
) {
$sons = (new DBUtils)->getSonsOf(
$itemtype::getTable(),
$decodedValues['show_tree_root']
);
if (!isset($decodedValues['selectable_tree_root']) || $decodedValues['selectable_tree_root'] == '0') {
unset($sons[$decodedValues['show_tree_root']]);
}
if (is_subclass_of($itemtype, CommonTreeDropdown::class)) {
// Set specific root if defined (CommonTreeDropdown)
$baseLevel = 0;
if (isset($decodedValues['show_tree_root'])
&& (int) $decodedValues['show_tree_root'] > -1
) {
$sons = (new DBUtils)->getSonsOf(
$itemtype::getTable(),
$decodedValues['show_tree_root']
);
if (!isset($decodedValues['selectable_tree_root']) || $decodedValues['selectable_tree_root'] == '0') {
unset($sons[$decodedValues['show_tree_root']]);
}

$dparams_cond_crit[$itemtype::getTable() . '.id'] = $sons;
$rootItem = new $itemtype();
if ($rootItem->getFromDB($decodedValues['show_tree_root'])) {
$baseLevel = $rootItem->fields['level'];
$dparams_cond_crit[$itemtype::getTable() . '.id'] = $sons;
$rootItem = new $itemtype();
if ($rootItem->getFromDB($decodedValues['show_tree_root'])) {
$baseLevel = $rootItem->fields['level'];
}
}

}

// Apply max depth if defined (CommonTreeDropdown)
if (isset($decodedValues['show_tree_depth'])
&& $decodedValues['show_tree_depth'] > 0
) {
$dparams_cond_crit['level'] = ['<=', $decodedValues['show_tree_depth'] + $baseLevel];
// Apply max depth if defined (CommonTreeDropdown)
if (isset($decodedValues['show_tree_depth'])
&& $decodedValues['show_tree_depth'] > 0
) {
$dparams_cond_crit['level'] = ['<=', $decodedValues['show_tree_depth'] + $baseLevel];
}
}

$dparams['condition'] = $dparams_cond_crit;
Expand Down

0 comments on commit 48053f5

Please sign in to comment.