本文整理汇总了PHP中CommonDBTM::getFromDB方法的典型用法代码示例。如果您正苦于以下问题:PHP CommonDBTM::getFromDB方法的具体用法?PHP CommonDBTM::getFromDB怎么用?PHP CommonDBTM::getFromDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommonDBTM
的用法示例。
在下文中一共展示了CommonDBTM::getFromDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'add':
$input = $ma->getInput();
$ticket = new Ticket();
if (isset($input['link']) && isset($input['tickets_id_1'])) {
if ($item->getFromDB($input['tickets_id_1'])) {
foreach ($ids as $id) {
$input2 = array();
$input2['id'] = $input['tickets_id_1'];
$input2['_link']['tickets_id_1'] = $input['tickets_id_1'];
$input2['_link']['link'] = $input['link'];
$input2['_link']['tickets_id_2'] = $id;
if ($item->can($input['tickets_id_1'], UPDATE)) {
if ($ticket->update($input2)) {
$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));
}
}
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例2: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $CFG_GLPI;
switch ($ma->getAction()) {
case "uninstall":
$itemtype = $ma->getItemtype(false);
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
//Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName()));
$_SESSION['glpi_uninstalllist'][$itemtype][$id] = $id;
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
}
}
Html::redirect($CFG_GLPI["root_doc"] . '/plugins/uninstall/front/action.php?device_type=' . $itemtype . "&model_id=" . $_POST["model_id"]);
return;
break;
}
return;
}
示例3: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $CFG_GLPI;
switch ($ma->getAction()) {
case "transfert":
$input = $ma->getInput();
$entities_id = $input['entities_id'];
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
$item->update(array("id" => $id, "entities_id" => $entities_id, "update" => __('Update')));
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
}
}
return;
break;
}
return;
}
示例4: processMassiveActionsForOneItemtype
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $CFG_GLPI;
switch ($ma->getAction()) {
case 'Generate':
$pbQRcode = new PluginBarcodeQRcode();
$rand = mt_rand();
$number = 0;
$codes = array();
if ($ma->POST['eliminate'] > 0) {
for ($nb = 0; $nb < $ma->POST['eliminate']; $nb++) {
$codes[] = '';
}
}
if ($ma->POST['type'] == 'QRcode') {
foreach ($ids as $key) {
$filename = $pbQRcode->generateQRcode($item->getType(), $key, $rand, $number, $ma->POST);
if ($filename) {
$codes[] = $filename;
$number++;
}
}
} else {
foreach ($ids as $key) {
$item->getFromDB($key);
if ($item->isField('otherserial')) {
$codes[] = $item->getField('otherserial');
}
}
}
if (count($codes) > 0) {
$params['codes'] = $codes;
$params['type'] = $ma->POST['type'];
$params['size'] = $ma->POST['size'];
$params['border'] = $ma->POST['border'];
$params['orientation'] = $ma->POST['orientation'];
$barcode = new PluginBarcodeBarcode();
$file = $barcode->printPDF($params);
$filePath = explode('/', $file);
$filename = $filePath[count($filePath) - 1];
$msg = "<a href='" . $CFG_GLPI['root_doc'] . '/plugins/barcode/front/send.php?file=' . urlencode($filename) . "'>" . __('Generated file', 'barcode') . "</a>";
Session::addMessageAfterRedirect($msg);
$pbQRcode->cleanQRcodefiles($rand, $number);
}
$ma->itemDone($item->getType(), 0, MassiveAction::ACTION_OK);
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例5: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'duplicate':
$rulecollection = new RuleCollection();
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
if ($rulecollection->duplicateRule($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_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
}
break;
case 'export':
if (count($ids)) {
$_SESSION['exportitems'] = $ids;
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK);
$ma->setRedirect('rule.backup.php?action=download&itemtype=' . $item->getType());
}
break;
case 'move_rule':
$input = $ma->getInput();
$collectionname = $input['rule_class_name'] . 'Collection';
$rulecollection = new $collectionname();
if ($rulecollection->canUpdate()) {
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
if ($rulecollection->moveRule($id, $input['ranking'], $input['move_type'])) {
$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_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
break;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例6: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'add_actor':
$input = $ma->getInput();
foreach ($ids as $id) {
$input2 = array('id' => $id);
if (isset($input['_itil_requester'])) {
$input2['_itil_requester'] = $input['_itil_requester'];
}
if (isset($input['_itil_observer'])) {
$input2['_itil_observer'] = $input['_itil_observer'];
}
if (isset($input['_itil_assign'])) {
$input2['_itil_assign'] = $input['_itil_assign'];
}
if ($item->can($id, UPDATE)) {
if ($item->update($input2)) {
$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));
}
}
return;
case 'update_notif':
$input = $ma->getInput();
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
$linkclass = new $item->userlinkclass();
foreach ($linkclass->getActors($id) as $type => $users) {
foreach ($users as $data) {
$data['use_notification'] = $input['use_notification'];
$linkclass->update($data);
}
}
$linkclass = new $this->supplierlinkclass();
foreach ($linkclass->getActors($id) as $type => $users) {
foreach ($users as $data) {
$data['use_notification'] = $input['use_notification'];
$linkclass->update($data);
}
}
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
return;
case 'add_task':
if (!($task = getItemForItemtype($item->getType() . 'Task'))) {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
break;
}
$field = $item->getForeignKeyField();
$input = $ma->getInput();
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
$input2 = array($field => $id, 'taskcategories_id' => $input['taskcategories_id'], 'content' => $input['content']);
if ($task->can(-1, CREATE, $input2)) {
if ($task->add($input2)) {
$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));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例7: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'DoIt':
if ($item->getType() == 'Computer') {
Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
Session::addMessageAfterRedirect(__('Write in item history', 'example'));
$changes = array(0, 'old value', 'new value');
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
Session::addMessageAfterRedirect("- " . $item->getField("name"));
Log::history($id, 'Computer', $changes, 'PluginExampleExample', Log::HISTORY_PLUGIN);
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
// Example of ko count
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
}
}
} else {
// When nothing is possible ...
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
case 'do_nothing':
if ($item->getType() == 'PluginExampleExample') {
Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
Session::addMessageAfterRedirect(__("But... I say I will do nothing for:", 'example'));
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
Session::addMessageAfterRedirect("- " . $item->getField("name"));
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
// Example for noright / Maybe do it with can function is better
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例8: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
$account_item = new PluginAccountsAccount_Item();
switch ($ma->getAction()) {
case "add_item":
$input = $ma->getInput();
foreach ($ma->items as $itemtype => $myitem) {
foreach ($myitem as $key => $value) {
if (!countElementsInTable('glpi_plugin_accounts_accounts_items', "itemtype='{$itemtype}' \n AND items_id='{$key}' \n AND plugin_accounts_accounts_id='" . $input['plugin_accounts_accounts_id'] . "'")) {
$myvalue['plugin_accounts_accounts_id'] = $input['plugin_accounts_accounts_id'];
$myvalue['itemtype'] = $itemtype;
$myvalue['items_id'] = $key;
if ($account_item->add($myvalue)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
break;
case "transfer":
$input = $ma->getInput();
if ($item->getType() == 'PluginAccountsAccount') {
foreach ($ids as $key) {
$item->getFromDB($key);
$type = PluginAccountsAccountType::transfer($item->fields["plugin_accounts_accounttypes_id"], $input['entities_id']);
if ($type > 0) {
$values["id"] = $key;
$values["plugin_accounts_accounttypes_id"] = $type;
$item->update($values);
}
unset($values);
$values["id"] = $key;
$values["entities_id"] = $input['entities_id'];
if ($item->update($values)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
break;
case 'install':
$input = $ma->getInput();
foreach ($ids as $key) {
if ($item->can($key, UPDATE)) {
$values = array('plugin_accounts_accounts_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
if ($account_item->add($values)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'uninstall':
$input = $ma->getInput();
foreach ($ids as $key) {
if ($val == 1) {
if ($account_item->deleteItemByAccountsAndItem($key, $input['item_item'], $input['typeitem'])) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
break;
}
}
示例9: processMassiveActionsForOneItemtype
/**
* Execute massive action for PluginFormcreatorFrom
*
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'Duplicate':
foreach ($ids as $id) {
if ($item->getFromDB($id) && $item->Duplicate()) {
Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName()));
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
// Example of ko count
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例10: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'submit_validation':
$input = $ma->getInput();
$valid = new static();
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
$input2 = array(static::$items_id => $id, 'comment_submission' => $input['comment_submission']);
if ($valid->can(-1, CREATE, $input2)) {
$users = $input['users_id_validate'];
if (!is_array($users)) {
$users = array($users);
}
$ok = true;
foreach ($users as $user) {
$input2["users_id_validate"] = $user;
if (!$valid->add($input2)) {
$ok = false;
}
}
if ($ok) {
$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));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例11: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'add_item':
$input = $ma->getInput();
$item_ticket = new static();
foreach ($ids as $id) {
if ($item->getFromDB($id) && !empty($input['items_id'])) {
$input['tickets_id'] = $id;
$input['itemtype'] = $input['item_itemtype'];
if ($item_ticket->can(-1, CREATE, $input)) {
$ok = true;
if (!$item_ticket->add($input)) {
$ok = false;
}
if ($ok) {
$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));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
}
return;
case 'delete_item':
$input = $ma->getInput();
$item_ticket = new static();
foreach ($ids as $id) {
if ($item->getFromDB($id) && !empty($input['items_id'])) {
$item_found = $item_ticket->find("`tickets_id` = {$id} AND `itemtype` = '" . $input['item_itemtype'] . "' AND `items_id` = " . $input['items_id']);
if (!empty($item_found)) {
$item_founds_id = array_keys($item_found);
$input['id'] = $item_founds_id[0];
if ($item_ticket->can($input['id'], DELETE, $input)) {
$ok = true;
if (!$item_ticket->delete($input)) {
$ok = false;
}
if ($ok) {
$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));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例12: processMassiveActionsForOneItemtype
/**
* Execute massive action for PluginFormcreatorFrom
*
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'Duplicate':
foreach ($ids as $id) {
if ($item->getFromDB($id) && $item->Duplicate()) {
Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName()));
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
// Example of ko count
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
}
}
//return;
break;
//[CRI]
//[CRI]
case "Pedido":
if ($item->getType() == 'Ticket') {
// [CRI]
$Plugin = new PluginFormcreatorForm();
$PluginItem = new PluginFormcreatorForm_Item();
$Target = new PluginFormcreatorTarget();
$helpdesk = new PluginFormcreatorTargetTicket();
$input = $ma->getInput();
foreach ($ids as $key) {
$listForm = $PluginItem->find("items_id = " . $key . " and itemtype = '" . $item->getType() . "'");
if (empty($listForm)) {
$input11 = array('plugin_formcreator_forms_id' => $input['plugin_formcreator_forms_id'], 'items_id' => $key, 'itemtype' => $item->getType());
$PluginItem->add($input11);
} else {
foreach ($listForm as $form_id => $value) {
$input12 = array('id' => $form_id);
$input12['plugin_formcreator_forms_id'] = $input['plugin_formcreator_forms_id'];
$input12['items_id'] = $key;
$input12['itemtype'] = $item->getType();
$PluginItem->update($input12);
}
}
//Actualizar Ticket
PluginFormcreatorForm::fromcreatorDropUserAndGrouponTicket($key);
//
PluginFormcreatorForm::updateTicketFromForm($input['plugin_formcreator_forms_id'], $key);
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
}
}
break;
//parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
}
示例13: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case "transfer":
$input = $ma->getInput();
if ($item->getType() == 'PluginBadgesBadge') {
foreach ($ids as $key) {
$item->getFromDB($key);
$type = PluginBadgesBadgeType::transfer($item->fields["plugin_badges_badgetypes_id"], $input['entities_id']);
if ($type > 0) {
$values["id"] = $key;
$values["plugin_badges_badgetypes_id"] = $type;
$item->update($values);
}
unset($values);
$values["id"] = $key;
$values["entities_id"] = $input['entities_id'];
if ($item->update($values)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
break;
}
}
示例14: countForItem
static function countForItem(CommonDBTM $item, $options = array())
{
global $DB;
$ID = $item->getField('id');
$query = "SELECT `glpi_plugin_shellcommands_shellcommands_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_shellcommands_shellcommands`.`name` AS assocName,\n `glpi_plugin_shellcommands_shellcommands`.*\n FROM `glpi_plugin_shellcommands_shellcommands_items`\n LEFT JOIN `glpi_plugin_shellcommands_shellcommands`\n ON (`glpi_plugin_shellcommands_shellcommands_items`.`plugin_shellcommands_shellcommands_id`=`glpi_plugin_shellcommands_shellcommands`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_shellcommands_shellcommands`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_shellcommands_shellcommands_items`.`itemtype` = '" . $item->getType() . "' ";
$query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_shellcommands_shellcommands", '', '', true);
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
$shells = array();
if ($number) {
while ($data = $DB->fetch_assoc($result)) {
$shells[$data['assocID']] = $data;
}
}
$countCommand = array();
$count = 0;
if ($number) {
foreach ($shells as $data) {
$link = $data["link"];
$item->getFromDB($ID);
if (strstr($link, '[NAME]')) {
// NAME
$countCommand['[NAME]' . $data['id']][] = 1;
$count++;
} else {
if (strstr($link, '[ID]')) {
// ID
$countCommand['[ID]' . $data['id']][] = 1;
$count++;
} else {
if (strstr($link, '[DOMAIN]')) {
// DOMAIN
if (isset($item->fields['domains_id'])) {
$countCommand['[DOMAIN]' . $data['id']][] = 1;
$count++;
}
} else {
if (strstr($link, '[IP]') || strstr($link, '[MAC]')) {
$mac = array();
$ip = array();
$i = 0;
$query2 = "SELECT `glpi_networkports`.*, `glpi_ipaddresses`.`name` as ip\n FROM `glpi_networkports`\n LEFT JOIN `glpi_networknames`\n ON (`glpi_networknames`.`items_id`=`glpi_networkports`.`id`) \n LEFT JOIN `glpi_ipaddresses`\n ON (`glpi_networknames`.`id`=`glpi_ipaddresses`.`items_id`) \n WHERE `glpi_networkports`.`items_id` = '{$ID}' \n AND `glpi_networkports`.`itemtype` = '" . $item->getType() . "' \n ORDER BY `glpi_networkports`.`logical_number`";
$result2 = $DB->query($query2);
if ($DB->numrows($result2) > 0) {
while ($data2 = $DB->fetch_array($result2)) {
if (!empty($data2["ip"]) && $data2["ip"] != '0.0.0.0') {
$ip[$i]['ip'] = $data2["ip"];
$i++;
}
if (!empty($data2["mac"])) {
$mac[$i]['mac'] = $data2["mac"];
$i++;
}
}
}
if (strstr($link, '[IP]')) {
// IP internal switch
if ($item->getType() == 'NetworkEquipment') {
$countCommand['[IP]' . $data['id']][] = 1;
$count++;
}
if (count($ip) > 0) {
foreach ($ip as $val) {
$countCommand['[IP]' . $data['id']][] = 1;
}
$count++;
}
}
if (strstr($link, '[MAC]')) {
// MAC internal switch
if ($item->getType() == 'NetworkEquipment') {
$countCommand['[MAC]' . $data['id']][] = 1;
$count++;
}
if (count($mac) > 0) {
foreach ($mac as $val) {
$countCommand['[MAC]' . $data['id']][] = 1;
}
$count++;
}
}
}
}
}
}
}
}
if (isset($options['type']) && isset($options['itemId']) && isset($countCommand['[IP]' . $options['itemId']]) && stristr($options['type'], 'ip')) {
return sizeof($countCommand['[IP]' . $options['itemId']]);
} elseif (isset($options['type']) && isset($options['itemId']) && isset($countCommand['[MAC]' . $options['itemId']]) && stristr($options['type'], 'mac')) {
return sizeof($countCommand['[MAC]' . $options['itemId']]);
} elseif (isset($options['type']) && $options['type'] == 'ALL') {
return $countCommand;
} else {
return $count;
}
}
示例15: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'reset':
if (Config::canUpdate()) {
foreach ($ids as $key) {
if ($item->getFromDB($key)) {
if ($item->resetDate()) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
}
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}