Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(hostgroup): fix display of hostgroups in select2 (#11431) #11443

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions www/class/centreonHostgroups.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ public function getObjectForSelect2($values = array(), $options = array())
return $items;
}

$hostgroups = [];
// $values structure: ['1,2,3,4'], keeping the foreach in case it could have more than one index
foreach ($values as $value) {
$hostgroups = array_merge($hostgroups, explode(',', $value));
}

// get list of authorized hostgroups
if (!$centreon->user->access->admin) {
$hgAcl = $centreon->user->access->getHostGroupAclConf(
Expand All @@ -347,7 +353,7 @@ public function getObjectForSelect2($values = array(), $options = array())
'conditions' => array(
'hostgroup.hg_id' => array(
'IN',
$values
$hostgroups
)
)
),
Expand All @@ -359,15 +365,13 @@ public function getObjectForSelect2($values = array(), $options = array())
$listValues = '';
$queryValues = array();

foreach ($values as $k => $v) {
//As it happens that $v could be like "X,Y" when two hostgroups are selected, we added a second foreach
$multiValues = explode(',', $v);
foreach ($multiValues as $item) {
$ids = explode('-', $item);
$listValues .= ':hgId_' . $ids[0] . ', ';
$queryValues['hgId_' . $ids[0]] = (int)$ids[0];
}
foreach ($hostgroups as $item) {
// the below explode may not be useful
$ids = explode('-', $item);
$listValues .= ':hgId_' . $ids[0] . ', ';
$queryValues['hgId_' . $ids[0]] = (int)$ids[0];
}

$listValues = rtrim($listValues, ', ');
$query = 'SELECT hg_id, hg_name FROM hostgroup WHERE hg_id IN (' . $listValues . ') ORDER BY hg_name ';
$stmt = $this->DB->prepare($query);
Expand Down