本文整理汇总了PHP中Infocom::can方法的典型用法代码示例。如果您正苦于以下问题:PHP Infocom::can方法的具体用法?PHP Infocom::can怎么用?PHP Infocom::can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Infocom
的用法示例。
在下文中一共展示了Infocom::can方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processMassiveActionsForOneItemtype
/**
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $CFG_GLPI;
$action = $ma->getAction();
switch ($action) {
case 'delete':
foreach ($ids as $id) {
if ($item->can($id, DELETE)) {
if ($item->delete(array("id" => $id))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'restore':
foreach ($ids as $id) {
if ($item->can($id, PURGE)) {
if ($item->restore(array("id" => $id))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'purge_item_but_devices':
case 'purge_but_item_linked':
case 'purge':
foreach ($ids as $id) {
if ($item->can($id, PURGE)) {
$force = 1;
// Only mark deletion for
if ($item->maybeDeleted() && $item->useDeletedToLockIfDynamic() && $item->isDynamic()) {
$force = 0;
}
$delete_array = array('id' => $id);
if ($action == 'purge_item_but_devices') {
$delete_array['keep_devices'] = true;
}
if ($item instanceof CommonDropdown) {
if ($item->haveChildren()) {
if ($action != 'purge_but_item_linked') {
$force = 0;
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage(__("You can't delete that item by massive actions, because it has sub-items"));
$ma->addMessage(__("but you can do it by the form of the item"));
continue;
}
}
if ($item->isUsed()) {
if ($action != 'purge_but_item_linked') {
$force = 0;
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage(__("You can't delete that item, because it is used for one or more items"));
$ma->addMessage(__("but you can do it by the form of the item"));
continue;
}
}
}
if ($item->delete($delete_array, $force)) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'update':
if (!isset($ma->POST['search_options']) || !isset($ma->POST['search_options'][$item->getType()])) {
return false;
}
$index = $ma->POST['search_options'][$item->getType()];
$searchopt = Search::getCleanedOptions($item->getType(), UPDATE);
$input = $ma->POST;
if (isset($searchopt[$index])) {
/// Infocoms case
if (!isPluginItemType($item->getType()) && Search::isInfocomOption($item->getType(), $index)) {
$ic = new Infocom();
$link_entity_type = -1;
/// Specific entity item
if ($searchopt[$index]["table"] == "glpi_suppliers") {
$ent = new Supplier();
if ($ent->getFromDB($input[$input["field"]])) {
//.........这里部分代码省略.........
示例2: doMassiveActions
/**
* Do the standard massive actions
*
* @since version 0.84
*
* This must not be overloaded in Class
* @param $input array of input datas
*
* @return an array of results (ok, ko, noright counts, may include REDIRECT field to set REDIRECT page)
**/
function doMassiveActions($input = array())
{
global $CFG_GLPI;
if (!isset($input["item"]) || count($input["item"]) == 0) {
return false;
}
$res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
switch ($input['action']) {
case 'add_document':
case 'remove_document':
$doc = new Document();
return $doc->doSpecificMassiveActions($input);
case "add_transfer_list":
if (!isset($_SESSION['glpitransfer_list'])) {
$_SESSION['glpitransfer_list'] = array();
}
if (!isset($_SESSION['glpitransfer_list'][$input["itemtype"]])) {
$_SESSION['glpitransfer_list'][$input["itemtype"]] = array();
}
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
$_SESSION['glpitransfer_list'][$input["itemtype"]][$key] = $key;
$res['ok']++;
}
}
$res['REDIRECT'] = $CFG_GLPI['root_doc'] . '/front/transfer.action.php';
break;
case "delete":
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
if ($this->can($key, 'd')) {
if ($this->delete(array("id" => $key))) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
case "purge":
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
if ($this->can($key, 'd')) {
$force = 1;
// Only mark deletion for
if ($this->maybeDeleted() && $this->useDeletedToLockIfDynamic() && $this->isDynamic()) {
$force = 0;
}
if ($this->delete(array("id" => $key), $force)) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
case "restore":
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
if ($this->can($key, 'd')) {
if ($this->restore(array("id" => $key))) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
case "update":
$searchopt = Search::getCleanedOptions($input["itemtype"], 'w');
if (isset($searchopt[$input["id_field"]])) {
/// Infocoms case
if (!isPluginItemType($input["itemtype"]) && Search::isInfocomOption($input["itemtype"], $input["id_field"])) {
$ic = new Infocom();
$link_entity_type = -1;
/// Specific entity item
if ($searchopt[$input["id_field"]]["table"] == "glpi_suppliers") {
$ent = new Supplier();
if ($ent->getFromDB($input[$input["field"]])) {
$link_entity_type = $ent->fields["entities_id"];
}
//.........这里部分代码省略.........