mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-06-28 06:58:43 +02:00
Fix example to adapt to new MassiveAction system (regarding ticket #4385 of the core)
git-svn-id: https://forge.glpi-project.org/svn/example/trunk@218 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
@ -81,8 +81,7 @@ class PluginExampleExample extends CommonDBTM {
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function getSearchOptions() {
|
||||
|
||||
@ -347,5 +346,105 @@ class PluginExampleExample extends CommonDBTM {
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
|
||||
/**
|
||||
* @since version 0.85
|
||||
*
|
||||
* @see CommonDBTM::getSpecificMassiveActions()
|
||||
**/
|
||||
function getSpecificMassiveActions($checkitem=NULL) {
|
||||
|
||||
Toolbox::logDebug();
|
||||
|
||||
$actions = parent::getSpecificMassiveActions($checkitem);
|
||||
|
||||
$actions['Document_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'add'] =
|
||||
_x('button', 'Add a document'); // GLPI core one
|
||||
$actions[__CLASS__.MassiveAction::CLASS_ACTION_SEPARATOR.'do_nothing'] =
|
||||
__('Do Nothing - just for fun', 'example'); // Specific one
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since version 0.85
|
||||
*
|
||||
* @see CommonDBTM::showMassiveActionsSubForm()
|
||||
**/
|
||||
static function showMassiveActionsSubForm(MassiveAction $ma) {
|
||||
|
||||
switch ($ma->getAction()) {
|
||||
case 'DoIt':
|
||||
echo " <input type='hidden' name='toto' value='1'>".
|
||||
Html::submit(_x('button','Post'), array('name' => 'massiveaction')).
|
||||
" ".__('Write in item history', 'example');
|
||||
return true;
|
||||
case 'do_nothing' :
|
||||
echo " ".Html::submit(_x('button','Post'), array('name' => 'massiveaction')).
|
||||
" ".__('but do nothing :)', 'example');
|
||||
return true;
|
||||
}
|
||||
return parent::showMassiveActionsSubForm($ma);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user