mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
Fix coding standards violations
This commit is contained in:
parent
72a8c561ea
commit
da86b4e48a
54
hook.php
54
hook.php
@ -37,10 +37,10 @@
|
|||||||
function plugin_change_profile_example() {
|
function plugin_change_profile_example() {
|
||||||
// For example : same right of computer
|
// For example : same right of computer
|
||||||
if (Session::haveRight('computer', UPDATE)) {
|
if (Session::haveRight('computer', UPDATE)) {
|
||||||
$_SESSION["glpi_plugin_example_profile"] = array('example' => 'w');
|
$_SESSION["glpi_plugin_example_profile"] = ['example' => 'w'];
|
||||||
|
|
||||||
} else if (Session::haveRight('computer', READ)) {
|
} else if (Session::haveRight('computer', READ)) {
|
||||||
$_SESSION["glpi_plugin_example_profile"] = array('example' => 'r');
|
$_SESSION["glpi_plugin_example_profile"] = ['example' => 'r'];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
unset($_SESSION["glpi_plugin_example_profile"]);
|
unset($_SESSION["glpi_plugin_example_profile"]);
|
||||||
@ -50,14 +50,14 @@ function plugin_change_profile_example() {
|
|||||||
|
|
||||||
// Define dropdown relations
|
// Define dropdown relations
|
||||||
function plugin_example_getDatabaseRelations() {
|
function plugin_example_getDatabaseRelations() {
|
||||||
return array("glpi_plugin_example_dropdowns" => array("glpi_plugin_example" => "plugin_example_dropdowns_id"));
|
return ["glpi_plugin_example_dropdowns" => ["glpi_plugin_example" => "plugin_example_dropdowns_id"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Define Dropdown tables to be manage in GLPI :
|
// Define Dropdown tables to be manage in GLPI :
|
||||||
function plugin_example_getDropdown() {
|
function plugin_example_getDropdown() {
|
||||||
// Table => Name
|
// Table => Name
|
||||||
return array('PluginExampleDropdown' => __("Plugin Example Dropdown", 'example'));
|
return ['PluginExampleDropdown' => __("Plugin Example Dropdown", 'example')];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ function plugin_example_getDropdown() {
|
|||||||
|
|
||||||
// Define Additionnal search options for types (other than the plugin ones)
|
// Define Additionnal search options for types (other than the plugin ones)
|
||||||
function plugin_example_getAddSearchOptions($itemtype) {
|
function plugin_example_getAddSearchOptions($itemtype) {
|
||||||
$sopt = array();
|
$sopt = [];
|
||||||
if ($itemtype == 'Computer') {
|
if ($itemtype == 'Computer') {
|
||||||
// Just for example, not working...
|
// Just for example, not working...
|
||||||
$sopt[1001]['table'] = 'glpi_plugin_example_dropdowns';
|
$sopt[1001]['table'] = 'glpi_plugin_example_dropdowns';
|
||||||
@ -93,7 +93,7 @@ function plugin_example_getAddSearchOptionsNew($itemtype) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See also PluginExampleExample::getSpecificValueToDisplay()
|
// See also PluginExampleExample::getSpecificValueToDisplay()
|
||||||
function plugin_example_giveItem($type,$ID,$data,$num) {
|
function plugin_example_giveItem($type, $ID, $data, $num) {
|
||||||
$searchopt = &Search::getOptions($type);
|
$searchopt = &Search::getOptions($type);
|
||||||
$table = $searchopt[$ID]["table"];
|
$table = $searchopt[$ID]["table"];
|
||||||
$field = $searchopt[$ID]["field"];
|
$field = $searchopt[$ID]["field"];
|
||||||
@ -231,7 +231,7 @@ function plugin_example_addHaving($link, $nott, $type, $ID, $val, $num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function plugin_example_addSelect($type,$ID,$num) {
|
function plugin_example_addSelect($type, $ID, $num) {
|
||||||
$searchopt = &Search::getOptions($type);
|
$searchopt = &Search::getOptions($type);
|
||||||
$table = $searchopt[$ID]["table"];
|
$table = $searchopt[$ID]["table"];
|
||||||
$field = $searchopt[$ID]["field"];
|
$field = $searchopt[$ID]["field"];
|
||||||
@ -246,7 +246,7 @@ function plugin_example_addSelect($type,$ID,$num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function plugin_example_addOrderBy($type,$ID,$order,$key=0) {
|
function plugin_example_addOrderBy($type, $ID, $order, $key = 0) {
|
||||||
$searchopt = &Search::getOptions($type);
|
$searchopt = &Search::getOptions($type);
|
||||||
$table = $searchopt[$ID]["table"];
|
$table = $searchopt[$ID]["table"];
|
||||||
$field = $searchopt[$ID]["field"];
|
$field = $searchopt[$ID]["field"];
|
||||||
@ -270,18 +270,18 @@ function plugin_example_MassiveActions($type) {
|
|||||||
switch ($type) {
|
switch ($type) {
|
||||||
// New action for core and other plugin types : name = plugin_PLUGINNAME_actionname
|
// New action for core and other plugin types : name = plugin_PLUGINNAME_actionname
|
||||||
case 'Computer' :
|
case 'Computer' :
|
||||||
return array('PluginExampleExample'.MassiveAction::CLASS_ACTION_SEPARATOR.'DoIt' =>
|
return ['PluginExampleExample'.MassiveAction::CLASS_ACTION_SEPARATOR.'DoIt' =>
|
||||||
__("plugin_example_DoIt", 'example'));
|
__("plugin_example_DoIt", 'example')];
|
||||||
|
|
||||||
// Actions for types provided by the plugin are included inside the classes
|
// Actions for types provided by the plugin are included inside the classes
|
||||||
}
|
}
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// How to display specific update fields ?
|
// How to display specific update fields ?
|
||||||
// options must contain at least itemtype and options array
|
// options must contain at least itemtype and options array
|
||||||
function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
|
function plugin_example_MassiveActionsFieldsDisplay($options = []) {
|
||||||
//$type,$table,$field,$linkfield
|
//$type,$table,$field,$linkfield
|
||||||
|
|
||||||
$table = $options['options']['table'];
|
$table = $options['options']['table'];
|
||||||
@ -316,7 +316,7 @@ function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
|
|||||||
// How to display specific search fields or dropdown ?
|
// How to display specific search fields or dropdown ?
|
||||||
// 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 = []) {
|
||||||
$table = $options['searchoption']['table'];
|
$table = $options['searchoption']['table'];
|
||||||
$field = $options['searchoption']['field'];
|
$field = $options['searchoption']['field'];
|
||||||
|
|
||||||
@ -325,9 +325,9 @@ function plugin_example_searchOptionsValues($options=array()) {
|
|||||||
case "glpi_plugin_example_examples.serial" :
|
case "glpi_plugin_example_examples.serial" :
|
||||||
echo __("Not really specific - Use your own dropdown - Just for example", 'example');
|
echo __("Not really specific - Use your own dropdown - Just for example", 'example');
|
||||||
Dropdown::show(getItemTypeForTable($options['searchoption']['table']),
|
Dropdown::show(getItemTypeForTable($options['searchoption']['table']),
|
||||||
array('value' => $options['value'],
|
['value' => $options['value'],
|
||||||
'name' => $options['name'],
|
'name' => $options['name'],
|
||||||
'comments' => 0));
|
'comments' => 0]);
|
||||||
// Need to return true if specific display
|
// Need to return true if specific display
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -447,9 +447,9 @@ function plugin_example_addParamFordynamicReport($itemtype) {
|
|||||||
if ($itemtype == 'PluginExampleExample') {
|
if ($itemtype == 'PluginExampleExample') {
|
||||||
// Return array data containing all params to add : may be single data or array data
|
// Return array data containing all params to add : may be single data or array data
|
||||||
// Search config are available from session variable
|
// Search config are available from session variable
|
||||||
return array('add1' => $_SESSION['glpisearch'][$itemtype]['order'],
|
return ['add1' => $_SESSION['glpisearch'][$itemtype]['order'],
|
||||||
'add2' => array('tutu' => 'Second Add',
|
'add2' => ['tutu' => 'Second Add',
|
||||||
'Other Data'));
|
'Other Data']];
|
||||||
}
|
}
|
||||||
// Return false or a non array data if not needed
|
// Return false or a non array data if not needed
|
||||||
return false;
|
return false;
|
||||||
@ -465,9 +465,9 @@ function plugin_example_install() {
|
|||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
$config->setConfigurationValues('plugin:Example', array('configuration' => false));
|
$config->setConfigurationValues('plugin:Example', ['configuration' => false]);
|
||||||
|
|
||||||
ProfileRight::addProfileRights(array('example:read'));
|
ProfileRight::addProfileRights(['example:read']);
|
||||||
|
|
||||||
if (!$DB->tableExists("glpi_plugin_example_examples")) {
|
if (!$DB->tableExists("glpi_plugin_example_examples")) {
|
||||||
$query = "CREATE TABLE `glpi_plugin_example_examples` (
|
$query = "CREATE TABLE `glpi_plugin_example_examples` (
|
||||||
@ -546,7 +546,7 @@ function plugin_example_install() {
|
|||||||
|
|
||||||
// To be called for each task the plugin manage
|
// To be called for each task the plugin manage
|
||||||
// task in class
|
// task in class
|
||||||
CronTask::Register('PluginExampleExample', 'Sample', DAY_TIMESTAMP, array('param' => 50));
|
CronTask::Register('PluginExampleExample', 'Sample', DAY_TIMESTAMP, ['param' => 50]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,14 +560,14 @@ function plugin_example_uninstall() {
|
|||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
$config->deleteConfigurationValues('plugin:Example', array('configuration' => false));
|
$config->deleteConfigurationValues('plugin:Example', ['configuration' => false]);
|
||||||
|
|
||||||
ProfileRight::deleteProfileRights(array('example:read'));
|
ProfileRight::deleteProfileRights(['example:read']);
|
||||||
|
|
||||||
$notif = new Notification();
|
$notif = new Notification();
|
||||||
$options = array('itemtype' => 'Ticket',
|
$options = ['itemtype' => 'Ticket',
|
||||||
'event' => 'plugin_example',
|
'event' => 'plugin_example',
|
||||||
'FIELDS' => 'id');
|
'FIELDS' => 'id'];
|
||||||
foreach ($DB->request('glpi_notifications', $options) as $data) {
|
foreach ($DB->request('glpi_notifications', $options) as $data) {
|
||||||
$notif->delete($data);
|
$notif->delete($data);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class PluginExampleConfig extends CommonDBTM {
|
|||||||
|
|
||||||
static protected $notable = true;
|
static protected $notable = true;
|
||||||
|
|
||||||
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
|
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
||||||
|
|
||||||
if (!$withtemplate) {
|
if (!$withtemplate) {
|
||||||
if ($item->getType() == 'Config') {
|
if ($item->getType() == 'Config') {
|
||||||
@ -75,7 +75,7 @@ class PluginExampleConfig extends CommonDBTM {
|
|||||||
Html::closeForm();
|
Html::closeForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
|
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
||||||
|
|
||||||
if ($item->getType() == 'Config') {
|
if ($item->getType() == 'Config') {
|
||||||
$config = new self();
|
$config = new self();
|
||||||
|
@ -41,7 +41,7 @@ if (!defined('GLPI_ROOT')) {
|
|||||||
/// Class DeviceCamera
|
/// Class DeviceCamera
|
||||||
class PluginExampleDeviceCamera extends CommonDevice {
|
class PluginExampleDeviceCamera extends CommonDevice {
|
||||||
|
|
||||||
static function getTypeName($nb=0) {
|
static function getTypeName($nb = 0) {
|
||||||
return _n('Camera', 'Cameras', $nb);
|
return _n('Camera', 'Cameras', $nb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
class PluginExampleDropdown extends CommonDropdown {
|
class PluginExampleDropdown extends CommonDropdown {
|
||||||
|
|
||||||
|
|
||||||
static function getTypeName($nb=0) {
|
static function getTypeName($nb = 0) {
|
||||||
|
|
||||||
if ($nb > 0) {
|
if ($nb > 0) {
|
||||||
return __('Plugin Example Dropdowns', 'example');
|
return __('Plugin Example Dropdowns', 'example');
|
||||||
|
@ -75,7 +75,7 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
**/
|
**/
|
||||||
static function getAdditionalMenuLinks() {
|
static function getAdditionalMenuLinks() {
|
||||||
global $CFG_GLPI;
|
global $CFG_GLPI;
|
||||||
$links = array();
|
$links = [];
|
||||||
|
|
||||||
$links['config'] = '/plugins/example/index.php';
|
$links['config'] = '/plugins/example/index.php';
|
||||||
$links["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".__s('Show all')."' alt='".__s('Show all')."'>"] = '/plugins/example/index.php';
|
$links["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".__s('Show all')."' alt='".__s('Show all')."'>"] = '/plugins/example/index.php';
|
||||||
@ -84,16 +84,16 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
return $links;
|
return $links;
|
||||||
}
|
}
|
||||||
|
|
||||||
function defineTabs($options = array()) {
|
function defineTabs($options = []) {
|
||||||
|
|
||||||
$ong = array();
|
$ong = [];
|
||||||
$this->addDefaultFormTab($ong);
|
$this->addDefaultFormTab($ong);
|
||||||
$this->addStandardTab('Link', $ong, $options);
|
$this->addStandardTab('Link', $ong, $options);
|
||||||
|
|
||||||
return $ong;
|
return $ong;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showForm($ID, $options = array()) {
|
function showForm($ID, $options = []) {
|
||||||
global $CFG_GLPI;
|
global $CFG_GLPI;
|
||||||
|
|
||||||
$this->initForm($ID, $options);
|
$this->initForm($ID, $options);
|
||||||
@ -167,10 +167,10 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
|
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'Sample' :
|
case 'Sample' :
|
||||||
return array('description' => __('Cron description for example', 'example'),
|
return ['description' => __('Cron description for example', 'example'),
|
||||||
'parameter' => __('Cron parameter for example', 'example'));
|
'parameter' => __('Cron parameter for example', 'example')];
|
||||||
}
|
}
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -206,20 +206,20 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hook done on before add item case (data altered by object prepareInputForAdd)
|
// Hook done on before add item case (data altered by object prepareInputForAdd)
|
||||||
static function post_prepareadd_computer(Computer$item) {
|
static function post_prepareadd_computer(Computer $item) {
|
||||||
Session::addMessageAfterRedirect("Post prepareAdd Computer Hook", true);
|
Session::addMessageAfterRedirect("Post prepareAdd Computer Hook", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Hook done on add item case
|
// Hook done on add item case
|
||||||
static function item_add_computer(Computer$item) {
|
static function item_add_computer(Computer $item) {
|
||||||
|
|
||||||
Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getID(), true);
|
Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getID(), true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
|
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
||||||
|
|
||||||
if (!$withtemplate) {
|
if (!$withtemplate) {
|
||||||
switch ($item->getType()) {
|
switch ($item->getType()) {
|
||||||
@ -238,14 +238,14 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
|
|
||||||
case 'ComputerDisk' :
|
case 'ComputerDisk' :
|
||||||
case 'Supplier' :
|
case 'Supplier' :
|
||||||
return array(1 => __("Test Plugin", 'example'),
|
return [1 => __("Test Plugin", 'example'),
|
||||||
2 => __("Test Plugin 2", 'example'));
|
2 => __("Test Plugin 2", 'example')];
|
||||||
|
|
||||||
case 'Computer' :
|
case 'Computer' :
|
||||||
case 'Central' :
|
case 'Central' :
|
||||||
case 'Preference':
|
case 'Preference':
|
||||||
case 'Notification':
|
case 'Notification':
|
||||||
return array(1 => __("Test Plugin", 'example'));
|
return [1 => __("Test Plugin", 'example')];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
|
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
||||||
|
|
||||||
switch ($item->getType()) {
|
switch ($item->getType()) {
|
||||||
case 'Phone' :
|
case 'Phone' :
|
||||||
@ -304,10 +304,10 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getSpecificValueToDisplay($field, $values, array $options=array()) {
|
static function getSpecificValueToDisplay($field, $values, array $options = []) {
|
||||||
|
|
||||||
if (!is_array($values)) {
|
if (!is_array($values)) {
|
||||||
$values = array($field => $values);
|
$values = [$field => $values];
|
||||||
}
|
}
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case 'serial' :
|
case 'serial' :
|
||||||
@ -323,7 +323,7 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
// 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
|
||||||
$output = array();
|
$output = [];
|
||||||
$key = $parm["begin"]."$$$"."plugin_example1";
|
$key = $parm["begin"]."$$$"."plugin_example1";
|
||||||
$output[$key]["begin"] = date("Y-m-d 17:00:00");
|
$output[$key]["begin"] = date("Y-m-d 17:00:00");
|
||||||
$output[$key]["end"] = date("Y-m-d 18:00:00");
|
$output[$key]["end"] = date("Y-m-d 18:00:00");
|
||||||
@ -345,7 +345,7 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
*
|
*
|
||||||
* @return Nothing (display function)
|
* @return Nothing (display function)
|
||||||
**/
|
**/
|
||||||
static function displayPlanningItem(array $val, $who, $type="", $complete=0) {
|
static function displayPlanningItem(array $val, $who, $type = "", $complete = 0) {
|
||||||
|
|
||||||
// $parm["type"] say begin end in or from type
|
// $parm["type"] say begin end in or from type
|
||||||
// Add items in the items fields of the parm array
|
// Add items in the items fields of the parm array
|
||||||
@ -401,7 +401,7 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
*
|
*
|
||||||
* @see CommonDBTM::getSpecificMassiveActions()
|
* @see CommonDBTM::getSpecificMassiveActions()
|
||||||
**/
|
**/
|
||||||
function getSpecificMassiveActions($checkitem=NULL) {
|
function getSpecificMassiveActions($checkitem = null) {
|
||||||
|
|
||||||
$actions = parent::getSpecificMassiveActions($checkitem);
|
$actions = parent::getSpecificMassiveActions($checkitem);
|
||||||
|
|
||||||
@ -424,11 +424,11 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
switch ($ma->getAction()) {
|
switch ($ma->getAction()) {
|
||||||
case 'DoIt':
|
case 'DoIt':
|
||||||
echo " <input type='hidden' name='toto' value='1'>".
|
echo " <input type='hidden' name='toto' value='1'>".
|
||||||
Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')).
|
Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']).
|
||||||
" ".__('Write in item history', 'example');
|
" ".__('Write in item history', 'example');
|
||||||
return true;
|
return true;
|
||||||
case 'do_nothing' :
|
case 'do_nothing' :
|
||||||
echo " ".Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')).
|
echo " ".Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']).
|
||||||
" ".__('but do nothing :)', 'example');
|
" ".__('but do nothing :)', 'example');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -450,7 +450,7 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
if ($item->getType() == 'Computer') {
|
if ($item->getType() == 'Computer') {
|
||||||
Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
|
Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
|
||||||
Session::addMessageAfterRedirect(__('Write in item history', 'example'));
|
Session::addMessageAfterRedirect(__('Write in item history', 'example'));
|
||||||
$changes = array(0, 'old value', 'new value');
|
$changes = [0, 'old value', 'new value'];
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
if ($item->getFromDB($id)) {
|
if ($item->getFromDB($id)) {
|
||||||
Session::addMessageAfterRedirect("- ".$item->getField("name"));
|
Session::addMessageAfterRedirect("- ".$item->getField("name"));
|
||||||
@ -494,7 +494,7 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
|
|
||||||
if (strstr($link, "[EXAMPLE_ID]")) {
|
if (strstr($link, "[EXAMPLE_ID]")) {
|
||||||
$link = str_replace("[EXAMPLE_ID]", $item->getID(), $link);
|
$link = str_replace("[EXAMPLE_ID]", $item->getID(), $link);
|
||||||
return array($link);
|
return [$link];
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::generateLinkContents($link, $item);
|
return parent::generateLinkContents($link, $item);
|
||||||
|
@ -35,10 +35,10 @@ if (!defined('GLPI_ROOT')) {
|
|||||||
class PluginExampleNotificationTargetExample extends NotificationTarget {
|
class PluginExampleNotificationTargetExample extends NotificationTarget {
|
||||||
|
|
||||||
function getEvents() {
|
function getEvents() {
|
||||||
return array ('alert' => 'alert example');
|
return ['alert' => 'alert example'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDataForTemplate($event, $options=array()) {
|
function addDataForTemplate($event, $options = []) {
|
||||||
global $DB, $CFG_GLPI;
|
global $DB, $CFG_GLPI;
|
||||||
|
|
||||||
$this->data['##example.name##'] = __('Example', 'example');
|
$this->data['##example.name##'] = __('Example', 'example');
|
||||||
|
@ -62,7 +62,7 @@ class PluginExampleRuleTest extends Rule {
|
|||||||
|
|
||||||
function getCriterias() {
|
function getCriterias() {
|
||||||
|
|
||||||
$criterias = array();
|
$criterias = [];
|
||||||
$criterias['name']['field'] = 'name';
|
$criterias['name']['field'] = 'name';
|
||||||
$criterias['name']['name'] = __('Software');
|
$criterias['name']['name'] = __('Software');
|
||||||
$criterias['name']['table'] = 'glpi_softwares';
|
$criterias['name']['table'] = 'glpi_softwares';
|
||||||
@ -73,7 +73,7 @@ class PluginExampleRuleTest extends Rule {
|
|||||||
|
|
||||||
function getActions() {
|
function getActions() {
|
||||||
|
|
||||||
$actions = array();
|
$actions = [];
|
||||||
$actions['softwarecategories_id']['name'] = __('Category (class)', 'example');
|
$actions['softwarecategories_id']['name'] = __('Category (class)', 'example');
|
||||||
$actions['softwarecategories_id']['type'] = 'dropdown';
|
$actions['softwarecategories_id']['type'] = 'dropdown';
|
||||||
$actions['softwarecategories_id']['table'] = 'glpi_softwarecategories';
|
$actions['softwarecategories_id']['table'] = 'glpi_softwarecategories';
|
||||||
|
84
setup.php
84
setup.php
@ -48,23 +48,23 @@ function plugin_init_example() {
|
|||||||
// array('classname' => 'PluginExampleExample',
|
// array('classname' => 'PluginExampleExample',
|
||||||
// ));
|
// ));
|
||||||
|
|
||||||
Plugin::registerClass('PluginExampleConfig', array('addtabon' => 'Config'));
|
Plugin::registerClass('PluginExampleConfig', ['addtabon' => 'Config']);
|
||||||
|
|
||||||
// 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',
|
$types = ['Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone',
|
||||||
'Preference', 'Profile', 'Supplier');
|
'Preference', 'Profile', 'Supplier'];
|
||||||
Plugin::registerClass('PluginExampleExample',
|
Plugin::registerClass('PluginExampleExample',
|
||||||
array('notificationtemplates_types' => true,
|
['notificationtemplates_types' => true,
|
||||||
'addtabon' => $types,
|
'addtabon' => $types,
|
||||||
'link_types' => true));
|
'link_types' => true]);
|
||||||
|
|
||||||
Plugin::registerClass('PluginExampleRuleTestCollection',
|
Plugin::registerClass('PluginExampleRuleTestCollection',
|
||||||
array('rulecollections_types' => true));
|
['rulecollections_types' => true]);
|
||||||
|
|
||||||
Plugin::registerClass('PluginExampleDeviceCamera',
|
Plugin::registerClass('PluginExampleDeviceCamera',
|
||||||
array('device_types' => true));
|
['device_types' => true]);
|
||||||
|
|
||||||
if (version_compare(GLPI_VERSION, '9.1', 'ge')) {
|
if (version_compare(GLPI_VERSION, '9.1', 'ge')) {
|
||||||
if (class_exists('PluginExampleExample')) {
|
if (class_exists('PluginExampleExample')) {
|
||||||
@ -74,8 +74,8 @@ function plugin_init_example() {
|
|||||||
// Display a menu entry ?
|
// Display a menu entry ?
|
||||||
$_SESSION["glpi_plugin_example_profile"]['example'] = 'w';
|
$_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'] = ['plugins' => 'PluginExampleExample',
|
||||||
'tools' => 'PluginExampleExample');
|
'tools' => 'PluginExampleExample'];
|
||||||
|
|
||||||
// Old menu style
|
// Old menu style
|
||||||
// $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php';
|
// $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php';
|
||||||
@ -104,45 +104,45 @@ function plugin_init_example() {
|
|||||||
//$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example';
|
//$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example';
|
||||||
|
|
||||||
// Item action event // See define.php for defined ITEM_TYPE
|
// Item action event // See define.php for defined ITEM_TYPE
|
||||||
$PLUGIN_HOOKS['pre_item_update']['example'] = array('Computer' => 'plugin_pre_item_update_example');
|
$PLUGIN_HOOKS['pre_item_update']['example'] = ['Computer' => 'plugin_pre_item_update_example'];
|
||||||
$PLUGIN_HOOKS['item_update']['example'] = array('Computer' => 'plugin_item_update_example');
|
$PLUGIN_HOOKS['item_update']['example'] = ['Computer' => 'plugin_item_update_example'];
|
||||||
|
|
||||||
$PLUGIN_HOOKS['item_empty']['example'] = array('Computer' => 'plugin_item_empty_example');
|
$PLUGIN_HOOKS['item_empty']['example'] = ['Computer' => 'plugin_item_empty_example'];
|
||||||
|
|
||||||
// Restrict right
|
// Restrict right
|
||||||
$PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'item_can']];
|
$PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'item_can']];
|
||||||
$PLUGIN_HOOKS['add_default_where']['example'] = ['Computer' => ['PluginExampleComputer', 'add_default_where']];
|
$PLUGIN_HOOKS['add_default_where']['example'] = ['Computer' => ['PluginExampleComputer', 'add_default_where']];
|
||||||
|
|
||||||
// Example using a method in class
|
// Example using a method in class
|
||||||
$PLUGIN_HOOKS['pre_item_add']['example'] = array('Computer' => array('PluginExampleExample',
|
$PLUGIN_HOOKS['pre_item_add']['example'] = ['Computer' => ['PluginExampleExample',
|
||||||
'pre_item_add_computer'));
|
'pre_item_add_computer']];
|
||||||
$PLUGIN_HOOKS['post_prepareadd']['example'] = array('Computer' => array('PluginExampleExample',
|
$PLUGIN_HOOKS['post_prepareadd']['example'] = ['Computer' => ['PluginExampleExample',
|
||||||
'post_prepareadd_computer'));
|
'post_prepareadd_computer']];
|
||||||
$PLUGIN_HOOKS['item_add']['example'] = array('Computer' => array('PluginExampleExample',
|
$PLUGIN_HOOKS['item_add']['example'] = ['Computer' => ['PluginExampleExample',
|
||||||
'item_add_computer'));
|
'item_add_computer']];
|
||||||
|
|
||||||
$PLUGIN_HOOKS['pre_item_delete']['example'] = array('Computer' => 'plugin_pre_item_delete_example');
|
$PLUGIN_HOOKS['pre_item_delete']['example'] = ['Computer' => 'plugin_pre_item_delete_example'];
|
||||||
$PLUGIN_HOOKS['item_delete']['example'] = array('Computer' => 'plugin_item_delete_example');
|
$PLUGIN_HOOKS['item_delete']['example'] = ['Computer' => 'plugin_item_delete_example'];
|
||||||
|
|
||||||
// Example using the same function
|
// Example using the same function
|
||||||
$PLUGIN_HOOKS['pre_item_purge']['example'] = array('Computer' => 'plugin_pre_item_purge_example',
|
$PLUGIN_HOOKS['pre_item_purge']['example'] = ['Computer' => 'plugin_pre_item_purge_example',
|
||||||
'Phone' => 'plugin_pre_item_purge_example');
|
'Phone' => 'plugin_pre_item_purge_example'];
|
||||||
$PLUGIN_HOOKS['item_purge']['example'] = array('Computer' => 'plugin_item_purge_example',
|
$PLUGIN_HOOKS['item_purge']['example'] = ['Computer' => 'plugin_item_purge_example',
|
||||||
'Phone' => 'plugin_item_purge_example');
|
'Phone' => 'plugin_item_purge_example'];
|
||||||
|
|
||||||
// Example with 2 different functions
|
// Example with 2 different functions
|
||||||
$PLUGIN_HOOKS['pre_item_restore']['example'] = array('Computer' => 'plugin_pre_item_restore_example',
|
$PLUGIN_HOOKS['pre_item_restore']['example'] = ['Computer' => 'plugin_pre_item_restore_example',
|
||||||
'Phone' => 'plugin_pre_item_restore_example2');
|
'Phone' => 'plugin_pre_item_restore_example2'];
|
||||||
$PLUGIN_HOOKS['item_restore']['example'] = array('Computer' => 'plugin_item_restore_example');
|
$PLUGIN_HOOKS['item_restore']['example'] = ['Computer' => 'plugin_item_restore_example'];
|
||||||
|
|
||||||
// Add event to GLPI core itemtype, event will be raised by the plugin.
|
// Add event to GLPI core itemtype, event will be raised by the plugin.
|
||||||
// See plugin_example_uninstall for cleanup of notification
|
// See plugin_example_uninstall for cleanup of notification
|
||||||
$PLUGIN_HOOKS['item_get_events']['example']
|
$PLUGIN_HOOKS['item_get_events']['example']
|
||||||
= array('NotificationTargetTicket' => 'plugin_example_get_events');
|
= ['NotificationTargetTicket' => 'plugin_example_get_events'];
|
||||||
|
|
||||||
// Add datas to GLPI core itemtype for notifications template.
|
// Add datas to GLPI core itemtype for notifications template.
|
||||||
$PLUGIN_HOOKS['item_get_datas']['example']
|
$PLUGIN_HOOKS['item_get_datas']['example']
|
||||||
= array('NotificationTargetTicket' => 'plugin_example_get_datas');
|
= ['NotificationTargetTicket' => 'plugin_example_get_datas'];
|
||||||
|
|
||||||
$PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example';
|
$PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example';
|
||||||
|
|
||||||
@ -173,12 +173,12 @@ function plugin_init_example() {
|
|||||||
//$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example";
|
//$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example";
|
||||||
|
|
||||||
// Reports
|
// Reports
|
||||||
$PLUGIN_HOOKS['reports']['example'] = array('report.php' => 'New Report',
|
$PLUGIN_HOOKS['reports']['example'] = ['report.php' => 'New Report',
|
||||||
'report.php?other' => 'New Report 2');
|
'report.php?other' => 'New Report 2'];
|
||||||
|
|
||||||
// Stats
|
// Stats
|
||||||
$PLUGIN_HOOKS['stats']['example'] = array('stat.php' => 'New stat',
|
$PLUGIN_HOOKS['stats']['example'] = ['stat.php' => 'New stat',
|
||||||
'stat.php?other' => 'New stats 2',);
|
'stat.php?other' => 'New stats 2',];
|
||||||
|
|
||||||
$PLUGIN_HOOKS['post_init']['example'] = 'plugin_example_postinit';
|
$PLUGIN_HOOKS['post_init']['example'] = 'plugin_example_postinit';
|
||||||
|
|
||||||
@ -193,21 +193,21 @@ function plugin_init_example() {
|
|||||||
|
|
||||||
// pre_show and post_show for tabs and items,
|
// pre_show and post_show for tabs and items,
|
||||||
// see PluginExampleShowtabitem class for implementation explanations
|
// see PluginExampleShowtabitem class for implementation explanations
|
||||||
$PLUGIN_HOOKS['pre_show_tab']['example'] = array('PluginExampleShowtabitem', 'pre_show_tab');
|
$PLUGIN_HOOKS['pre_show_tab']['example'] = ['PluginExampleShowtabitem', 'pre_show_tab'];
|
||||||
$PLUGIN_HOOKS['post_show_tab']['example'] = array('PluginExampleShowtabitem', 'post_show_tab');
|
$PLUGIN_HOOKS['post_show_tab']['example'] = ['PluginExampleShowtabitem', 'post_show_tab'];
|
||||||
$PLUGIN_HOOKS['pre_show_item']['example'] = array('PluginExampleShowtabitem', 'pre_show_item');
|
$PLUGIN_HOOKS['pre_show_item']['example'] = ['PluginExampleShowtabitem', 'pre_show_item'];
|
||||||
$PLUGIN_HOOKS['post_show_item']['example'] = array('PluginExampleShowtabitem', 'post_show_item');
|
$PLUGIN_HOOKS['post_show_item']['example'] = ['PluginExampleShowtabitem', 'post_show_item'];
|
||||||
|
|
||||||
$PLUGIN_HOOKS['pre_item_form']['example'] = ['PluginExampleItemForm', 'preItemForm'];
|
$PLUGIN_HOOKS['pre_item_form']['example'] = ['PluginExampleItemForm', 'preItemForm'];
|
||||||
$PLUGIN_HOOKS['post_item_form']['example'] = ['PluginExampleItemForm', 'postItemForm'];
|
$PLUGIN_HOOKS['post_item_form']['example'] = ['PluginExampleItemForm', 'postItemForm'];
|
||||||
|
|
||||||
// declare this plugin as an import plugin for Computer itemtype
|
// declare this plugin as an import plugin for Computer itemtype
|
||||||
$PLUGIN_HOOKS['import_item']['exemple'] = array('Computer' => array('Plugin'));
|
$PLUGIN_HOOKS['import_item']['exemple'] = ['Computer' => ['Plugin']];
|
||||||
|
|
||||||
// add additional informations on Computer::showForm
|
// add additional informations on Computer::showForm
|
||||||
$PLUGIN_HOOKS['autoinventory_information']['exemple'] = array(
|
$PLUGIN_HOOKS['autoinventory_information']['exemple'] = [
|
||||||
'Computer' => array('PluginExampleComputer', 'showInfo')
|
'Computer' => ['PluginExampleComputer', 'showInfo']
|
||||||
);
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user