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
This commit is contained in:
remicollet 2012-01-24 11:32:20 +00:00
parent 7e733f2322
commit cd37a236d1
3 changed files with 71 additions and 108 deletions

104
hook.php
View File

@ -384,7 +384,7 @@ function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
// options must contain at least itemtype and options array // options must contain at least itemtype and options array
// MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration // MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration
function plugin_example_searchOptionsValues($options=array()) { function plugin_example_searchOptionsValues($options=array()) {
$table = $options['searchoption']['table']; $table = $options['searchoption']['table'];
$field = $options['searchoption']['field']; $field = $options['searchoption']['field'];
@ -514,7 +514,7 @@ function plugin_display_planning_example($parm) {
break; break;
case "through" : case "through" :
echo Html::resume_text($val["name"],80); echo Html::resume_text($parm["name"],80);
break; break;
case "begin" : 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 "<div class='center'>";
switch (get_class($item)) {
case 'Central' :
_e("Plugin central action");
break;
case 'Preference' :
// Complete form display
$data = plugin_version_example();
echo "<form action='Where to post form'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='3'>".$data['name']." - ".$data['version'];
echo "</th></tr>";
echo "<tr class='tab_bg_1'><td>Name of the pref</td>";
echo "<td>Input to set the pref</td>";
echo "<td><input class='submit' type='submit' name='submit' value='submit'></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
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 "</div>";
}
}
// Do special actions for dynamic report // Do special actions for dynamic report
function plugin_example_dynamicReport($parm) { function plugin_example_dynamicReport($parm) {

View File

@ -148,12 +148,30 @@ class PluginExampleExample extends CommonDBTM {
if (!$withtemplate) { if (!$withtemplate) {
switch ($item->getType()) { switch ($item->getType()) {
case 'Profile' :
if ($item->getField('central')) {
return __('Example');
}
break;
case 'Phone' : case 'Phone' :
if ($_SESSION['glpishow_count_on_tabs']) { if ($_SESSION['glpishow_count_on_tabs']) {
return self::createTabEntry(__('Example'), return self::createTabEntry(__('Example'),
countElementsInTable($this->getTable())); countElementsInTable($this->getTable()));
} }
return __('Example'); 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 ''; return '';
@ -162,8 +180,51 @@ class PluginExampleExample extends CommonDBTM {
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
if ($item->getType()=='Phone') { switch ($item->getType()) {
echo "Plugin Example on Phone"; 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 "<form action='Where to post form'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='3'>".$data['name']." - ".$data['version'];
echo "</th></tr>";
echo "<tr class='tab_bg_1'><td>Name of the pref</td>";
echo "<td>Input to set the pref</td>";
echo "<td><input class='submit' type='submit' name='submit' value='submit'></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
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; return true;
} }
@ -179,11 +240,11 @@ class PluginExampleExample extends CommonDBTM {
} }
return ''; return '';
} }
// Parm contains begin, end and who // 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"] // 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) { static function populatePlanning($parm) {
// Add items in the output array // Add items in the output array
// Items need to have an unique index beginning by the begin date of the item to display // Items need to have an unique index beginning by the begin date of the item to display
// needed to be correcly displayed // needed to be correcly displayed
@ -199,7 +260,7 @@ class PluginExampleExample extends CommonDBTM {
// Specify the itemtype to be able to use specific display system // Specify the itemtype to be able to use specific display system
$output[$key]["itemtype"] = "PluginExampleExample"; $output[$key]["itemtype"] = "PluginExampleExample";
return $output; return $output;
} }
} }
?> ?>

View File

@ -45,9 +45,11 @@ function plugin_init_example() {
// Params : plugin name - string type - ID - Array of attributes // Params : plugin name - string type - ID - Array of attributes
Plugin::registerClass('PluginExampleDropdown'); Plugin::registerClass('PluginExampleDropdown');
$types = array('Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone',
'Preference', 'Profile', 'Supplier');
Plugin::registerClass('PluginExampleExample', Plugin::registerClass('PluginExampleExample',
array('notificationtemplates_types' => true, array('notificationtemplates_types' => true,
'addtabon' => array('Phone'))); 'addtabon' => $types));
Plugin::registerClass('PluginExampleRuleTestCollection', Plugin::registerClass('PluginExampleRuleTestCollection',
array('rulecollections_types' => true)); array('rulecollections_types' => true));