Coding standard (yllen)

git-svn-id: https://forge.glpi-project.org/svn/example/trunk@117 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
remicollet 2009-12-13 17:07:33 +00:00
parent c16272abf4
commit 41a5750e6f
6 changed files with 629 additions and 628 deletions

View File

@ -36,10 +36,10 @@
define('GLPI_ROOT', '../../..'); define('GLPI_ROOT', '../../..');
include (GLPI_ROOT . "/inc/includes.php"); include (GLPI_ROOT . "/inc/includes.php");
if ($_SESSION["glpiactiveprofile"]["interface"] == "central"){ if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
commonHeader("TITRE", $_SERVER['PHP_SELF'],"plugins","example","optionname"); commonHeader("TITRE", $_SERVER['PHP_SELF'],"plugins","example","optionname");
} else { } else {
helpHeader("TITRE", $_SERVER['PHP_SELF']); helpHeader("TITRE", $_SERVER['PHP_SELF']);
} }
checkTypeRight('PluginExampleExample',"r"); checkTypeRight('PluginExampleExample',"r");

999
hook.php

File diff suppressed because it is too large Load Diff

View File

@ -42,22 +42,20 @@ class PluginExampleExample extends CommonDBTM {
// Should return the localized name of the type // Should return the localized name of the type
static function getTypeName() { static function getTypeName() {
global $LANG;
return 'Example Type'; return 'Example Type';
} }
static function canCreate() { static function canCreate() {
if (isset($_SESSION["glpi_plugin_example_profile"])) { if (isset($_SESSION["glpi_plugin_example_profile"])) {
return ($_SESSION["glpi_plugin_example_profile"]['example']=='w'); return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w');
} }
return false; return false;
} }
static function canView() { static function canView() {
if (isset($_SESSION["glpi_plugin_example_profile"])) { if (isset($_SESSION["glpi_plugin_example_profile"])) {
return ($_SESSION["glpi_plugin_example_profile"]['example']=='w' return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w'
|| $_SESSION["glpi_plugin_example_profile"]['example']=='r'); || $_SESSION["glpi_plugin_example_profile"]['example'] == 'r');
} }
return false; return false;
} }
@ -66,28 +64,28 @@ class PluginExampleExample extends CommonDBTM {
global $LANG; global $LANG;
$tab = array(); $tab = array();
$tab['common']="Header Needed"; $tab['common'] = "Header Needed";
$tab[1]['table']='glpi_plugin_example_examples'; $tab[1]['table'] = 'glpi_plugin_example_examples';
$tab[1]['field']='name'; $tab[1]['field'] = 'name';
$tab[1]['linkfield']='name'; $tab[1]['linkfield'] = 'name';
$tab[1]['name']=$LANG['plugin_example']["name"]; $tab[1]['name'] = $LANG['plugin_example']["name"];
$tab[2]['table']='glpi_plugin_example_dropdowns'; $tab[2]['table'] = 'glpi_plugin_example_dropdowns';
$tab[2]['field']='name'; $tab[2]['field'] = 'name';
$tab[2]['linkfield']='plugin_example_dropdowns_id'; $tab[2]['linkfield'] = 'plugin_example_dropdowns_id';
$tab[2]['name']='Dropdown'; $tab[2]['name'] = 'Dropdown';
$tab[3]['table']='glpi_plugin_example_examples'; $tab[3]['table'] = 'glpi_plugin_example_examples';
$tab[3]['field']='serial'; $tab[3]['field'] = 'serial';
$tab[3]['linkfield']='serial'; $tab[3]['linkfield'] = 'serial';
$tab[3]['name']='Serial'; $tab[3]['name'] = 'Serial';
$tab[3]['usehaving']=true; $tab[3]['usehaving'] = true;
$tab[30]['table']='glpi_plugin_example_examples'; $tab[30]['table'] = 'glpi_plugin_example_examples';
$tab[30]['field']='id'; $tab[30]['field'] = 'id';
$tab[30]['linkfield']=''; $tab[30]['linkfield'] = '';
$tab[30]['name']=$LANG["common"][2]; $tab[30]['name'] = $LANG["common"][2];
return $tab; return $tab;
} }
@ -103,11 +101,9 @@ class PluginExampleExample extends CommonDBTM {
global $LANG; global $LANG;
switch ($name) { switch ($name) {
case 'sample2': case 'sample2' :
return array ( return array('description' => $LANG['plugin_example']['test']." (class)",
'description' => $LANG['plugin_example']['test']." (class)", 'parameter' => $LANG['plugin_example']['test']);
'parameter' => $LANG['plugin_example']['test']);
break;
} }
return array(); return array();
} }
@ -123,6 +119,7 @@ class PluginExampleExample extends CommonDBTM {
* 0 : nothing to do * 0 : nothing to do
*/ */
static function cronSample2($task) { static function cronSample2($task) {
$task->log("Example log message from class"); $task->log("Example log message from class");
$task->setVolume(mt_rand(0,10)); $task->setVolume(mt_rand(0,10));

View File

@ -33,6 +33,6 @@
// Purpose of file: // Purpose of file:
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
$LANG['plugin_example']["test"]="test english"; $LANG['plugin_example']["test"] = "english test";
$LANG['plugin_example']["name"]="Name"; $LANG['plugin_example']["name"] = "Name";
?> ?>

View File

@ -34,6 +34,6 @@
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
$LANG['plugin_example']["test"]="test french"; $LANG['plugin_example']["test"] = "test français";
$LANG['plugin_example']["name"]="Nom"; $LANG['plugin_example']["name"] = "Nom";
?> ?>

191
setup.php
View File

@ -35,141 +35,138 @@
// Init the hooks of the plugins -Needed // Init the hooks of the plugins -Needed
function plugin_init_example() { function plugin_init_example() {
global $PLUGIN_HOOKS,$LANG,$CFG_GLPI; global $PLUGIN_HOOKS,$LANG,$CFG_GLPI;
// Params : plugin name - string type - ID - Array of attributes
Plugin::registerClass('PluginExampleExample', array(
'classname' => 'PluginExampleExample',
'formpage' => 'front/example.form.php',
'deleted_tables' => false,
'template_tables' => false,
'specif_entities_tables' => false,
'recursive_type' => false,
//'linkuser_types' => true,
//'linkgroup_types' => true
));
// Params : plugin name - string type - ID - Array of attributes // Params : plugin name - string type - ID - Array of attributes
Plugin::registerClass('PluginExampleDropdown', array( Plugin::registerClass('PluginExampleExample',
'classname' => 'PluginExampleDropdown', array('classname' => 'PluginExampleExample',
'typename' => 'Example Dropdown Type', 'formpage' => 'front/example.form.php',
'formpage' => 'front/dropdown.form.php')); 'deleted_tables' => false,
'template_tables' => false,
'specif_entities_tables' => false,
'recursive_type' => false));
// Display a menu entry ? // Params : plugin name - string type - ID - Array of attributes
if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook Plugin::registerClass('PluginExampleDropdown',
array('classname' => 'PluginExampleDropdown',
'typename' => 'Example Dropdown Type',
'formpage' => 'front/dropdown.form.php'));
// Display a menu entry ?
if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook
$PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php'; $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['title']="Search"; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['title'] = "Search";
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page']='/plugins/example/front/example.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['page'] = '/plugins/example/front/example.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search']='/plugins/example/front/example.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['search'] = '/plugins/example/front/example.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['add'] = '/plugins/example/front/example.form.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']['config'] = '/plugins/example/index.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".$LANG['plugin_example']["test"]."' alt='".$LANG['plugin_example']["test"]."'>"] = '/plugins/example/index.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links']["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".$LANG['plugin_example']["test"]."' alt='".$LANG['plugin_example']["test"]."'>"] = '/plugins/example/index.php';
$PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][$LANG['plugin_example']["test"]] = '/plugins/example/index.php'; $PLUGIN_HOOKS['submenu_entry']['example']['options']['optionname']['links'][$LANG['plugin_example']["test"]] = '/plugins/example/index.php';
$PLUGIN_HOOKS["helpdesk_menu_entry"]['example'] = true; $PLUGIN_HOOKS["helpdesk_menu_entry"]['example'] = true;
} }
// Config page // Config page
if (haveRight('config','w')) { if (haveRight('config','w')) {
$PLUGIN_HOOKS['config_page']['example'] = 'config.php'; $PLUGIN_HOOKS['config_page']['example'] = 'config.php';
} }
// Init session // Init session
//$PLUGIN_HOOKS['init_session']['example'] = 'plugin_init_session_example'; //$PLUGIN_HOOKS['init_session']['example'] = 'plugin_init_session_example';
// Change profile // Change profile
$PLUGIN_HOOKS['change_profile']['example'] = 'plugin_change_profile_example'; $PLUGIN_HOOKS['change_profile']['example'] = 'plugin_change_profile_example';
// Change entity // Change entity
//$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example'; //$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example';
// Onglets management
$PLUGIN_HOOKS['headings']['example'] = 'plugin_get_headings_example';
$PLUGIN_HOOKS['headings_action']['example'] = 'plugin_headings_actions_example';
// Onglets management // Item action event // See define.php for defined ITEM_TYPE
$PLUGIN_HOOKS['headings']['example'] = 'plugin_get_headings_example'; $PLUGIN_HOOKS['pre_item_update']['example'] = 'plugin_pre_item_update_example';
$PLUGIN_HOOKS['headings_action']['example'] = 'plugin_headings_actions_example'; $PLUGIN_HOOKS['item_update']['example'] = 'plugin_item_update_example';
// Item action event // See define.php for defined ITEM_TYPE $PLUGIN_HOOKS['pre_item_add']['example'] = 'plugin_pre_item_add_example';
$PLUGIN_HOOKS['pre_item_update']['example'] = 'plugin_pre_item_update_example'; $PLUGIN_HOOKS['item_add']['example'] = 'plugin_item_add_example';
$PLUGIN_HOOKS['item_update']['example'] = 'plugin_item_update_example';
$PLUGIN_HOOKS['pre_item_add']['example'] = 'plugin_pre_item_add_example'; $PLUGIN_HOOKS['pre_item_delete']['example'] = 'plugin_pre_item_delete_example';
$PLUGIN_HOOKS['item_add']['example'] = 'plugin_item_add_example'; $PLUGIN_HOOKS['item_delete']['example'] = 'plugin_item_delete_example';
$PLUGIN_HOOKS['pre_item_delete']['example'] = 'plugin_pre_item_delete_example'; $PLUGIN_HOOKS['pre_item_purge']['example'] = 'plugin_pre_item_purge_example';
$PLUGIN_HOOKS['item_delete']['example'] = 'plugin_item_delete_example'; $PLUGIN_HOOKS['item_purge']['example'] = 'plugin_item_purge_example';
$PLUGIN_HOOKS['pre_item_purge']['example'] = 'plugin_pre_item_purge_example'; $PLUGIN_HOOKS['pre_item_restore']['example'] = 'plugin_pre_item_restore_example';
$PLUGIN_HOOKS['item_purge']['example'] = 'plugin_item_purge_example'; $PLUGIN_HOOKS['item_restore']['example'] = 'plugin_item_restore_example';
$PLUGIN_HOOKS['pre_item_restore']['example'] = 'plugin_pre_item_restore_example'; $PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example';
$PLUGIN_HOOKS['item_restore']['example'] = 'plugin_item_restore_example';
$PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example'; //redirect appel http://localhost/glpi/index.php?redirect=plugin_example_2 (ID 2 du form)
$PLUGIN_HOOKS['redirect_page']['example'] = 'example.form.php';
//redirect appel http://localhost/glpi/index.php?redirect=plugin_example_2 (ID 2 du form) //function to populate planning
$PLUGIN_HOOKS['redirect_page']['example']="example.form.php"; $PLUGIN_HOOKS['planning_populate']['example'] = 'plugin_planning_populate_example';
//function to populate planning //function to display planning items
$PLUGIN_HOOKS['planning_populate']['example']="plugin_planning_populate_example"; $PLUGIN_HOOKS['display_planning']['example'] = 'plugin_display_planning_example';
//function to display planning items // Massive Action definition
$PLUGIN_HOOKS['display_planning']['example']="plugin_display_planning_example"; $PLUGIN_HOOKS['use_massive_action']['example'] = 1;
// Massive Action definition $PLUGIN_HOOKS['assign_to_ticket']['example'] = 1;
$PLUGIN_HOOKS['use_massive_action']['example']=1;
$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';
// Add specific files to add to the header : javascript or css // Retrieve others datas from LDAP
$PLUGIN_HOOKS['add_javascript']['example']="example.js"; //$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example";
$PLUGIN_HOOKS['add_css']['example']="example.css";
// Retrieve others datas from LDAP // Reports
//$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example"; $PLUGIN_HOOKS['reports']['example'] = array('report.php' => 'New Report',
'report.php?other' => 'New Report 2');
// Reports
$PLUGIN_HOOKS['reports']['example'] = array('report.php'=>'New Report', 'report.php?other'=>'New Report 2',);
// Stats
$PLUGIN_HOOKS['stats']['example'] = array('stat.php'=>'New stat', 'stat.php?other'=>'New stats 2',);
// Stats
$PLUGIN_HOOKS['stats']['example'] = array('stat.php' => 'New stat',
'stat.php?other' => 'New stats 2',);
} }
// Get the name and the version of the plugin - Needed // Get the name and the version of the plugin - Needed
function plugin_version_example(){ function plugin_version_example() {
return array(
'name' => 'Plugin Example', return array('name' => 'Plugin Example',
'version' => '0.2.0', 'version' => '0.2.0',
'author' => 'Julien Dombre', 'author' => 'Julien Dombre',
'homepage'=> 'http://glpi-project.org', 'homepage' => 'https://forge.indepnet.net/projects/show/example',
'minGlpiVersion' => '0.80',// For compatibility / no install in version < 0.72 'minGlpiVersion' => '0.80');// For compatibility / no install in version < 0.72
);
} }
// Optional : check prerequisites before install : may print errors or add to message after redirect // Optional : check prerequisites before install : may print errors or add to message after redirect
function plugin_example_check_prerequisites(){ function plugin_example_check_prerequisites() {
if (GLPI_VERSION>=0.80){
return true; if (GLPI_VERSION >= 0.80) {
} else { return true;
echo "GLPI version not compatible need 0.80"; } else {
} echo "GLPI version not compatible need 0.80";
}
} }
// Check configuration process for plugin : need to return true if succeeded // Check configuration process for plugin : need to return true if succeeded
// Can display a message only if failure and $verbose is true // Can display a message only if failure and $verbose is true
function plugin_example_check_config($verbose=false){ function plugin_example_check_config($verbose=false) {
global $LANG; global $LANG;
if (true) { // Your configuration check if (true) { // Your configuration check
return true; return true;
} }
if ($verbose) { if ($verbose) {
echo $LANG['plugins'][2]; echo $LANG['plugins'][2];
} }
return false; return false;
} }
?> ?>