Add tags and display for plugins on GLPI External links & minor fixes

This commit is contained in:
tsmr 2016-01-27 18:04:09 +01:00
parent 946224b913
commit 285a86be4e
4 changed files with 51 additions and 9 deletions

View File

@ -87,8 +87,8 @@ function plugin_example_giveItem($type,$ID,$data,$num) {
switch ($table.'.'.$field) { switch ($table.'.'.$field) {
case "glpi_plugin_example_examples.name" : case "glpi_plugin_example_examples.name" :
$out = "<a href='".Toolbox::getItemTypeFormURL('PluginExampleExample')."?id=".$data['id']."'>"; $out = "<a href='".Toolbox::getItemTypeFormURL('PluginExampleExample')."?id=".$data['id']."'>";
$out .= $data["ITEM_$num"]; $out .= $data[$num][0]['name'];
if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_$num"])) { if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) {
$out .= " (".$data["id"].")"; $out .= " (".$data["id"].")";
} }
$out .= "</a>"; $out .= "</a>";

View File

@ -49,7 +49,7 @@ class PluginExampleConfig extends CommonDBTM {
function showFormExample() { function showFormExample() {
global $CFG_GLPI; global $CFG_GLPI;
if (!Session::haveRight("config", "w")) { if (!Session::haveRight("config", UPDATE)) {
return false; return false;
} }

View File

@ -34,7 +34,8 @@
// Class of the defined type // Class of the defined type
class PluginExampleExample extends CommonDBTM { class PluginExampleExample extends CommonDBTM {
static $tags = '[EXAMPLE_ID]';
// Should return the localized name of the type // Should return the localized name of the type
static function getTypeName($nb = 0) { static function getTypeName($nb = 0) {
@ -68,6 +69,7 @@ class PluginExampleExample extends CommonDBTM {
return __('Example plugin'); return __('Example plugin');
} }
/** /**
* @see CommonGLPI::getAdditionalMenuLinks() * @see CommonGLPI::getAdditionalMenuLinks()
**/ **/
@ -82,7 +84,33 @@ class PluginExampleExample extends CommonDBTM {
return $links; return $links;
} }
function defineTabs($options = array()) {
$ong = array();
$this->addDefaultFormTab($ong);
$this->addStandardTab('Link', $ong, $options);
return $ong;
}
function showForm($ID, $options = array()) {
global $CFG_GLPI;
$this->initForm($ID, $options);
$this->showFormHeader($options);
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('ID') . "</td>";
echo "<td>";
echo $ID;
echo "</td>";
$this->showFormButtons($options);
return true;
}
function getSearchOptions() { function getSearchOptions() {
$tab = array(); $tab = array();
@ -357,8 +385,6 @@ class PluginExampleExample extends CommonDBTM {
**/ **/
function getSpecificMassiveActions($checkitem=NULL) { function getSpecificMassiveActions($checkitem=NULL) {
Toolbox::logDebug();
$actions = parent::getSpecificMassiveActions($checkitem); $actions = parent::getSpecificMassiveActions($checkitem);
$actions['Document_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'add'] = $actions['Document_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'add'] =
@ -445,6 +471,17 @@ class PluginExampleExample extends CommonDBTM {
} }
parent::processMassiveActionsForOneItemtype($ma, $item, $ids); parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
} }
static function generateLinkContents($link, CommonDBTM $item) {
if (strstr($link,"[EXAMPLE_ID]")) {
$link = str_replace("[EXAMPLE_ID]", $item->getID(),$link);
return array($link);
}
return parent::generateLinkContents($link, $item);
}
} }
?> ?>

View File

@ -51,15 +51,20 @@ function plugin_init_example() {
'Preference', 'Profile', 'Supplier'); 'Preference', 'Profile', 'Supplier');
Plugin::registerClass('PluginExampleExample', Plugin::registerClass('PluginExampleExample',
array('notificationtemplates_types' => true, array('notificationtemplates_types' => true,
'addtabon' => $types)); 'addtabon' => $types,
'link_types' => true));
Plugin::registerClass('PluginExampleRuleTestCollection', Plugin::registerClass('PluginExampleRuleTestCollection',
array('rulecollections_types' => true)); array('rulecollections_types' => true));
Plugin::registerClass('PluginExampleDeviceCamera', Plugin::registerClass('PluginExampleDeviceCamera',
array('device_types' => true)); array('device_types' => true));
if (class_exists('PluginExampleExample')) {
Link::registerTag(PluginExampleExample::$tags);
}
// Display a menu entry ? // Display a menu entry ?
$_SESSION["glpi_plugin_example_profile"]['example'] = 'w';
if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook
$PLUGIN_HOOKS['menu_toadd']['example'] = array('plugins' => 'PluginExampleExample', $PLUGIN_HOOKS['menu_toadd']['example'] = array('plugins' => 'PluginExampleExample',
'tools' => 'PluginExampleExample'); 'tools' => 'PluginExampleExample');
@ -79,7 +84,7 @@ function plugin_init_example() {
} }
// Config page // Config page
if (Session::haveRight('config','w')) { if (Session::haveRight('config',UPDATE)) {
$PLUGIN_HOOKS['config_page']['example'] = 'config.php'; $PLUGIN_HOOKS['config_page']['example'] = 'config.php';
} }