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:
webmyster
2013-11-01 06:41:05 +00:00
parent 0edcafd1fb
commit 76d6268bf1
2 changed files with 108 additions and 93 deletions

View File

@ -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 "&nbsp;<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 "&nbsp;".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);
}
}
?>