abstract class CMapElement extends CApiService {
protected function checkSelementInput(&$selements, $method) {
$create = ($method === 'createSelements');
$update = ($method === 'updateSelements');
$element_types = [SYSMAP_ELEMENT_TYPE_HOST, SYSMAP_ELEMENT_TYPE_MAP, SYSMAP_ELEMENT_TYPE_TRIGGER,
SYSMAP_ELEMENT_TYPE_HOST_GROUP, SYSMAP_ELEMENT_TYPE_IMAGE
$elementtype_validator = new CLimitedSetValidator(['values' => $element_types]);
$db_selements = $this->fetchSelementsByIds(zbx_objectValues($selements, 'selementid'));
$selements = $this->extendFromObjects(zbx_toHash($selements, 'selementid'), $db_selements, ['elementtype', 'elements']);
foreach ($selements as &$selement) {
if (!is_array($selement)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect arguments passed to function.'));
$missing_keys = array_diff(['sysmapid', 'elementtype', 'iconid_off'], array_keys($selement));
self::exception(ZBX_API_ERROR_PARAMETERS,
_s('Map element is missing parameters: %1$s', implode(', ', $missing_keys))
if (array_key_exists('label', $selement)
&& mb_strlen($selement['label']) > DB::getFieldLength('sysmaps_elements', 'label')) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value for field "%1$s": %2$s.',
'label', _('value is too long')
if (array_key_exists('urls', $selement)) {
$url_validate_options = ['allow_user_macro' => false];
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
$url_validate_options['allow_inventory_macro'] = INVENTORY_URL_MACRO_HOST;
elseif ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) {
$url_validate_options['allow_inventory_macro'] = INVENTORY_URL_MACRO_TRIGGER;
$url_validate_options['allow_inventory_macro'] = INVENTORY_URL_MACRO_NONE;
foreach ($selement['urls'] as &$url_data) {
if (!CHtmlUrlValidator::validate($url_data['url'], $url_validate_options)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Wrong value for "url" field.'));
unset($url_data['sysmapelementurlid'], $url_data['selementid']);
if (!$elementtype_validator->validate($selement['elementtype'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value for field "%1$s": %2$s.',
'elementtype', _s('value must be one of %1$s', implode(', ', $element_types))
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE) {
unset($selement['elements']);