本文整理汇总了PHP中CMap::addElements方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::addElements方法的具体用法?PHP CMap::addElements怎么用?PHP CMap::addElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::addElements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseMap
//.........这里部分代码省略.........
if (isset($selement[$icon])) {
$image = getImageByIdent($selement[$icon]);
if (!$image) {
$error = S_CANNOT_FIND_IMAGE . ' "' . $selement[$icon]['name'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"';
throw new Exception($error);
}
$selement[$icon] = $image['imageid'];
} else {
$selement[$icon] = 0;
}
}
}
unset($selement);
foreach ($sysmap['links'] as $lnum => &$link) {
if (!isset($link['linktriggers'])) {
continue;
}
foreach ($link['linktriggers'] as $ltnum => &$linktrigger) {
$nodeCaption = isset($linktrigger['triggerid']['node']) ? $linktrigger['triggerid']['node'] . ':' : '';
$db_triggers = CTrigger::getObjects($linktrigger['triggerid']);
if (empty($db_triggers)) {
$error = S_CANNOT_FIND_TRIGGER . ' "' . $nodeCaption . $linktrigger['triggerid']['host'] . ':' . $linktrigger['triggerid']['description'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"';
throw new Exception($error);
}
$tmp = reset($db_triggers);
$linktrigger['triggerid'] = $tmp['triggerid'];
}
unset($linktrigger);
}
unset($link);
$sysmaps[] = $sysmap;
}
unset($sysmap);
$importMaps = $sysmaps;
foreach ($importMaps as $mnum => $importMap) {
$sysmap = $importMap;
if (isset($importMap['sysmapid'])) {
$result = CMap::update($importMap);
$sysmapids = $result['sysmapids'];
// Deleteing all selements (with links)
$db_selementids = array();
$res = DBselect('SELECT selementid FROM sysmaps_elements WHERE sysmapid=' . $sysmap['sysmapid']);
while ($db_selement = DBfetch($res)) {
$db_selementids[$db_selement['selementid']] = $db_selement['selementid'];
}
delete_sysmaps_element($db_selementids);
//----
} else {
// first we must create an empty map without any elements (they will be added below)
$mapToCreate = $importMap;
$mapToCreate['selements'] = array();
$mapToCreate['links'] = array();
$result = CMap::create($mapToCreate);
$sysmapids = $result['sysmapids'];
$sysmap['sysmapid'] = reset($sysmapids);
}
// adding elements and links
$selements = $importMap['selements'];
$links = $importMap['links'];
foreach ($selements as $id => $selement) {
if (!isset($selement['elementid']) || $selement['elementid'] == 0) {
$selement['elementid'] = 0;
$selement['elementtype'] = SYSMAP_ELEMENT_TYPE_IMAGE;
}
if (!isset($selement['iconid_off']) || $selement['iconid_off'] == 0) {
throw new Exception(S_NO_ICON_FOR_MAP_ELEMENT . ' ' . $sysmap['name'] . ':' . $selement['label']);
}
$selement['sysmapid'] = $sysmap['sysmapid'];
$selementids = CMap::addElements($selement);
$selementid = reset($selementids);
foreach ($links as $id => &$link) {
if ($link['selementid1'] == $selement['selementid']) {
$links[$id]['selementid1'] = $selementid;
} else {
if ($link['selementid2'] == $selement['selementid']) {
$links[$id]['selementid2'] = $selementid;
}
}
}
unset($link);
}
foreach ($links as $id => $link) {
if (!isset($link['linktriggers'])) {
$link['linktriggers'] = array();
}
$link['sysmapid'] = $sysmap['sysmapid'];
$result = CMap::addLinks($link);
}
if (isset($importMap['sysmapid'])) {
info(S_MAP . ' [' . $sysmap['name'] . '] ' . S_UPDATED_SMALL);
} else {
info(S_MAP . ' [' . $sysmap['name'] . '] ' . S_ADDED_SMALL);
}
}
return true;
} catch (Exception $e) {
error($e->getMessage());
return false;
}
}
示例2: array
$db_selementids = array();
$res = DBselect('SELECT selementid FROM sysmaps_elements WHERE sysmapid=' . $sysmapid);
while ($db_selement = DBfetch($res)) {
$db_selementids[$db_selement['selementid']] = $db_selement['selementid'];
}
$transaction = DBstart();
foreach ($selements as $id => $selement) {
if ($selement['elementid'] == 0) {
$selement['elementtype'] = SYSMAP_ELEMENT_TYPE_IMAGE;
}
if ($selement['iconid_off'] == 0) {
throw new Exception('Cannot save map. Map element "' . $selement['label'] . '" contains no icon.');
}
if (isset($selement['new'])) {
$selement['sysmapid'] = $sysmapid;
$selementids = CMap::addElements($selement);
$selementid = reset($selementids);
foreach ($links as $id => $link) {
if ($link['selementid1'] == $selement['selementid']) {
$links[$id]['selementid1'] = $selementid;
} else {
if ($link['selementid2'] == $selement['selementid']) {
$links[$id]['selementid2'] = $selementid;
}
}
}
} else {
//SDII($selement);
$selement['sysmapid'] = $sysmapid;
$result = CMap::updateElements($selement);
unset($db_selementids[$selement['selementid']]);