/** * Get icon id by mapping. * * @param array $iconMap * @param array $inventory * * @return int */ function getIconByMapping($iconMap, $inventory) { if (!empty($inventory['inventory'])) { $inventories = getHostInventories(); foreach ($iconMap['mappings'] as $mapping) { try { $expr = new GlobalRegExp($mapping['expression']); if ($expr->match($inventory['inventory'][$inventories[$mapping['inventory_link']]['db_field']])) { return $mapping['iconid']; } } catch (Exception $e) { continue; } } } return $iconMap['default_iconid']; }
/** * @param array $iconMap * @param array $inventory * * @return int icon id */ function getIconByMapping($iconMap, $inventory) { $iconid = null; $inventories = getHostInventories(); if (isset($inventory['inventory'])) { foreach ($iconMap['mappings'] as $mapping) { try { $expr = new GlobalRegExp($mapping['expression']); if ($expr->match($inventory['inventory'][$inventories[$mapping['inventory_link']]['db_field']])) { $iconid = $mapping['iconid']; break; } } catch (Exception $e) { continue; } } } if (null === $iconid) { $iconid = $iconMap['default_iconid']; } return $iconid; }