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

Commit

Permalink
fix(hostgroup): fix display of hostgroups in select2 (#11431) (#11443)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjaouen authored Jul 29, 2022
1 parent 598c001 commit 7737c37
Showing 1 changed file with 13 additions and 9 deletions.
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

0 comments on commit 7737c37

Please sign in to comment.