/**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $itemtype = $ma->getItemtype(false);
     $item = new PluginConsumablesRequest();
     $validation = new PluginConsumablesValidation();
     $consumable = new Consumable();
     $input = $ma->getInput();
     if (count($ids)) {
         switch ($ma->getAction()) {
             case "validate":
                 foreach ($ids as $key => $val) {
                     if ($item->can($key, UPDATE)) {
                         $item->getFromDB($key);
                         // Get available consumables
                         $outConsumable = array();
                         $availables = $consumable->find("`consumableitems_id` = '" . $item->fields['consumables_id'] . "' AND `items_id` = 0");
                         foreach ($availables as $available) {
                             $outConsumable[] = $available;
                         }
                         // Check if enough stock
                         if (!empty($outConsumable) && count($outConsumable) >= $item->fields['number']) {
                             // Give consumable
                             $result = array(1);
                             for ($i = 0; $i < $item->fields['number']; $i++) {
                                 if (isset($outConsumable[$i]) && $consumable->out($outConsumable[$i]['id'], $item->fields['give_itemtype'], $item->fields['give_items_id'])) {
                                     $result[] = 1;
                                 } else {
                                     $result[] = 0;
                                 }
                             }
                             if (!in_array(0, $result)) {
                                 // Validation status update
                                 $validation->validationConsumable($item->fields, CommonITILValidation::ACCEPTED);
                                 // Send notification
                                 NotificationEvent::raiseEvent(PluginConsumablesNotificationTargetRequest::CONSUMABLE_RESPONSE, $item, array('entities_id' => $_SESSION['glpiactive_entity'], 'consumablerequest' => $item->fields, 'comment' => $input['comment']));
                                 $ma->addMessage("<span style='color:green'>" . sprintf(__('Consumable %s validated', 'consumables'), Dropdown::getDropdownName("glpi_consumableitems", $item->fields['consumables_id'])) . "</span>");
                                 $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_KO);
                             }
                         } else {
                             $ma->addMessage(sprintf(__('Not enough stock for consumable %s', 'consumables'), Dropdown::getDropdownName("glpi_consumableitems", $item->fields['consumables_id'])));
                             $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_KO);
                         }
                     } else {
                         $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($validation->getErrorMessage(ERROR_RIGHT));
                     }
                 }
                 break;
             case "refuse":
                 foreach ($ids as $key => $val) {
                     if ($item->can($key, UPDATE)) {
                         // Validation status update
                         if ($validation->validationConsumable($item->fields, CommonITILValidation::REFUSED)) {
                             // Send notification
                             NotificationEvent::raiseEvent(PluginConsumablesNotificationTargetRequest::CONSUMABLE_RESPONSE, $item, array('entities_id' => $_SESSION['glpiactive_entity'], 'consumablerequest' => $item->fields, 'comment' => $input['comment']));
                             $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_OK);
                             $ma->addMessage(__('Consumable refused', 'consumables'));
                         } else {
                             $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_KO);
                         }
                     } else {
                         $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($validation->getErrorMessage(ERROR_RIGHT));
                     }
                 }
                 break;
             default:
                 return parent::doSpecificMassiveActions($ma->POST);
         }
     }
 }