diff --git a/hook.php b/hook.php
index d44562b..4d946a6 100644
--- a/hook.php
+++ b/hook.php
@@ -270,102 +270,15 @@ function plugin_example_MassiveActions($type) {
switch ($type) {
// New action for core and other plugin types : name = plugin_PLUGINNAME_actionname
case 'Computer' :
- return array("plugin_example_DoIt" => __("plugin_example_DoIt", 'example'));
+ return array('PluginExampleExample'.MassiveAction::CLASS_ACTION_SEPARATOR.'DoIt' =>
+ __("plugin_example_DoIt", 'example'));
- // Actions for types provided by the plugin
- case 'PluginExampleExample' :
- return array("add_document" => _x('button', 'Add a document'), // GLPI core one
- "do_nothing" => __('Do Nothing - just for fun', 'example')); // Specific one
+ // Actions for types provided by the plugin are included inside the classes
}
return array();
}
-// How to display specific actions ?
-// options contain at least itemtype and and action
-function plugin_example_MassiveActionsDisplay($options=array()) {
-
- switch ($options['itemtype']) {
- case 'Computer' :
- switch ($options['action']) {
- case "plugin_example_DoIt" :
- echo " ".
- " ".__('Write in item history', 'example');
- break;
- }
- break;
-
- case 'PluginExampleExample' :
- switch ($options['action']) {
- // No case for add_document : use GLPI core one
- case "do_nothing" :
- echo " ".__('but do nothing :)', 'example');
- break;
- }
- break;
- }
- return "";
-}
-
-
-// How to process specific actions ?
-// May return array of stats containing number of process: ok / ko / noright count to display stats
-function plugin_example_MassiveActionsProcess($data) {
-
- $ok = 0;
- $ko = 0;
- $noright = 0;
-
- switch ($data['action']) {
- case 'plugin_example_DoIt' :
- if ($data['itemtype'] == 'Computer') {
- $comp = new 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 ($data['item'] as $key => $val) {
- if ($val == 1) {
- if ($comp->getFromDB($key)) {
- Session::addMessageAfterRedirect("- ".$comp->getField("name"));
- Log::history($key, 'Computer', $changes, 'PluginExampleExample', Log::HISTORY_PLUGIN);
- $ok++;
- } else {
- // Example of ko count
- $ko++;
- }
- }
- }
- }
- break;
-
- case 'do_nothing' :
- if ($data['itemtype'] == 'PluginExampleExample') {
- $ex = new PluginExampleExample();
- Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
- Session::addMessageAfterRedirect(__("But... I say I will do nothing for:", 'example'));
- foreach ($data['item'] as $key => $val) {
- if ($val == 1) {
- if ($ex->getFromDB($key)) {
- Session::addMessageAfterRedirect("- ".$ex->getField("name"));
- $ok++;
- } else {
- // Example for noright / Maybe do it with can function is better
- $noright++;
- }
- }
- }
- }
- break;
- }
- return array('ok' => $ok,
- 'ko' => $ko,
- 'noright' => $noright);
-
-}
-
-
// How to display specific update fields ?
// options must contain at least itemtype and options array
function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
@@ -449,7 +362,10 @@ function plugin_item_update_example($item) {
// Hook done on get empty item case
function plugin_item_empty_example($item) {
- Session::addMessageAfterRedirect(__("Empty Computer Hook", 'example'),true);
+ if (empty($_SESSION['Already displayed "Empty Computer Hook"'])) {
+ Session::addMessageAfterRedirect(__("Empty Computer Hook", 'example'),true);
+ $_SESSION['Already displayed "Empty Computer Hook"'] = true;
+ }
return true;
}
diff --git a/inc/example.class.php b/inc/example.class.php
index 51c974b..62d281c 100644
--- a/inc/example.class.php
+++ b/inc/example.class.php
@@ -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 " ".
+ 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);
+ }
+
}
?>
\ No newline at end of file