function plugin_accounts_MassiveActionsProcess($data) { $account_item = new PluginAccountsAccount_Item(); $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); switch ($data['action']) { case "plugin_accounts_add_item": foreach ($data["item"] as $key => $val) { if ($val == 1) { $input = array('plugin_accounts_accounts_id' => $data['plugin_accounts_accounts_id'], 'items_id' => $key, 'itemtype' => $data['itemtype']); if ($account_item->can(-1, 'w', $input)) { if ($account_item->add($input)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } } break; } return $res; }
/** * @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; } }
/** * Do the specific massive actions * * @since version 0.84 * * @param $input array of input datas * * @return an array of results (nbok, nbko, nbnoright counts) **/ public function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); $account_item = new PluginAccountsAccount_Item(); switch ($input['action']) { case "Transfert": if ($input['itemtype'] == 'PluginAccountsAccount') { foreach ($input["item"] as $key => $val) { if ($val == 1) { $this->getFromDB($key); $type = PluginAccountsAccountType::transfer($this->fields["plugin_accounts_accounttypes_id"], $input['entities_id']); if ($type > 0) { $values["id"] = $key; $values["plugin_accounts_accounttypes_id"] = $type; if ($this->update($values)) { $res['ok']++; } else { $res['ko']++; } } unset($values); $values["id"] = $key; $values["entities_id"] = $input['entities_id']; if ($this->update($values)) { $res['ok']++; } else { $res['ko']++; } } } } break; case "Install": foreach ($input["item"] as $key => $val) { if ($val == 1) { $values = array('plugin_accounts_accounts_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']); if ($account_item->add($values)) { $res['ok']++; } else { $res['ko']++; } } } break; case "Desinstall": foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($account_item->deleteItemByAccountsAndItem($key, $input['item_item'], $input['typeitem'])) { $res['ok']++; } else { $res['ko']++; } } } break; default: return parent::doSpecificMassiveActions($input); break; } return $res; }