當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CTemplate::massAdd方法代碼示例

本文整理匯總了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;
     }
 }
開發者ID:songyuanjie,項目名稱:zabbix-stats,代碼行數:52,代碼來源:class.chost.php


注:本文中的CTemplate::massAdd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。