diff --git a/config.php b/front/config.php similarity index 95% rename from config.php rename to front/config.php index 7080fe9..516e32a 100644 --- a/config.php +++ b/front/config.php @@ -37,8 +37,7 @@ //header("Location:../../central.php"); // Entry menu case -define('GLPI_ROOT', '../..'); -include (GLPI_ROOT . "/inc/includes.php"); +include ("../../../inc/includes.php"); Session::checkRight("config", UPDATE); diff --git a/front/devicecamera.form.php b/front/devicecamera.form.php index 4741a34..fbf9bdb 100644 --- a/front/devicecamera.form.php +++ b/front/devicecamera.form.php @@ -33,7 +33,9 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\DeviceCamera; + include ('../../../inc/includes.php'); -$dropdown = new PluginExampleDeviceCamera(); +$dropdown = new DeviceCamera(); include (GLPI_ROOT . "/front/dropdown.common.form.php"); diff --git a/front/devicecamera.php b/front/devicecamera.php index 390e90d..2254232 100644 --- a/front/devicecamera.php +++ b/front/devicecamera.php @@ -35,5 +35,5 @@ include ('../../../inc/includes.php'); -$dropdown = new PluginExampleDeviceCamera(); +$dropdown = new DeviceCamera(); include (GLPI_ROOT . "/front/dropdown.common.php"); diff --git a/front/dropdown.form.php b/front/dropdown.form.php index 4b1fa44..e4f1ea9 100644 --- a/front/dropdown.form.php +++ b/front/dropdown.form.php @@ -33,10 +33,11 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\Dropdown; include ('../../../inc/includes.php'); Plugin::load('example', true); -$dropdown = new PluginExampleDropdown(); +$dropdown = new Dropdown(); include (GLPI_ROOT . "/front/dropdown.common.form.php"); diff --git a/front/dropdown.php b/front/dropdown.php index 42b5ef0..6e56f24 100644 --- a/front/dropdown.php +++ b/front/dropdown.php @@ -33,10 +33,11 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\Dropdown; include ('../../../inc/includes.php'); Plugin::load('example', true); -$dropdown = new PluginExampleDropdown(); +$dropdown = new Dropdown(); include (GLPI_ROOT . "/front/dropdown.common.php"); diff --git a/front/example.form.php b/front/example.form.php index 2289b5c..bc97177 100644 --- a/front/example.form.php +++ b/front/example.form.php @@ -33,15 +33,17 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\Example; + include ('../../../inc/includes.php'); if ($_SESSION["glpiactiveprofile"]["interface"] == "central") { - Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", "pluginexampleexample", ""); + Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, ""); } else { Html::helpHeader("TITRE", $_SERVER['PHP_SELF']); } -$example = new PluginExampleExample(); +$example = new Example(); $example->display($_GET); Html::footer(); diff --git a/front/example.php b/front/example.php index 9054809..c1074cf 100644 --- a/front/example.php +++ b/front/example.php @@ -33,17 +33,19 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\Example; + include ('../../../inc/includes.php'); if ($_SESSION["glpiactiveprofile"]["interface"] == "central") { - Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", "pluginexampleexample", ""); + Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", Example::class, ""); } else { Html::helpHeader("TITRE", $_SERVER['PHP_SELF']); } -//checkTypeRight('PluginExampleExample',"r"); +//checkTypeRight(Example::class,"r"); -Search::show('PluginExampleExample'); +Search::show(Example::class); Html::footer(); diff --git a/front/ruletest.form.php b/front/ruletest.form.php index 3de028a..6f67fb2 100644 --- a/front/ruletest.form.php +++ b/front/ruletest.form.php @@ -33,9 +33,10 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\RuleTestCollection; include ('../../../inc/includes.php'); -$rulecollection = new PluginExampleRuleTestCollection(); +$rulecollection = new RuleTestCollection(); include (GLPI_ROOT . "/front/rule.common.form.php"); diff --git a/front/ruletest.php b/front/ruletest.php index ba1d368..a79689f 100644 --- a/front/ruletest.php +++ b/front/ruletest.php @@ -33,9 +33,10 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\RuleTestCollection; include ('../../../inc/includes.php'); -$rulecollection = new PluginExampleRuleTestCollection(); +$rulecollection = new RuleTestCollection(); include (GLPI_ROOT . "/front/rule.common.php"); diff --git a/hook.php b/hook.php index 197ee2d..1482a5d 100644 --- a/hook.php +++ b/hook.php @@ -33,6 +33,10 @@ // Purpose of file: // ---------------------------------------------------------------------- +use GlpiPlugin\Example\Dropdown; +use GlpiPlugin\Example\Example; +use Dropdown as GlpiDropdown; + // Hook called on profile change // Good place to evaluate the user right on this plugin // And to save it in the session @@ -59,7 +63,7 @@ function plugin_example_getDatabaseRelations() { // Define Dropdown tables to be manage in GLPI : function plugin_example_getDropdown() { // Table => Name - return ['PluginExampleDropdown' => __("Plugin Example Dropdown", 'example')]; + return [Dropdown::class => __("Plugin Example Dropdown", 'example')]; } @@ -94,7 +98,7 @@ function plugin_example_getAddSearchOptionsNew($itemtype) { return $options; } -// See also PluginExampleExample::getSpecificValueToDisplay() +// See also GlpiPlugin\Example\Example::getSpecificValueToDisplay() function plugin_example_giveItem($type, $ID, $data, $num) { $searchopt = &Search::getOptions($type); $table = $searchopt[$ID]["table"]; @@ -102,7 +106,7 @@ function plugin_example_giveItem($type, $ID, $data, $num) { switch ($table.'.'.$field) { case "glpi_plugin_example_examples.name" : - $out = ""; + $out = ""; $out .= $data[$num][0]['name']; if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) { $out .= " (".$data["id"].")"; @@ -133,7 +137,7 @@ function plugin_example_addDefaultJoin($type, $ref_table, &$already_link_tables) // Example of default JOIN clause // No need of the function if you do not have specific cases switch ($type) { - // case "PluginExampleExample" : + // case Example::class : case "MyType" : return Search::addLeftJoin($type, $ref_table, $already_link_tables, "newtable", "linkfield"); @@ -146,7 +150,7 @@ function plugin_example_addDefaultSelect($type) { // Example of default SELECT item to be added // No need of the function if you do not have specific cases switch ($type) { - // case "PluginExampleExample" : + // case Example::class : case "MyType" : return "`mytable`.`myfield` = 'myvalue' AS MYNAME, "; } @@ -158,7 +162,7 @@ function plugin_example_addDefaultWhere($type) { // Example of default WHERE item to be added // No need of the function if you do not have specific cases switch ($type) { - // case "PluginExampleExample" : + // case Example::class : case "MyType" : return " `mytable`.`myfield` = 'myvalue' "; } @@ -179,7 +183,7 @@ function plugin_example_addLeftJoin($type, $ref_table, $new_table, $linkfield) { function plugin_example_forceGroupBy($type) { switch ($type) { - case 'PluginExampleExample' : + case Example::class : // Force add GROUP BY IN REQUEST return true; } @@ -272,7 +276,7 @@ function plugin_example_MassiveActions($type) { switch ($type) { // New action for core and other plugin types : name = plugin_PLUGINNAME_actionname case 'Computer' : - return ['PluginExampleExample'.MassiveAction::CLASS_ACTION_SEPARATOR.'DoIt' => + return [Example::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'DoIt' => __("plugin_example_DoIt", 'example')]; // Actions for types provided by the plugin are included inside the classes @@ -325,7 +329,7 @@ function plugin_example_searchOptionsValues($options = []) { switch ($table.".".$field) { case "glpi_plugin_example_examples.serial" : echo __("Not really specific - Use your own dropdown - Just for example", 'example'); - Dropdown::show(getItemTypeForTable($options['searchoption']['table']), + GlpiDropdown::show(getItemTypeForTable($options['searchoption']['table']), ['value' => $options['value'], 'name' => $options['name'], 'comments' => 0]); @@ -427,7 +431,7 @@ function plugin_item_transfer_example($parm) { // Do special actions for dynamic report function plugin_example_dynamicReport($parm) { - if ($parm["item_type"] == 'PluginExampleExample') { + if ($parm["item_type"] == Example::class) { // Do all what you want for export depending on $parm echo "Personalized export for type ".$parm["display_type"]; echo 'with additional datas : '; @@ -445,7 +449,7 @@ function plugin_example_dynamicReport($parm) { // Add parameters to Html::printPager in search system function plugin_example_addParamFordynamicReport($itemtype) { - if ($itemtype == 'PluginExampleExample') { + if ($itemtype == Example::class) { // Return array data containing all params to add : may be single data or array data // Search config are available from session variable return ['add1' => $_SESSION['glpisearch'][$itemtype]['order'], @@ -551,7 +555,7 @@ function plugin_example_install() { // To be called for each task the plugin manage // task in class - CronTask::Register('PluginExampleExample', 'Sample', DAY_TIMESTAMP, ['param' => 50]); + CronTask::Register(Example::class, 'Sample', DAY_TIMESTAMP, ['param' => 50]); return true; } @@ -607,7 +611,7 @@ function plugin_example_uninstall() { function plugin_example_AssignToTicket($types) { - $types['PluginExampleExample'] = "Example"; + $types[Example::class] = "Example"; return $types; } diff --git a/setup.php b/setup.php index 33f5ae9..63d027c 100644 --- a/setup.php +++ b/setup.php @@ -29,6 +29,14 @@ */ use Glpi\Plugin\Hooks; +use GlpiPlugin\Example\Computer; +use GlpiPlugin\Example\Config; +use GlpiPlugin\Example\Dropdown; +use GlpiPlugin\Example\DeviceCamera; +use GlpiPlugin\Example\Example; +use GlpiPlugin\Example\ItemForm; +use GlpiPlugin\Example\RuleTestCollection; +use GlpiPlugin\Example\Showtabitem; define('PLUGIN_EXAMPLE_VERSION', '0.0.1'); @@ -48,38 +56,38 @@ function plugin_init_example() { // Params : plugin name - string type - ID - Array of attributes // No specific information passed so not needed - //Plugin::registerClass('PluginExampleExample', - // array('classname' => 'PluginExampleExample', + //Plugin::registerClass(Example::getType(), + // array('classname' => Example::class, // )); - Plugin::registerClass('PluginExampleConfig', ['addtabon' => 'Config']); + Plugin::registerClass(Config::class, ['addtabon' => 'Config']); // Params : plugin name - string type - ID - Array of attributes - Plugin::registerClass('PluginExampleDropdown'); + Plugin::registerClass(Dropdown::class); $types = ['Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone', 'Preference', 'Profile', 'Supplier']; - Plugin::registerClass('PluginExampleExample', + Plugin::registerClass(Example::class, ['notificationtemplates_types' => true, 'addtabon' => $types, 'link_types' => true]); - Plugin::registerClass('PluginExampleRuleTestCollection', + Plugin::registerClass(RuleTestCollection::class, ['rulecollections_types' => true]); - Plugin::registerClass('PluginExampleDeviceCamera', + Plugin::registerClass(DeviceCamera::class, ['device_types' => true]); if (version_compare(GLPI_VERSION, '9.1', 'ge')) { - if (class_exists('PluginExampleExample')) { - Link::registerTag(PluginExampleExample::$tags); + if (class_exists(Example::class)) { + Link::registerTag(Example::$tags); } } // Display a menu entry ? $_SESSION["glpi_plugin_example_profile"]['example'] = 'w'; if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook - $PLUGIN_HOOKS['menu_toadd']['example'] = ['plugins' => 'PluginExampleExample', - 'tools' => 'PluginExampleExample']; + $PLUGIN_HOOKS['menu_toadd']['example'] = ['plugins' => Example::class, + 'tools' => Example::class]; // Old menu style // $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php'; @@ -92,13 +100,13 @@ function plugin_init_example() { // $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][""] = '/plugins/example/index.php'; // $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][__s('Test link', 'example')] = '/plugins/example/index.php'; - $PLUGIN_HOOKS["helpdesk_menu_entry"]['example'] = true; - $PLUGIN_HOOKS["helpdesk_menu_entry_icon"]['example'] = 'fas fa-puzzle-piece'; + $PLUGIN_HOOKS[Hooks::HELPDESK_MENU_ENTRY]['example'] = true; + $PLUGIN_HOOKS[Hooks::HELPDESK_MENU_ENTRY_ICON]['example'] = 'fas fa-puzzle-piece'; } // Config page if (Session::haveRight('config', UPDATE)) { - $PLUGIN_HOOKS['config_page']['example'] = 'config.php'; + $PLUGIN_HOOKS['config_page']['example'] = 'front/config.php'; } // Init session @@ -109,53 +117,53 @@ function plugin_init_example() { //$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example'; // Item action event // See define.php for defined ITEM_TYPE - $PLUGIN_HOOKS['pre_item_update']['example'] = ['Computer' => 'plugin_pre_item_update_example']; - $PLUGIN_HOOKS['item_update']['example'] = ['Computer' => 'plugin_item_update_example']; + $PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['example'] = [Computer::class => 'plugin_pre_item_update_example']; + $PLUGIN_HOOKS[hooks::ITEM_UPDATE]['example'] = [Computer::class => 'plugin_item_update_example']; - $PLUGIN_HOOKS['item_empty']['example'] = ['Computer' => 'plugin_item_empty_example']; + $PLUGIN_HOOKS[Hooks::ITEM_EMPTY]['example'] = [Computer::class => 'plugin_item_empty_example']; // Restrict right - $PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'item_can']]; - $PLUGIN_HOOKS['add_default_where']['example'] = ['Computer' => ['PluginExampleComputer', 'add_default_where']]; + $PLUGIN_HOOKS[Hooks::ITEM_CAN]['example'] = [Computer::class => [Example::class, 'item_can']]; + $PLUGIN_HOOKS['add_default_where']['example'] = [Computer::class => [Example::class, 'add_default_where']]; // Example using a method in class - $PLUGIN_HOOKS['pre_item_add']['example'] = ['Computer' => ['PluginExampleExample', + $PLUGIN_HOOKS[Hooks::PRE_ITEM_ADD]['example'] = [Computer::class => [Example::class, 'pre_item_add_computer']]; - $PLUGIN_HOOKS['post_prepareadd']['example'] = ['Computer' => ['PluginExampleExample', + $PLUGIN_HOOKS[Hooks::POST_PREPAREADD]['example'] = [Computer::class => [Example::class, 'post_prepareadd_computer']]; - $PLUGIN_HOOKS['item_add']['example'] = ['Computer' => ['PluginExampleExample', + $PLUGIN_HOOKS[Hooks::ITEM_ADD]['example'] = [Computer::class => [Example::class, 'item_add_computer']]; - $PLUGIN_HOOKS['pre_item_delete']['example'] = ['Computer' => 'plugin_pre_item_delete_example']; - $PLUGIN_HOOKS['item_delete']['example'] = ['Computer' => 'plugin_item_delete_example']; + $PLUGIN_HOOKS[Hooks::PRE_ITEM_DELETE]['example'] = [Computer::class => 'plugin_pre_item_delete_example']; + $PLUGIN_HOOKS[Hooks::ITEM_DELETE]['example'] = [Computer::class => 'plugin_item_delete_example']; // Example using the same function - $PLUGIN_HOOKS['pre_item_purge']['example'] = ['Computer' => 'plugin_pre_item_purge_example', + $PLUGIN_HOOKS[Hooks::PRE_ITEM_PURGE]['example'] = [Computer::class => 'plugin_pre_item_purge_example', 'Phone' => 'plugin_pre_item_purge_example']; - $PLUGIN_HOOKS['item_purge']['example'] = ['Computer' => 'plugin_item_purge_example', + $PLUGIN_HOOKS[Hooks::ITEM_PURGE]['example'] = [Computer::class => 'plugin_item_purge_example', 'Phone' => 'plugin_item_purge_example']; // Example with 2 different functions - $PLUGIN_HOOKS['pre_item_restore']['example'] = ['Computer' => 'plugin_pre_item_restore_example', + $PLUGIN_HOOKS[Hooks::PRE_ITEM_RESTORE]['example'] = [Computer::class => 'plugin_pre_item_restore_example', 'Phone' => 'plugin_pre_item_restore_example2']; - $PLUGIN_HOOKS['item_restore']['example'] = ['Computer' => 'plugin_item_restore_example']; + $PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['example'] = [Computer::class => 'plugin_item_restore_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'] + $PLUGIN_HOOKS[Hooks::ITEM_GET_EVENTS]['example'] = ['NotificationTargetTicket' => 'plugin_example_get_events']; // Add datas to GLPI core itemtype for notifications template. - $PLUGIN_HOOKS['item_get_datas']['example'] + $PLUGIN_HOOKS[Hooks::ITEM_GET_DATA]['example'] = ['NotificationTargetTicket' => 'plugin_example_get_datas']; - $PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example'; + $PLUGIN_HOOKS[Hooks::ITEM_TRANSFER]['example'] = 'plugin_item_transfer_example'; // function to populate planning // No more used since GLPI 0.84 // $PLUGIN_HOOKS['planning_populate']['example'] = 'plugin_planning_populate_example'; // Use instead : add class to planning types and define populatePlanning in class - $CFG_GLPI['planning_types'][] = 'PluginExampleExample'; + $CFG_GLPI['planning_types'][] = Example::class; //function to display planning items // No more used sinc GLPi 0.84 @@ -168,8 +176,8 @@ function plugin_init_example() { $PLUGIN_HOOKS['assign_to_ticket']['example'] = 1; // Add specific files to add to the header : javascript or css - $PLUGIN_HOOKS['add_javascript']['example'] = 'example.js'; - $PLUGIN_HOOKS['add_css']['example'] = 'example.css'; + $PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['example'] = 'example.js'; + $PLUGIN_HOOKS[Hooks::ADD_CSS]['example'] = 'example.css'; // request more attributes from ldap //$PLUGIN_HOOKS['retrieve_more_field_from_ldap']['example']="plugin_retrieve_more_field_from_ldap_example"; @@ -185,45 +193,45 @@ function plugin_init_example() { $PLUGIN_HOOKS['stats']['example'] = ['stat.php' => 'New stat', 'stat.php?other' => 'New stats 2',]; - $PLUGIN_HOOKS['post_init']['example'] = 'plugin_example_postinit'; + $PLUGIN_HOOKS[Hooks::POST_INIT]['example'] = 'plugin_example_postinit'; $PLUGIN_HOOKS['status']['example'] = 'plugin_example_Status'; // CSRF compliance : All actions must be done via POST and forms closed by Html::closeForm(); - $PLUGIN_HOOKS['csrf_compliant']['example'] = true; + $PLUGIN_HOOKS[Hooks::CSRF_COMPLIANT]['example'] = true; - $PLUGIN_HOOKS['display_central']['example'] = "plugin_example_display_central"; - $PLUGIN_HOOKS['display_login']['example'] = "plugin_example_display_login"; - $PLUGIN_HOOKS['infocom']['example'] = "plugin_example_infocom_hook"; + $PLUGIN_HOOKS[Hooks::DISPLAY_CENTRAL]['example'] = "plugin_example_display_central"; + $PLUGIN_HOOKS[Hooks::DISPLAY_LOGIN]['example'] = "plugin_example_display_login"; + $PLUGIN_HOOKS[Hooks::INFOCOM]['example'] = "plugin_example_infocom_hook"; // pre_show and post_show for tabs and items, - // see PluginExampleShowtabitem class for implementation explanations - $PLUGIN_HOOKS['pre_show_tab']['example'] = ['PluginExampleShowtabitem', 'pre_show_tab']; - $PLUGIN_HOOKS['post_show_tab']['example'] = ['PluginExampleShowtabitem', 'post_show_tab']; - $PLUGIN_HOOKS['pre_show_item']['example'] = ['PluginExampleShowtabitem', 'pre_show_item']; - $PLUGIN_HOOKS['post_show_item']['example'] = ['PluginExampleShowtabitem', 'post_show_item']; + // see GlpiPlugin\Example\Showtabitem class for implementation explanations + $PLUGIN_HOOKS[Hooks::PRE_SHOW_TAB]['example'] = [Showtabitem::class, 'pre_show_tab']; + $PLUGIN_HOOKS[Hooks::POST_SHOW_TAB]['example'] = [Showtabitem::class, 'post_show_tab']; + $PLUGIN_HOOKS[Hooks::PRE_SHOW_ITEM]['example'] = [Showtabitem::class, 'pre_show_item']; + $PLUGIN_HOOKS[Hooks::POST_SHOW_ITEM]['example'] = [Showtabitem::class, 'post_show_item']; - $PLUGIN_HOOKS['pre_item_form']['example'] = ['PluginExampleItemForm', 'preItemForm']; - $PLUGIN_HOOKS['post_item_form']['example'] = ['PluginExampleItemForm', 'postItemForm']; + $PLUGIN_HOOKS[Hooks::PRE_ITEM_FORM]['example'] = [ItemForm::class, 'preItemForm']; + $PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['example'] = [ItemForm::class, 'postItemForm']; // Add new actions to timeline - $PLUGIN_HOOKS['timeline_actions']['example'] = [ - 'PluginExampleItemForm', 'timelineActions' + $PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['example'] = [ + ItemForm::class, 'timelineActions' ]; // declare this plugin as an import plugin for Computer itemtype - $PLUGIN_HOOKS['import_item']['example'] = ['Computer' => ['Plugin']]; + $PLUGIN_HOOKS['import_item']['example'] = [Computer::class => ['Plugin']]; // add additional informations on Computer::showForm - $PLUGIN_HOOKS['autoinventory_information']['example'] = [ - 'Computer' => ['PluginExampleComputer', 'showInfo'] + $PLUGIN_HOOKS[Hooks::AUTOINVENTORY_INFORMATION]['example'] = [ + Computer::class => [Computer::class, 'showInfo'] ]; $PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['example'] = "plugin_example_filter_actors"; // add new cards to dashboard grid - $PLUGIN_HOOKS['dashboard_types']['example'] = ['PluginExampleExample', 'dashboardTypes']; - $PLUGIN_HOOKS['dashboard_cards']['example'] = ['PluginExampleExample', 'dashboardCards']; + $PLUGIN_HOOKS['dashboard_types']['example'] = [Example::class, 'dashboardTypes']; + $PLUGIN_HOOKS['dashboard_cards']['example'] = [Example::class, 'dashboardCards']; } diff --git a/inc/child.class.php b/src/Child.php similarity index 97% rename from inc/child.class.php rename to src/Child.php index cfa09be..ce2a4ed 100644 --- a/inc/child.class.php +++ b/src/Child.php @@ -33,13 +33,17 @@ // Purpose of file: // ---------------------------------------------------------------------- +namespace GlpiPlugin\Example; +use CommonDBChild; +use Session; + // Sample of class that inherit from CommonDBChild. The behaviour of CommonRelation is similar. // The main evolution introduced by 0.84 version of GLPI is a stronger control and log of // interactions. We suggest you to refer to the header of CommonDBConnexity class to see these // enhancements. // For CommonDBRelation, the variable are quiet equivalent, but they use _1 and _2 for each side // parent -class PluginExampleChild extends CommonDBChild { +class Child extends CommonDBChild { // A child rely on an item. If $itemtype=='itemtype', then that is a variable item. static public $itemtype = 'itemtype'; diff --git a/inc/computer.class.php b/src/Computer.php similarity index 96% rename from inc/computer.class.php rename to src/Computer.php index 7ffbbaf..1834155 100644 --- a/inc/computer.class.php +++ b/src/Computer.php @@ -33,13 +33,16 @@ // Purpose of file: // ---------------------------------------------------------------------- +namespace GlpiPlugin\Example; +use CommonDBTM; + // Class of the defined type if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } -class PluginExampleComputer extends CommonDBTM { +class Computer extends CommonDBTM { static function showInfo() { @@ -78,4 +81,3 @@ class PluginExampleComputer extends CommonDBTM { } } - diff --git a/inc/config.class.php b/src/Config.php similarity index 92% rename from inc/config.class.php rename to src/Config.php index 754ad2c..e22b906 100644 --- a/inc/config.class.php +++ b/src/Config.php @@ -28,7 +28,16 @@ * ------------------------------------------------------------------------- */ -class PluginExampleConfig extends CommonDBTM { +namespace GlpiPlugin\Example; +use CommonDBTM; +use CommonGLPI; +use Config as GlpiConfig; +use Dropdown; +use Html; +use Session; +use Toolbox; + +class Config extends CommonDBTM { static protected $notable = true; @@ -54,7 +63,7 @@ class PluginExampleConfig extends CommonDBTM { return false; } - $my_config = Config::getConfigurationValues('plugin:Example'); + $my_config = GlpiConfig::getConfigurationValues('plugin:Example'); echo ""; echo ""; diff --git a/inc/devicecamera.class.php b/src/DeviceCamera.php similarity index 94% rename from inc/devicecamera.class.php rename to src/DeviceCamera.php index 0c48d2b..64b52d2 100644 --- a/inc/devicecamera.class.php +++ b/src/DeviceCamera.php @@ -33,6 +33,9 @@ // Purpose of file: // ---------------------------------------------------------------------- +namespace GlpiPlugin\Example; +use CommonDevice; + // Class of the defined type if (!defined('GLPI_ROOT')) { @@ -40,7 +43,7 @@ if (!defined('GLPI_ROOT')) { } /// Class DeviceCamera -class PluginExampleDeviceCamera extends CommonDevice { +class DeviceCamera extends CommonDevice { static function getTypeName($nb = 0) { return _n('Camera', 'Cameras', $nb); diff --git a/inc/document.class.php b/src/Document.php similarity index 98% rename from inc/document.class.php rename to src/Document.php index a00bf5e..a306c0a 100644 --- a/inc/document.class.php +++ b/src/Document.php @@ -54,11 +54,14 @@ along with GLPI. If not, see . * */ +namespace GlpiPlugin\Example; +use Document as GlpiDocument; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } -class PluginExampleDocument extends Document { +class Document extends GlpiDocument { /** * Return the table used to store this object. Overloads the implementation in CommonDBTM diff --git a/inc/dropdown.class.php b/src/Dropdown.php similarity index 94% rename from inc/dropdown.class.php rename to src/Dropdown.php index ab463a1..463324d 100644 --- a/inc/dropdown.class.php +++ b/src/Dropdown.php @@ -32,9 +32,11 @@ // Original Author of file: // Purpose of file: // ---------------------------------------------------------------------- +namespace GlpiPlugin\Example; +use CommonDropdown; // Class for a Dropdown -class PluginExampleDropdown extends CommonDropdown { +class Dropdown extends CommonDropdown { static function getTypeName($nb = 0) { diff --git a/inc/example.class.php b/src/Example.php similarity index 96% rename from inc/example.class.php rename to src/Example.php index c7b9016..42ec715 100644 --- a/inc/example.class.php +++ b/src/Example.php @@ -33,8 +33,17 @@ // Purpose of file: // ---------------------------------------------------------------------- +namespace GlpiPlugin\Example; +use CommonDBTM; +use CommonGLPI; +use Computer; +use Html; +use Log; +use MassiveAction; +use Session; + // Class of the defined type -class PluginExampleExample extends CommonDBTM { +class Example extends CommonDBTM { static $tags = '[EXAMPLE_ID]'; @@ -330,9 +339,9 @@ class PluginExampleExample extends CommonDBTM { $output[$key]["end"] = date("Y-m-d 18:00:00"); $output[$key]["name"] = __("test planning example 1", 'example'); // Specify the itemtype to be able to use specific display system - $output[$key]["itemtype"] = "PluginExampleExample"; + $output[$key]["itemtype"] = Example::class; // Set the ID using the ID of the item in the database to have unique ID - $output[$key][getForeignKeyFieldForItemType('PluginExampleExample')] = 1; + $output[$key][getForeignKeyFieldForItemType(Example::class)] = 1; return $output; } @@ -455,7 +464,7 @@ class PluginExampleExample extends CommonDBTM { foreach ($ids as $id) { if ($item->getFromDB($id)) { Session::addMessageAfterRedirect("- ".$item->getField("name")); - Log::history($id, 'Computer', $changes, 'PluginExampleExample', + Log::history($id, 'Computer', $changes, Example::class, Log::HISTORY_PLUGIN); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { @@ -470,7 +479,7 @@ class PluginExampleExample extends CommonDBTM { return; case 'do_nothing' : - If ($item->getType() == 'PluginExampleExample') { + If ($item->getType() == Example::class) { Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example')); Session::addMessageAfterRedirect(__("But... I say I will do nothing for:", 'example')); @@ -506,12 +515,12 @@ class PluginExampleExample extends CommonDBTM { return [ 'example' => [ 'label' => __("Plugin Example", 'example'), - 'function' => "PluginExampleExample::cardWidget", + 'function' => Example::class . "::cardWidget", 'image' => "https://via.placeholder.com/100x86?text=example", ], 'example_static' => [ 'label' => __("Plugin Example (static)", 'example'), - 'function' => "PluginExampleExample::cardWidgetWithoutProvider", + 'function' => Example::class . "::cardWidgetWithoutProvider", 'image' => "https://via.placeholder.com/100x86?text=example+static", ], ]; @@ -526,7 +535,7 @@ class PluginExampleExample extends CommonDBTM { 'plugin_example_card' => [ 'widgettype' => ["example"], 'label' => __("Plugin Example card"), - 'provider' => "PluginExampleExample::cardDataProvider", + 'provider' => Example::class . "::cardDataProvider", ], 'plugin_example_card_without_provider' => [ 'widgettype' => ["example_static"], @@ -535,7 +544,7 @@ class PluginExampleExample extends CommonDBTM { 'plugin_example_card_with_core_widget' => [ 'widgettype' => ["bigNumber"], 'label' => __("Plugin Example card with core provider"), - 'provider' => "PluginExampleExample::cardBigNumberProvider", + 'provider' => Example::class . "::cardBigNumberProvider", ], ]; diff --git a/inc/itemform.class.php b/src/ItemForm.php similarity index 95% rename from inc/itemform.class.php rename to src/ItemForm.php index 2cb3dc5..3920135 100644 --- a/inc/itemform.class.php +++ b/src/ItemForm.php @@ -28,12 +28,16 @@ * ------------------------------------------------------------------------- */ +namespace GlpiPlugin\Example; +use Html; +use Ticket; + /** - * Summary of PluginExampleItemForm + * Summary of GlpiPlugin\Example\ItemForm * Example of *_item_form implementation * @see http://glpi-developer-documentation.rtfd.io/en/master/plugins/hooks.html#items-display-related * */ -class PluginExampleItemForm { +class ItemForm { /** * Display contents at the begining of item forms. @@ -46,7 +50,7 @@ class PluginExampleItemForm { $item = $params['item']; $options = $params['options']; - $firstelt = ($item::getType() == Ticket::getType() ? 'th' : 'td'); + $firstelt = ($item::getType() == Ticket::class ? 'th' : 'td'); $out = ''; $out .= sprintf( @@ -88,7 +92,7 @@ class PluginExampleItemForm { $item = $params['item']; $options = $params['options']; - $firstelt = ($item::getType() == Ticket::getType() ? 'th' : 'td'); + $firstelt = ($item::getType() == Ticket::class ? 'th' : 'td'); $out = ''; $out .= sprintf( diff --git a/inc/item_devicecamera.class.php b/src/Item_DeviceCamera.php similarity index 90% rename from inc/item_devicecamera.class.php rename to src/Item_DeviceCamera.php index 6662889..a2aa88d 100644 --- a/inc/item_devicecamera.class.php +++ b/src/Item_DeviceCamera.php @@ -35,6 +35,10 @@ // Class of the defined type +namespace GlpiPlugin\Example; +use GlpiPlugin\Example\DeviceCamera; +use Item_Devices; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } @@ -42,9 +46,9 @@ if (!defined('GLPI_ROOT')) { /** * Relation between item and devices **/ -class PluginExampleItem_DeviceCamera extends Item_Devices { +class Item_DeviceCamera extends Item_Devices { - static public $itemtype_2 = 'PluginExampleDeviceCamera'; + static public $itemtype_2 = DeviceCamera::class; static public $items_id_2 = 'plugin_example_devicecameras_id'; static protected $notable = false; diff --git a/inc/notificationtargetexample.class.php b/src/NotificationTargetExample.php similarity index 93% rename from inc/notificationtargetexample.class.php rename to src/NotificationTargetExample.php index b6c8e6d..a197049 100644 --- a/inc/notificationtargetexample.class.php +++ b/src/NotificationTargetExample.php @@ -28,12 +28,15 @@ * ------------------------------------------------------------------------- */ +namespace GlpiPlugin\Example; +use NotificationTarget; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } // Class NotificationTarget -class PluginExampleNotificationTargetExample extends NotificationTarget { +class NotificationTargetExample extends NotificationTarget { function getEvents() { return ['alert' => 'alert example']; diff --git a/inc/ruletest.class.php b/src/RuleTest.php similarity index 95% rename from inc/ruletest.class.php rename to src/RuleTest.php index 28560e8..3e4dce5 100644 --- a/inc/ruletest.class.php +++ b/src/RuleTest.php @@ -32,6 +32,10 @@ // Original Author of file: Walid Nouh // Purpose of file: // ---------------------------------------------------------------------- + +namespace GlpiPlugin\Example; +use Rule; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } @@ -44,10 +48,10 @@ if (!defined('GLPI_ROOT')) { * - actions * **/ -class PluginExampleRuleTest extends Rule { +class RuleTest extends Rule { // From Rule - static public $right = 'rule_import'; + public $rightname = 'rule_import'; public $can_sort = true; diff --git a/inc/ruletestcollection.class.php b/src/RuleTestCollection.php similarity index 91% rename from inc/ruletestcollection.class.php rename to src/RuleTestCollection.php index 3a0154a..58a4d18 100644 --- a/inc/ruletestcollection.class.php +++ b/src/RuleTestCollection.php @@ -32,16 +32,20 @@ // Original Author of file: Walid Nouh // Purpose of file: // ---------------------------------------------------------------------- + +namespace GlpiPlugin\Example; +use RuleCollection; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } -class PluginExampleRuleTestCollection extends RuleCollection { +class RuleTestCollection extends RuleCollection { // From RuleCollection public $stop_on_first_match = true; - static public $right = 'rule_import'; + public static $rightname = 'rule_import'; public $menu_option = 'test'; function getTitle() { diff --git a/inc/showtabitem.class.php b/src/Showtabitem.php similarity index 97% rename from inc/showtabitem.class.php rename to src/Showtabitem.php index 2faef25..021f9e3 100644 --- a/inc/showtabitem.class.php +++ b/src/Showtabitem.php @@ -28,8 +28,10 @@ * ------------------------------------------------------------------------- */ +namespace GlpiPlugin\Example; + /** - * Summary of PluginExampleShowtabitem + * Summary of GlpiPlugin\Example\Showtabitem * Example of pre_show_xxx and post_show_xxx implementation * * @@ -49,7 +51,7 @@ * post_show_tab will be fired after the tab show * * */ -class PluginExampleShowtabitem { +class Showtabitem { /** * Summary of pre_show_tab @@ -65,7 +67,7 @@ class PluginExampleShowtabitem { static function pre_show_tab($params) { switch ($params['item']->getType()) { case 'Ticket': - if ($params['options']['itemtype']=='Ticket' && $params['options']['tabnum']==2) { + if ($params['options']['itemtype']=='TicketValidation' && $params['options']['tabnum']==2) { // if tasks are not all done // then prevent solution div to show // this is an example to prevent solving of ticket