本文整理汇总了PHP中API::ValueMap方法的典型用法代码示例。如果您正苦于以下问题:PHP API::ValueMap方法的具体用法?PHP API::ValueMap怎么用?PHP API::ValueMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::ValueMap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMappedValue
/**
* Get mapping for value.
*
* @param int|float|string $value Value that mapping should be applied to.
* @param string $valuemapid Value map ID which should be used.
*
* @return string|bool If there is no mapping return false, return mapped value otherwise.
*/
function getMappedValue($value, $valuemapid)
{
static $valuemaps = [];
if ($valuemapid == 0) {
return false;
}
if (!array_key_exists($valuemapid, $valuemaps)) {
$valuemaps[$valuemapid] = [];
$db_valuemaps = API::ValueMap()->get(['output' => [], 'selectMappings' => ['value', 'newvalue'], 'valuemapids' => [$valuemapid]]);
if ($db_valuemaps) {
foreach ($db_valuemaps[0]['mappings'] as $mapping) {
$valuemaps[$valuemapid][$mapping['value']] = $mapping['newvalue'];
}
}
}
return array_key_exists((string) $value, $valuemaps[$valuemapid]) ? $valuemaps[$valuemapid][(string) $value] : false;
}
示例2: zbx_objectValues
$items = API::Item()->get(['itemids' => zbx_objectValues($data['hosts']['items'], 'itemid'), 'output' => ['itemid', 'type']]);
$usedInterfacesTypes = [];
foreach ($items as $item) {
$usedInterfacesTypes[$item['type']] = itemTypeInterface($item['type']);
}
$initialItemType = min(array_keys($usedInterfacesTypes));
$data['type'] = getRequest('type') !== null ? $data['type'] : $initialItemType;
$data['initial_item_type'] = $initialItemType;
$data['multiple_interface_types'] = count(array_unique($usedInterfacesTypes)) > 1;
}
}
// item types
$data['itemTypes'] = item_type2str();
unset($data['itemTypes'][ITEM_TYPE_HTTPTEST]);
// valuemap
$data['valuemaps'] = API::ValueMap()->get(['output' => ['valuemapid', 'name']]);
CArrayHelper::sort($data['valuemaps'], ['name']);
if (!$data['delay_flex']) {
$data['delay_flex'][] = ['delay' => '', 'period' => '', 'type' => ITEM_DELAY_FLEX_TYPE_FLEXIBLE];
}
// render view
$itemView = new CView('configuration.item.massupdate', $data);
$itemView->render();
$itemView->show();
} elseif (hasRequest('action') && getRequest('action') == 'item.masscopyto' && hasRequest('group_itemid')) {
// render view
$data = getCopyElementsFormData('group_itemid', _('Items'));
$data['action'] = 'item.masscopyto';
$graphView = new CView('configuration.copy.elements', $data);
$graphView->render();
$graphView->show();
示例3: gatherValueMaps
/**
* Get value maps for export builder from database.
*
* @param array $valuemapids
*
* return array
*/
protected function gatherValueMaps(array $valuemapids)
{
$this->data['valueMaps'] = API::ValueMap()->get(['output' => ['valuemapid', 'name'], 'selectMappings' => ['value', 'newvalue'], 'valuemapids' => $valuemapids, 'preservekeys' => true]);
}
示例4: getItemFormData
//.........这里部分代码省略.........
$data['password'] = $data['item']['password'];
$data['publickey'] = $data['item']['publickey'];
$data['privatekey'] = $data['item']['privatekey'];
$data['logtimefmt'] = $data['item']['logtimefmt'];
$data['new_application'] = getRequest('new_application', '');
if ($data['parent_discoveryid'] != 0) {
$data['new_application_prototype'] = getRequest('new_application_prototype', '');
}
if (!$data['is_discovery_rule']) {
$data['formula'] = $data['item']['formula'];
}
if (!$data['limited'] || !isset($_REQUEST['form_refresh'])) {
$data['delay'] = $data['item']['delay'];
if (($data['type'] == ITEM_TYPE_TRAPPER || $data['type'] == ITEM_TYPE_SNMPTRAP) && $data['delay'] == 0) {
$data['delay'] = ZBX_ITEM_DELAY_DEFAULT;
}
$data['history'] = $data['item']['history'];
$data['status'] = $data['item']['status'];
$data['delta'] = $data['item']['delta'];
$data['trends'] = $data['item']['trends'];
$parser = new CItemDelayFlexParser($data['item']['delay_flex']);
if ($parser->isValid()) {
foreach ($parser->getIntervals() as $interval) {
if ($interval['type'] == ITEM_DELAY_FLEX_TYPE_FLEXIBLE) {
$interval_parts = explode('/', $interval['interval']);
$data['delay_flex'][] = ['delay' => $interval_parts[0], 'period' => $interval_parts[1], 'type' => ITEM_DELAY_FLEX_TYPE_FLEXIBLE];
} else {
$data['delay_flex'][] = ['schedule' => $interval['interval'], 'type' => ITEM_DELAY_FLEX_TYPE_SCHEDULING];
}
}
}
$data['applications'] = array_unique(zbx_array_merge($data['applications'], get_applications_by_itemid($data['itemid'])));
if ($data['parent_discoveryid'] != 0) {
/*
* Get a list of application prototypes assigned to item prototype. Don't select distinct names,
* since database can be accidentally created case insensitive.
*/
$application_prototypes = DBfetchArray(DBselect('SELECT ap.name' . ' FROM application_prototype ap,item_application_prototype iap' . ' WHERE ap.application_prototypeid=iap.application_prototypeid' . ' AND ap.itemid=' . zbx_dbstr($data['parent_discoveryid']) . ' AND iap.itemid=' . zbx_dbstr($data['itemid'])));
// Merge form submitted data with data existing in DB to find diff and correctly display ListBox.
$data['application_prototypes'] = array_unique(zbx_array_merge($data['application_prototypes'], zbx_objectValues($application_prototypes, 'name')));
}
}
}
if (!$data['delay_flex']) {
$data['delay_flex'][] = ['delay' => '', 'period' => '', 'type' => ITEM_DELAY_FLEX_TYPE_FLEXIBLE];
}
// applications
if (count($data['applications']) == 0) {
array_push($data['applications'], 0);
}
$data['db_applications'] = DBfetchArray(DBselect('SELECT DISTINCT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . zbx_dbstr($data['hostid']) . ($data['parent_discoveryid'] ? ' AND a.flags=' . ZBX_FLAG_DISCOVERY_NORMAL : '')));
order_result($data['db_applications'], 'name');
if ($data['parent_discoveryid'] != 0) {
// Make the application prototype list no appearing empty, but filling it with "-None-" as first element.
if (count($data['application_prototypes']) == 0) {
$data['application_prototypes'][] = 0;
}
// Get a list of application prototypes by discovery rule.
$data['db_application_prototypes'] = DBfetchArray(DBselect('SELECT ap.application_prototypeid,ap.name' . ' FROM application_prototype ap' . ' WHERE ap.itemid=' . zbx_dbstr($data['parent_discoveryid'])));
order_result($data['db_application_prototypes'], 'name');
}
// interfaces
$data['interfaces'] = API::HostInterface()->get(['hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND]);
// valuemapid
if ($data['limited']) {
if ($data['valuemapid'] != 0) {
$valuemaps = API::ValueMap()->get(['output' => ['name'], 'valuemapids' => [$data['valuemapid']]]);
if ($valuemaps) {
$data['valuemaps'] = $valuemaps[0]['name'];
}
}
} else {
$data['valuemaps'] = API::ValueMap()->get(['output' => ['valemapid', 'name']]);
CArrayHelper::sort($data['valuemaps'], ['name']);
}
// possible host inventories
if (empty($data['parent_discoveryid'])) {
$data['possibleHostInventories'] = getHostInventories();
// get already populated fields by other items
$data['alreadyPopulated'] = API::item()->get(['output' => ['inventory_link'], 'filter' => ['hostid' => $data['hostid']], 'nopermissions' => true]);
$data['alreadyPopulated'] = zbx_toHash($data['alreadyPopulated'], 'inventory_link');
}
// unset snmpv3 fields
if ($data['type'] != ITEM_TYPE_SNMPV3) {
$data['snmpv3_contextname'] = '';
$data['snmpv3_securityname'] = '';
$data['snmpv3_securitylevel'] = ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV;
$data['snmpv3_authprotocol'] = ITEM_AUTHPROTOCOL_MD5;
$data['snmpv3_authpassphrase'] = '';
$data['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES;
$data['snmpv3_privpassphrase'] = '';
}
// unset ssh auth fields
if ($data['type'] != ITEM_TYPE_SSH) {
$data['authtype'] = ITEM_AUTHTYPE_PASSWORD;
$data['publickey'] = '';
$data['privatekey'] = '';
}
return $data;
}
示例5: selectValueMaps
/**
* Select value map IDs for previously added value map names.
*/
protected function selectValueMaps()
{
if ($this->valueMaps) {
$this->valueMapsRefs = [];
$valuemaps = API::ValueMap()->get(['output' => ['valeumapid', 'name'], 'filter' => ['name' => $this->valueMaps]]);
foreach ($valuemaps as $valuemap) {
$this->valueMapsRefs[$valuemap['name']] = $valuemap['valuemapid'];
}
$this->valueMaps = [];
}
}
示例6: processValueMaps
/**
* Import value maps.
*/
protected function processValueMaps()
{
if (!$this->options['valueMaps']['createMissing'] && !$this->options['valueMaps']['updateExisting']) {
return;
}
$all_valuemaps = $this->getFormattedValueMaps();
if (!$all_valuemaps) {
return;
}
$valuemaps_to_create = [];
$valuemaps_to_update = [];
foreach ($all_valuemaps as $valuemap) {
$valuemapid = $this->referencer->resolveValueMap($valuemap['name']);
if ($valuemapid) {
$valuemap['valuemapid'] = $valuemapid;
$valuemaps_to_update[] = $valuemap;
} else {
$valuemaps_to_create[] = $valuemap;
}
}
if ($this->options['valueMaps']['createMissing'] && $valuemaps_to_create) {
$valuemapids = API::ValueMap()->create($valuemaps_to_create);
foreach ($valuemaps_to_create as $key => $valuemap) {
$this->referencer->addValueMapRef($valuemap['name'], $valuemapids['valuemapids'][$key]);
}
}
if ($this->options['valueMaps']['updateExisting'] && $valuemaps_to_update) {
API::ValueMap()->update($valuemaps_to_update);
}
}
示例7: getRequest
} else {
$data['name'] = getRequest('name', '');
$data['mappings'] = getRequest('mappings', []);
}
if ($data['valuemapid'] != 0) {
$data['valuemap_count'] += API::Item()->get(['countOutput' => true, 'webitems' => true, 'filter' => ['valuemapid' => $data['valuemapid']]]);
$data['valuemap_count'] += API::ItemPrototype()->get(['countOutput' => true, 'filter' => ['valuemapid' => $data['valuemapid']]]);
}
if (!$data['mappings']) {
$data['mappings'][] = ['value' => '', 'newvalue' => ''];
}
$view = new CView('administration.general.valuemapping.edit', $data);
} else {
$sortfield = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
$sortorder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
CProfile::update('web.' . $page['file'] . '.sort', $sortfield, PROFILE_TYPE_STR);
CProfile::update('web.' . $page['file'] . '.sortorder', $sortorder, PROFILE_TYPE_STR);
$data = ['sort' => $sortfield, 'sortorder' => $sortorder];
$data['valuemaps'] = API::ValueMap()->get(['output' => ['valuemapid', 'name'], 'selectMappings' => ['value', 'newvalue'], 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1]);
order_result($data['valuemaps'], $sortfield, $sortorder);
$data['paging'] = getPagingLine($data['valuemaps'], $sortorder, new CUrl('adm.valuemapping.php'));
foreach ($data['valuemaps'] as &$valuemap) {
order_result($valuemap['mappings'], 'value');
$valuemap['used_in_items'] = (bool) API::Item()->get(['output' => [], 'webitems' => true, 'filter' => ['valuemapid' => $valuemap['valuemapid']], 'limit' => 1]) || (bool) API::ItemPrototype()->get(['output' => [], 'filter' => ['valuemapid' => $valuemap['valuemapid']], 'limit' => 1]);
}
unset($valuemap);
$view = new CView('administration.general.valuemapping.list', $data);
}
$view->render();
$view->show();
require_once dirname(__FILE__) . '/include/page_footer.php';