static public getMassiveActionsForItemtype ( array &$actions, $itemtype, $is_deleted, CommonDBTM $checkitem = NULL ) | ||
$actions | array | |
$checkitem | CommonDBTM |
/** * Get the standard massive actions * * @param $item the item for which we want the massive actions * @param $is_deleted massive action for deleted items ? (default 0) * @param $checkitem link item to check right (default NULL) * * @return an array of massive actions or false if $item is not valid **/ static function getAllMassiveActions($item, $is_deleted = 0, CommonDBTM $checkitem = NULL) { global $CFG_GLPI, $PLUGIN_HOOKS; // TODO: when maybe* will be static, when can completely switch to $itemtype ! if (is_string($item)) { $itemtype = $item; if (!($item = getItemForItemtype($itemtype))) { return false; } } else { if ($item instanceof CommonDBTM) { $itemtype = $item->getType(); } else { return false; } } if (!is_null($checkitem)) { $canupdate = $checkitem->canUpdate(); $candelete = $checkitem->canDelete(); $canpurge = $checkitem->canPurge(); } else { $canupdate = $itemtype::canUpdate(); $candelete = $itemtype::canDelete(); $canpurge = $itemtype::canPurge(); } $actions = array(); $self_pref = __CLASS__ . self::CLASS_ACTION_SEPARATOR; if ($is_deleted) { if ($canpurge) { if (in_array($itemtype, Item_Devices::getConcernedItems())) { $actions[$self_pref . 'purge_item_but_devices'] = _x('button', 'Delete permanently but keep devices'); $actions[$self_pref . 'purge'] = _x('button', 'Delete permanently and remove devices'); } else { $actions[$self_pref . 'purge'] = _x('button', 'Delete permanently'); } $actions[$self_pref . 'restore'] = _x('button', 'Restore'); } } else { if ($_SESSION['glpiactiveprofile']['interface'] == 'central' && ($canupdate || InfoCom::canApplyOn($itemtype) && Infocom::canUpdate())) { //TRANS: select action 'update' (before doing it) $actions[$self_pref . 'update'] = _x('button', 'Update'); } Infocom::getMassiveActionsForItemtype($actions, $itemtype, $is_deleted, $checkitem); CommonDBConnexity::getMassiveActionsForItemtype($actions, $itemtype, $is_deleted, $checkitem); // do not take into account is_deleted if items may be dynamic if ($item->maybeDeleted() && !$item->useDeletedToLockIfDynamic()) { if ($candelete) { $actions[$self_pref . 'delete'] = _x('button', 'Put in dustbin'); } } else { if ($canpurge) { $actions[$self_pref . 'purge'] = _x('button', 'Delete permanently'); if ($item instanceof CommonDropdown) { $actions[$self_pref . 'purge_but_item_linked'] = _x('button', 'Delete permanently even if linked items'); } } } Document::getMassiveActionsForItemtype($actions, $itemtype, $is_deleted, $checkitem); Contract::getMassiveActionsForItemtype($actions, $itemtype, $is_deleted, $checkitem); // Specific actions $actions += $item->getSpecificMassiveActions($checkitem); // Plugin Specific actions if (isset($PLUGIN_HOOKS['use_massive_action'])) { foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) { $plug_actions = Plugin::doOneHook($plugin, 'MassiveActions', $itemtype); if (count($plug_actions)) { $actions += $plug_actions; } } } } Lock::getMassiveActionsForItemtype($actions, $itemtype, $is_deleted, $checkitem); // Manage forbidden actions : try complete action name or MassiveAction:action_name $forbidden_actions = $item->getForbiddenStandardMassiveAction(); if (is_array($forbidden_actions) && count($forbidden_actions)) { foreach ($forbidden_actions as $actiontodel) { if (isset($actions[$actiontodel])) { unset($actions[$actiontodel]); } else { // Not found search adding MassiveAction prefix $actiontodel = $self_pref . $actiontodel; if (isset($actions[$actiontodel])) { unset($actions[$actiontodel]); } } } } return $actions; }