mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
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:
parent
7e733f2322
commit
cd37a236d1
102
hook.php
102
hook.php
@ -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 "<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
|
||||
function plugin_example_dynamicReport($parm) {
|
||||
|
||||
|
@ -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 "<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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user