本文整理匯總了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;
}
}