本文整理汇总了PHP中CTemplate::massAdd方法的典型用法代码示例。如果您正苦于以下问题:PHP CTemplate::massAdd方法的具体用法?PHP CTemplate::massAdd怎么用?PHP CTemplate::massAdd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTemplate
的用法示例。
在下文中一共展示了CTemplate::massAdd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: massAdd
/**
* Add Hosts to HostGroups. All Hosts are added to all HostGroups.
*
* @param array $data
* @param array $data['groups']
* @param array $data['templates']
* @param array $data['macros']
* @return array
*/
public static function massAdd($data)
{
$data['hosts'] = zbx_toArray($data['hosts']);
try {
self::BeginTransaction(__METHOD__);
$options = array('hostids' => zbx_objectValues($data['hosts'], 'hostid'), 'editable' => 1, 'preservekeys' => 1);
$upd_hosts = self::get($options);
foreach ($data['hosts'] as $hnum => $host) {
if (!isset($upd_hosts[$host['hostid']])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, 'You do not have enough rights for operation');
}
}
if (isset($data['groups']) && !empty($data['groups'])) {
$options = array('groups' => zbx_toArray($data['groups']), 'hosts' => $data['hosts']);
$result = CHostGroup::massAdd($options);
if (!$result) {
self::exception();
}
}
if (isset($data['templates']) && !empty($data['templates'])) {
$options = array('hosts' => $data['hosts'], 'templates' => zbx_toArray($data['templates']));
$result = CTemplate::massAdd($options);
if (!$result) {
self::exception();
}
}
if (isset($data['macros']) && !empty($data['macros'])) {
$options = array('hosts' => $data['hosts'], 'macros' => $data['macros']);
$result = CUserMacro::massAdd($options);
if (!$result) {
self::exception();
}
}
self::EndTransaction(true, __METHOD__);
return array('hostids' => zbx_objectValues($data['hosts'], 'hostid'));
} catch (APIException $e) {
self::EndTransaction(false, __METHOD__);
$error = $e->getErrors();
$error = reset($error);
self::setError(__METHOD__, $e->getCode(), $error);
return false;
}
}