From cd37a236d1b11a8617d9290515af5dc6b7016090 Mon Sep 17 00:00:00 2001 From: remicollet Date: Tue, 24 Jan 2012 11:32:20 +0000 Subject: [PATCH] remove old hook (headings) and move to new standard tab git-svn-id: https://forge.glpi-project.org/svn/example/trunk@184 349b9182-4a13-0410-896f-e5e9767dd1b3 --- hook.php | 104 +----------------------------------------- inc/example.class.php | 71 ++++++++++++++++++++++++++-- setup.php | 4 +- 3 files changed, 71 insertions(+), 108 deletions(-) diff --git a/hook.php b/hook.php index 9092fde..6d97b20 100644 --- a/hook.php +++ b/hook.php @@ -384,7 +384,7 @@ function plugin_example_MassiveActionsFieldsDisplay($options=array()) { // options must contain at least itemtype and options array // MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration function plugin_example_searchOptionsValues($options=array()) { - + $table = $options['searchoption']['table']; $field = $options['searchoption']['field']; @@ -514,7 +514,7 @@ function plugin_display_planning_example($parm) { break; case "through" : - echo Html::resume_text($val["name"],80); + echo Html::resume_text($parm["name"],80); break; case "begin" : @@ -532,106 +532,6 @@ function plugin_display_planning_example($parm) { } -// Define headings added by the plugin -function plugin_get_headings_example($item, $withtemplate) { - - switch (get_class($item)) { - case 'Profile' : - $prof = new Profile(); - if ($item->fields['interface'] == 'central') { - return array(1 => __("Test PLugin")); - } - return array(); - - case 'Computer' : - // new object / template case - if ($withtemplate) { - return array(); - // Non template case / editing an existing object - } - return array(1 => __("Test PLugin")); - - case 'ComputerDisk' : - case 'Supplier' : - if ($item->getField('id')) { // Not in create mode - return array(1 => __("Test PLugin"), - 2 => __("Test PLugin 2")); - } - break; - - case 'Central' : - case 'Preference': - case 'Notification': - return array(1 => __("Test PLugin")); - } - return false; -} - - -// Define headings actions added by the plugin -function plugin_headings_actions_example($item) { - - switch (get_class($item)) { - case 'Profile' : - case 'Computer' : - return array(1 => "plugin_headings_example"); - - case 'ComputerDisk' : - case 'Supplier' : - return array(1 => "plugin_headings_example", - 2 => "plugin_headings_example"); - - case 'Central' : - case 'Preference' : - case 'Notification' : - return array(1 => "plugin_headings_example"); - } - return false; -} - - -// Example of an action heading -function plugin_headings_example($item, $withtemplate=0) { - - if (!$withtemplate) { - echo "
"; - switch (get_class($item)) { - case 'Central' : - _e("Plugin central action"); - break; - - case 'Preference' : - // Complete form display - $data = plugin_version_example(); - - echo "
"; - echo ""; - echo ""; - - echo ""; - echo ""; - - echo ""; - echo ""; - - echo "
".$data['name']." - ".$data['version']; - echo "
Name of the prefInput to set the pref
"; - echo "
"; - break; - - case 'Notification' : - _e("Plugin mailing action"); - break; - - default : - printf(__("Plugin function with headings CLASS=%1$s id=%1$d"),get_class($item),$item->getField('id')); - break; - } - echo "
"; - } -} - - // Do special actions for dynamic report function plugin_example_dynamicReport($parm) { diff --git a/inc/example.class.php b/inc/example.class.php index a146366..e249b0b 100644 --- a/inc/example.class.php +++ b/inc/example.class.php @@ -148,12 +148,30 @@ class PluginExampleExample extends CommonDBTM { if (!$withtemplate) { switch ($item->getType()) { + case 'Profile' : + if ($item->getField('central')) { + return __('Example'); + } + break; + case 'Phone' : if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(__('Example'), countElementsInTable($this->getTable())); } return __('Example'); + + case 'ComputerDisk' : + case 'Supplier' : + return array(1 => __("Test PLugin"), + 2 => __("Test PLugin 2")); + + case 'Computer' : + case 'Central' : + case 'Preference': + case 'Notification': + return array(1 => __("Test PLugin")); + } } return ''; @@ -162,8 +180,51 @@ class PluginExampleExample extends CommonDBTM { static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { - if ($item->getType()=='Phone') { - echo "Plugin Example on Phone"; + switch ($item->getType()) { + case 'Phone' : + _e("Plugin Example on Phone"); + break; + + case 'Central' : + _e("Plugin central action"); + break; + + case 'Preference' : + // Complete form display + $data = plugin_version_example(); + + echo "
"; + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo "
".$data['name']." - ".$data['version']; + echo "
Name of the prefInput to set the pref
"; + echo "
"; + break; + + case 'Notification' : + _e("Plugin mailing action"); + break; + + case 'ComputerDisk' : + case 'Supplier' : + if ($tabnum==1) { + _e('First tab of Plugin example'); + } else { + _e('Second tab of Plugin example'); + } + break; + + default : + //TRANS: %1$s is a class name, %2$d is an item ID + printf(__('Plugin example CLASS=%1$s id=%2$d'), $item->getType(), $item->getField('id')); + break; } return true; } @@ -179,11 +240,11 @@ class PluginExampleExample extends CommonDBTM { } return ''; } - + // Parm contains begin, end and who // Create data to be displayed in the planning of $parm["who"] or $parm["who_group"] between $parm["begin"] and $parm["end"] static function populatePlanning($parm) { - + // Add items in the output array // Items need to have an unique index beginning by the begin date of the item to display // needed to be correcly displayed @@ -199,7 +260,7 @@ class PluginExampleExample extends CommonDBTM { // Specify the itemtype to be able to use specific display system $output[$key]["itemtype"] = "PluginExampleExample"; return $output; - } + } } ?> diff --git a/setup.php b/setup.php index a1e0dc3..ee5d487 100755 --- a/setup.php +++ b/setup.php @@ -45,9 +45,11 @@ function plugin_init_example() { // Params : plugin name - string type - ID - Array of attributes Plugin::registerClass('PluginExampleDropdown'); + $types = array('Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone', + 'Preference', 'Profile', 'Supplier'); Plugin::registerClass('PluginExampleExample', array('notificationtemplates_types' => true, - 'addtabon' => array('Phone'))); + 'addtabon' => $types)); Plugin::registerClass('PluginExampleRuleTestCollection', array('rulecollections_types' => true));