mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
CS + call functions
git-svn-id: https://forge.glpi-project.org/svn/example/trunk@172 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
parent
6188cf8ad0
commit
acf0490727
44
hook.php
44
hook.php
@ -63,6 +63,8 @@ function plugin_example_getDropdown() {
|
||||
return array('PluginExampleDropdown' => "Plugin Example Dropdown");
|
||||
}
|
||||
|
||||
|
||||
|
||||
////// SEARCH FUNCTIONS ///////(){
|
||||
|
||||
// Define Additionnal search options for types (other than the plugin ones)
|
||||
@ -100,23 +102,23 @@ function plugin_example_giveItem($type,$ID,$data,$num) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_displayConfigItem($type, $ID, $data, $num) {
|
||||
|
||||
$searchopt = &Search::getOptions($type);
|
||||
$table = $searchopt[$ID]["table"];
|
||||
$field = $searchopt[$ID]["field"];
|
||||
|
||||
|
||||
// Example of specific style options
|
||||
// No need of the function if you do not have specific cases
|
||||
switch ($table.'.'.$field) {
|
||||
case "glpi_plugin_example_examples.name" :
|
||||
return " style=\"background-color:#DDDDDD;\" ";
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables) {
|
||||
|
||||
// Example of default JOIN clause
|
||||
@ -126,11 +128,11 @@ function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables)
|
||||
case "MyType" :
|
||||
return Search::addLeftJoin($type, $ref_table, $already_link_tables,
|
||||
"newtable", "linkfield");
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addDefaultSelect($type) {
|
||||
|
||||
// Example of default SELECT item to be added
|
||||
@ -139,11 +141,11 @@ function plugin_example_addDefaultSelect($type) {
|
||||
// case "PluginExampleExample" :
|
||||
case "MyType" :
|
||||
return "`mytable`.`myfield` = 'myvalue' AS MYNAME, ";
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_addDefaultWhere($type) {
|
||||
|
||||
// Example of default WHERE item to be added
|
||||
@ -152,7 +154,6 @@ function plugin_example_addDefaultWhere($type) {
|
||||
// case "PluginExampleExample" :
|
||||
case "MyType" :
|
||||
return " `mytable`.`myfield` = 'myvalue' ";
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@ -291,8 +292,8 @@ function plugin_example_MassiveActionsDisplay($options=array()) {
|
||||
case 'Computer' :
|
||||
switch ($options['action']) {
|
||||
case "plugin_example_DoIt" :
|
||||
|
||||
echo " <input type='hidden' name='toto' value='1'><input type='submit' name='massiveaction' class='submit' value='".
|
||||
echo " <input type='hidden' name='toto' value='1'>".
|
||||
"<input type='submit' name='massiveaction' class='submit' value='".
|
||||
$LANG["buttons"][2]."'> but do nothing :)";
|
||||
break;
|
||||
}
|
||||
@ -319,13 +320,13 @@ function plugin_example_MassiveActionsProcess($data) {
|
||||
switch ($data['action']) {
|
||||
case 'plugin_example_DoIt' :
|
||||
if ($data['itemtype'] == 'Computer') {
|
||||
$comp = new Computer;
|
||||
addMessageAfterRedirect("Right it is the type I want...");
|
||||
addMessageAfterRedirect("But... I say I will do nothing for :");
|
||||
$comp = new Computer();
|
||||
Session::addMessageAfterRedirect("Right it is the type I want...");
|
||||
Session::addMessageAfterRedirect("But... I say I will do nothing for :");
|
||||
foreach ($data['item'] as $key => $val) {
|
||||
if ($val == 1) {
|
||||
if ($comp->getFromDB($key)) {
|
||||
addMessageAfterRedirect("- ".$comp->getField("name"));
|
||||
Session::addMessageAfterRedirect("- ".$comp->getField("name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -335,12 +336,12 @@ function plugin_example_MassiveActionsProcess($data) {
|
||||
case 'do_nothing' :
|
||||
if ($data['itemtype'] == 'PluginExampleExample') {
|
||||
$ex = new PluginExampleExample();
|
||||
addMessageAfterRedirect("Right it is the type I want...");
|
||||
addMessageAfterRedirect("But... I say I will do nothing for :");
|
||||
Session::addMessageAfterRedirect("Right it is the type I want...");
|
||||
Session::addMessageAfterRedirect("But... I say I will do nothing for :");
|
||||
foreach ($data['item'] as $key => $val) {
|
||||
if ($val == 1) {
|
||||
if ($ex->getFromDB($key)) {
|
||||
addMessageAfterRedirect("- ".$ex->getField("name"));
|
||||
Session::addMessageAfterRedirect("- ".$ex->getField("name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -358,8 +359,8 @@ function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
|
||||
$table = $options['options']['table'];
|
||||
$field = $options['options']['field'];
|
||||
$linkfield = $options['options']['linkfield'];
|
||||
if ($table == getTableForItemType($options['itemtype'])) {
|
||||
|
||||
if ($table == getTableForItemType($options['itemtype'])) {
|
||||
// Table fields
|
||||
switch ($table.".".$field) {
|
||||
case 'glpi_plugin_example_examples.serial' :
|
||||
@ -383,6 +384,7 @@ function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// How to display specific search fields or dropdown ?
|
||||
// options must contain at least itemtype and options array
|
||||
// MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration
|
||||
@ -394,7 +396,6 @@ function plugin_example_searchOptionsValues($options=array()) {
|
||||
|
||||
// Table fields
|
||||
switch ($table.".".$field) {
|
||||
|
||||
case "glpi_plugin_example_examples.serial" :
|
||||
echo "Not really specific - Use your own dropdown - Just for example ";
|
||||
Dropdown::show(getItemTypeForTable($options['searchoption']['table']),
|
||||
@ -430,6 +431,7 @@ function plugin_item_update_example($item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on get empty item case
|
||||
function plugin_item_empty_example($item) {
|
||||
|
||||
@ -485,6 +487,7 @@ function plugin_pre_item_restore_example2($item) {
|
||||
Session::addMessageAfterRedirect("Pre Restore Phone Hook");
|
||||
}
|
||||
|
||||
|
||||
// Hook done on restore item case
|
||||
function plugin_item_restore_example($item) {
|
||||
|
||||
@ -558,18 +561,16 @@ function plugin_get_headings_example($item, $withtemplate) {
|
||||
$prof = new Profile();
|
||||
if ($item->fields['interface'] == 'central') {
|
||||
return array(1 => "Test PLugin");
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
return array();
|
||||
|
||||
case 'Computer' :
|
||||
// new object / template case
|
||||
if ($withtemplate) {
|
||||
return array();
|
||||
// Non template case / editing an existing object
|
||||
} else {
|
||||
return array(1 => "Test PLugin");
|
||||
}
|
||||
return array(1 => "Test PLugin");
|
||||
|
||||
case 'ComputerDisk' :
|
||||
case 'Supplier' :
|
||||
@ -781,14 +782,17 @@ function plugin_example_AssignToTicket($types) {
|
||||
return $types;
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_get_events(NotificationTargetTicket $target) {
|
||||
$target->events['plugin_example'] = "Example event";
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_get_datas(NotificationTargetTicket $target) {
|
||||
$target->datas['##ticket.example##'] = "Example datas";
|
||||
}
|
||||
|
||||
|
||||
function plugin_example_postinit() {
|
||||
global $CFG_GLPI;
|
||||
|
||||
|
@ -36,23 +36,24 @@
|
||||
// Class of the defined type
|
||||
class PluginExampleExample extends CommonDBTM {
|
||||
|
||||
// From CommonDBTM
|
||||
public $table = 'glpi_plugin_example_examples';
|
||||
public $type = 'PluginExampleExample';
|
||||
|
||||
// Should return the localized name of the type
|
||||
static function getTypeName() {
|
||||
return 'Example Type';
|
||||
}
|
||||
|
||||
|
||||
function canCreate() {
|
||||
|
||||
if (isset($_SESSION["glpi_plugin_example_profile"])) {
|
||||
return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function canView() {
|
||||
|
||||
if (isset($_SESSION["glpi_plugin_example_profile"])) {
|
||||
return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w'
|
||||
|| $_SESSION["glpi_plugin_example_profile"]['example'] == 'r');
|
||||
@ -60,6 +61,7 @@ class PluginExampleExample extends CommonDBTM {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function getSearchOptions() {
|
||||
global $LANG;
|
||||
|
||||
@ -87,6 +89,7 @@ class PluginExampleExample extends CommonDBTM {
|
||||
return $tab;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give localized information about 1 task
|
||||
*
|
||||
@ -105,6 +108,7 @@ class PluginExampleExample extends CommonDBTM {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute 1 task manage by the plugin
|
||||
*
|
||||
@ -123,16 +127,17 @@ class PluginExampleExample extends CommonDBTM {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Hook done on before add item case
|
||||
static function pre_item_add_example($item) {
|
||||
addMessageAfterRedirect("Pre Add Computer Hook",true);
|
||||
Session::addMessageAfterRedirect("Pre Add Computer Hook", true);
|
||||
}
|
||||
|
||||
|
||||
// Hook done on add item case
|
||||
static function item_add_example($item) {
|
||||
|
||||
addMessageAfterRedirect("Add Computer Hook, ID=".$item->getField('id'),true);
|
||||
Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getField('id'), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@ if (!defined('GLPI_ROOT')){
|
||||
class PluginExampleNotificationTargetExample extends NotificationTarget {
|
||||
|
||||
function getEvents() {
|
||||
global $LANG;
|
||||
return array ('alert' => 'alert example');
|
||||
}
|
||||
|
||||
|
@ -50,18 +50,20 @@ class PluginExampleRuleTest extends Rule {
|
||||
public $right = 'rule_ocs';
|
||||
public $can_sort = true;
|
||||
|
||||
function getTitle() {
|
||||
global $LANG;
|
||||
|
||||
function getTitle() {
|
||||
return 'test';
|
||||
}
|
||||
|
||||
|
||||
function maxActionsCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
function getCriterias() {
|
||||
global $LANG;
|
||||
|
||||
$criterias = array();
|
||||
$criterias['name']['field'] = 'name';
|
||||
$criterias['name']['name'] = $LANG['help'][31];
|
||||
@ -70,8 +72,10 @@ class PluginExampleRuleTest extends Rule {
|
||||
return $criterias;
|
||||
}
|
||||
|
||||
|
||||
function getActions() {
|
||||
global $LANG;
|
||||
|
||||
$actions = array();
|
||||
$actions['softwarecategories_id']['name'] = $LANG['common'][36];
|
||||
$actions['softwarecategories_id']['type'] = 'dropdown';
|
||||
@ -79,5 +83,4 @@ class PluginExampleRuleTest extends Rule {
|
||||
return $actions;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -45,10 +45,7 @@ class PluginExampleRuleTestCollection extends RuleCollection {
|
||||
public $menu_option = 'test';
|
||||
|
||||
function getTitle() {
|
||||
global $LANG;
|
||||
|
||||
return 'Rulesengine test';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -112,10 +112,12 @@ function plugin_init_example() {
|
||||
|
||||
// Add event to GLPI core itemtype, event will be raised by the plugin.
|
||||
// See plugin_example_uninstall for cleanup of notification
|
||||
$PLUGIN_HOOKS['item_get_events']['example'] = array('NotificationTargetTicket'=>'plugin_example_get_events');
|
||||
$PLUGIN_HOOKS['item_get_events']['example']
|
||||
= array('NotificationTargetTicket' => 'plugin_example_get_events');
|
||||
|
||||
// Add datas to GLPI core itemtype for notifications template.
|
||||
$PLUGIN_HOOKS['item_get_datas']['example'] = array('NotificationTargetTicket'=>'plugin_example_get_datas');
|
||||
$PLUGIN_HOOKS['item_get_datas']['example']
|
||||
= array('NotificationTargetTicket' => 'plugin_example_get_datas');
|
||||
|
||||
$PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example';
|
||||
|
||||
@ -188,11 +190,10 @@ function plugin_example_check_config($verbose=false) {
|
||||
if (true) { // Your configuration check
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($verbose) {
|
||||
echo $LANG['plugins'][2];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user