当前位置: 首页>>代码示例>>PHP>>正文


PHP Computer_Item::can方法代码示例

本文整理汇总了PHP中Computer_Item::can方法的典型用法代码示例。如果您正苦于以下问题:PHP Computer_Item::can方法的具体用法?PHP Computer_Item::can怎么用?PHP Computer_Item::can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Computer_Item的用法示例。


在下文中一共展示了Computer_Item::can方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: methodLinkObjects

 /**
  * Link inventory object to another one
  *
  * @param $params    the input parameters
  * @param $protocol  the commonication protocol used
  *
  **/
 static function methodLinkObjects($params, $protocol)
 {
     global $CFG_GLPI;
     if (isset($params['help'])) {
         return array('fields' => 'array, mandatory', 'help' => 'bool, optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     //Must be superadmin to use this method
     if (!Session::haveRight('config', UPDATE)) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
     }
     if (!isset($params['fields']) || empty($params['fields']) || !is_array($params['fields'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'fields');
     }
     if (!isset($_SESSION["glpi_currenttime"])) {
         $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     }
     $resp = array();
     $errors = array();
     foreach ($params['fields'] as $links) {
         if (!in_array($links['from_item']['itemtype'], array('Computer')) && !preg_match("/Device/", $links['from_item']['itemtype'])) {
             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
         }
         switch ($links['from_item']['itemtype']) {
             case 'Computer':
                 // Direct connections
                 if (in_array($links['to_item']['itemtype'], array('Monitor', 'Peripheral', 'Phone', 'Printer'))) {
                     $comp_item = new Computer_Item();
                     $data = array();
                     $data['items_id'] = $links['to_item']['id'];
                     $data['computers_id'] = $links['from_item']['id'];
                     $data['itemtype'] = $links['to_item']['itemtype'];
                     if (!$comp_item->can(-1, UPDATE, $data)) {
                         $errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
                     } else {
                         if ($comp_item->add($data)) {
                             $resp['Computer'][$data['computers_id']] = self::methodGetObject(array('itemtype' => 'Computer', 'id' => $data['computers_id'], 'with_printer' => 1, 'with_monitor' => 1, 'with_phone' => 1, 'with_peripheral' => 1), $protocol);
                         } else {
                             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
                         }
                     }
                 }
                 // Device connection
                 if (preg_match("/Device/", $links['to_item']['itemtype'])) {
                     $comp_device = new Computer_Device();
                     $links_field = getPlural(strtolower($links['to_item']['itemtype'])) . "_id";
                     $data = array();
                     $data['computers_id'] = $links['from_item']['id'];
                     $data[$links_field] = $links['to_item']['id'];
                     $data['itemtype'] = $links['to_item']['itemtype'];
                     if (!isset($links['to_item']['quantity']) || !is_numeric($links['to_item']['quantity'])) {
                         $quantity = 1;
                     } else {
                         $quantity = $links['to_item']['quantity'];
                     }
                     if (isset($links['to_item']['specificity'])) {
                         if (!is_numeric($links['to_item']['specificity'])) {
                             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'specificity');
                         } else {
                             $data['specificity'] = $links['to_item']['specificity'];
                         }
                     }
                     $linked = false;
                     for ($i = 0; $i < $quantity; $i++) {
                         if (!$comp_device->can(-1, UPDATE, $data)) {
                             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
                         } else {
                             if ($comp_device->add($data)) {
                                 $linked = true;
                             }
                         }
                     }
                     if ($linked) {
                         $resp['Computer'][$data['computers_id']] = self::methodGetObject(array('itemtype' => 'Computer', 'id' => $data['computers_id']), $protocol);
                     } else {
                         $errors[] = self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
                     }
                 }
                 //other link object
                 break;
                 //itemtype
         }
     }
     if (count($errors)) {
         $resp = array($resp, $errors);
     }
     return $resp;
 }
开发者ID:JULIO8,项目名称:respaldo_glpi,代码行数:97,代码来源:methodinventaire.class.php

示例2: array

             if ($val == 1) {
                 $input = array('computers_id' => $key, 'itemtype' => $_POST["itemtype"], 'items_id' => $_POST["connect_item"]);
                 if ($conn->can(-1, 'w', $input)) {
                     $conn->add($input);
                 }
             }
         }
     }
     break;
 case "connect":
     if (isset($_POST["connect_item"]) && $_POST["connect_item"]) {
         $conn = new Computer_Item();
         foreach ($_POST["item"] as $key => $val) {
             if ($val == 1) {
                 $input = array('computers_id' => $_POST["connect_item"], 'itemtype' => $_POST["itemtype"], 'items_id' => $key);
                 if ($conn->can(-1, 'w', $input)) {
                     $conn->add($input);
                 }
             }
         }
     }
     break;
 case "disconnect":
     $conn = new Computer_Item();
     foreach ($_POST["item"] as $key => $val) {
         if ($val == 1) {
             if ($item->getFromDB($key)) {
                 $conn->disconnectForItem($item);
             }
         }
     }
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:31,代码来源:massiveaction.php


注:本文中的Computer_Item::can方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。