clean + fix table name

git-svn-id: https://forge.glpi-project.org/svn/example/trunk@116 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
remicollet 2009-12-12 18:51:33 +00:00
parent d5d2a93dc7
commit c16272abf4
4 changed files with 19 additions and 24 deletions

View File

@ -54,7 +54,7 @@ function plugin_change_profile_example() {
// Define dropdown relations // Define dropdown relations
function plugin_example_getDatabaseRelations(){ function plugin_example_getDatabaseRelations(){
// //
return array("glpi_plugin_example_dropdown"=>array("glpi_plugin_example"=>"plugin_example_dropdown_id")); return array("glpi_plugin_example_dropdowns"=>array("glpi_plugin_example"=>"plugin_example_dropdowns_id"));
} }
@ -73,9 +73,9 @@ function plugin_example_getAddSearchOptions($itemtype){
$sopt=array(); $sopt=array();
if ($itemtype == COMPUTER_TYPE) { if ($itemtype == COMPUTER_TYPE) {
// Just for example, not working... // Just for example, not working...
$sopt[1001]['table'] = 'glpi_plugin_example_dropdown'; $sopt[1001]['table'] = 'glpi_plugin_example_dropdowns';
$sopt[1001]['field'] = 'name'; $sopt[1001]['field'] = 'name';
$sopt[1001]['linkfield'] = 'plugin_example_dropdown_id'; $sopt[1001]['linkfield'] = 'plugin_example_dropdowns_id';
$sopt[1001]['name'] = 'Example plugin'; $sopt[1001]['name'] = 'Example plugin';
} }
@ -105,7 +105,7 @@ function plugin_example_addLeftJoin($type,$ref_table,$new_table,$linkfield){
// Example of standard LEFT JOIN clause but use it ONLY for specific LEFT JOIN // Example of standard LEFT JOIN clause but use it ONLY for specific LEFT JOIN
// No need of the function if you do not have specific cases // No need of the function if you do not have specific cases
switch ($new_table){ switch ($new_table){
case "glpi_plugin_example_dropdown" : case "glpi_plugin_example_dropdowns" :
return " LEFT JOIN $new_table ON ($ref_table.$linkfield = $new_table.id) "; return " LEFT JOIN $new_table ON ($ref_table.$linkfield = $new_table.id) ";
break; break;
} }
@ -307,7 +307,7 @@ function plugin_example_MassiveActionsFieldsDisplay($type,$table,$field,$linkfie
} else { } else {
// Linked Fields // Linked Fields
switch ($table.".".$field){ switch ($table.".".$field){
case "glpi_plugin_example_dropdown.name" : case "glpi_plugin_example_dropdowns.name" :
echo "Not really specific - Just for example "; echo "Not really specific - Just for example ";
dropdown($table,$linkfield,1,$_SESSION["glpiactive_entity"]); dropdown($table,$linkfield,1,$_SESSION["glpiactive_entity"]);
//dropdownUsers($linkfield,0,"own_ticket",0,1,$_SESSION["glpiactive_entity"]); //dropdownUsers($linkfield,0,"own_ticket",0,1,$_SESSION["glpiactive_entity"]);
@ -707,7 +707,7 @@ function plugin_example_install(){
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL, `name` varchar(255) collate utf8_unicode_ci default NULL,
`serial` varchar(255) collate utf8_unicode_ci NOT NULL, `serial` varchar(255) collate utf8_unicode_ci NOT NULL,
`plugin_example_dropdown_id` int(11) NOT NULL default '0', `plugin_example_dropdowns_id` int(11) NOT NULL default '0',
`is_deleted` smallint(6) NOT NULL default '0', `is_deleted` smallint(6) NOT NULL default '0',
`is_template` smallint(6) NOT NULL default '0', `is_template` smallint(6) NOT NULL default '0',
`template_name` varchar(255) collate utf8_unicode_ci default NULL, `template_name` varchar(255) collate utf8_unicode_ci default NULL,
@ -715,16 +715,16 @@ function plugin_example_install(){
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
"; ";
$DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error()); $DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error());
$query="INSERT INTO `glpi_plugin_example_examples` (`id`, `name`, `serial`, `plugin_example_dropdown_id`, $query="INSERT INTO `glpi_plugin_example_examples` (`id`, `name`, `serial`, `plugin_example_dropdowns_id`,
`is_deleted`, `is_template`, `template_name`) VALUES `is_deleted`, `is_template`, `template_name`) VALUES
(1, 'example 1', 'serial 1', 1, 0, 0, NULL), (1, 'example 1', 'serial 1', 1, 0, 0, NULL),
(2, 'example 2', 'serial 2', 2, 0, 0, NULL), (2, 'example 2', 'serial 2', 2, 0, 0, NULL),
(3, 'example 3', 'serial 3', 1, 0, 0, NULL);"; (3, 'example 3', 'serial 3', 1, 0, 0, NULL);";
$DB->query($query) or die("error populate glpi_plugin_example ". $DB->error()); $DB->query($query) or die("error populate glpi_plugin_example ". $DB->error());
} }
if (!TableExists("glpi_plugin_example_dropdown")){ if (!TableExists("glpi_plugin_example_dropdowns")){
$query="CREATE TABLE `glpi_plugin_example_dropdown` ( $query="CREATE TABLE `glpi_plugin_example_dropdowns` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL, `name` varchar(255) collate utf8_unicode_ci default NULL,
`comment` text collate utf8_unicode_ci, `comment` text collate utf8_unicode_ci,
@ -732,11 +732,11 @@ function plugin_example_install(){
KEY `name` (`name`) KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query) or die("error creating glpi_plugin_example_dropdown". $DB->error()); $DB->query($query) or die("error creating glpi_plugin_example_dropdowns". $DB->error());
$query="INSERT INTO `glpi_plugin_example_dropdown` (`id`, `name`, `comment`) VALUES $query="INSERT INTO `glpi_plugin_example_dropdowns` (`id`, `name`, `comment`) VALUES
(1, 'dp 1', 'comment 1'), (1, 'dp 1', 'comment 1'),
(2, 'dp2', 'comment 2');"; (2, 'dp2', 'comment 2');";
$DB->query($query) or die("error populate glpi_plugin_example_dropdown". $DB->error()); $DB->query($query) or die("error populate glpi_plugin_example_dropdowns". $DB->error());
} }
@ -766,9 +766,9 @@ function plugin_example_uninstall(){
$query="DROP TABLE `glpi_plugin_example_example`;"; $query="DROP TABLE `glpi_plugin_example_example`;";
$DB->query($query) or die("error deleting glpi_plugin_example_example"); $DB->query($query) or die("error deleting glpi_plugin_example_example");
} }
if (TableExists("glpi_plugin_example_dropdown")){ if (TableExists("glpi_plugin_example_dropdowns")){
$query="DROP TABLE `glpi_plugin_example_dropdown`;"; $query="DROP TABLE `glpi_plugin_example_dropdowns`;";
$DB->query($query) or die("error deleting glpi_plugin_example_dropdown"); $DB->query($query) or die("error deleting glpi_plugin_example_dropdowns");
} }
return true; return true;
} }

View File

@ -37,7 +37,7 @@
class PluginExampleDropdown extends CommonDropdown { class PluginExampleDropdown extends CommonDropdown {
// From CommonDBTM // From CommonDBTM
public $table = 'glpi_plugin_example_dropdown'; public $table = 'glpi_plugin_example_dropdowns';
public $type = 'PluginExampleDropdown'; public $type = 'PluginExampleDropdown';
static function getTypeName() { static function getTypeName() {

View File

@ -73,9 +73,9 @@ class PluginExampleExample extends CommonDBTM {
$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_dropdown'; $tab[2]['table']='glpi_plugin_example_dropdowns';
$tab[2]['field']='name'; $tab[2]['field']='name';
$tab[2]['linkfield']='plugin_example_dropdown_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';

View File

@ -40,10 +40,7 @@ function plugin_init_example() {
// Params : plugin name - string type - ID - Array of attributes // Params : plugin name - string type - ID - Array of attributes
Plugin::registerClass('PluginExampleExample', array( Plugin::registerClass('PluginExampleExample', array(
'classname' => 'PluginExampleExample', 'classname' => 'PluginExampleExample',
'tablename' => 'glpi_plugin_example_example',
'formpage' => 'front/example.form.php', 'formpage' => 'front/example.form.php',
'searchpage' => 'front/example.php',
'typename' => 'Example Type',
'deleted_tables' => false, 'deleted_tables' => false,
'template_tables' => false, 'template_tables' => false,
'specif_entities_tables' => false, 'specif_entities_tables' => false,
@ -55,10 +52,8 @@ function plugin_init_example() {
// Params : plugin name - string type - ID - Array of attributes // Params : plugin name - string type - ID - Array of attributes
Plugin::registerClass('PluginExampleDropdown', array( Plugin::registerClass('PluginExampleDropdown', array(
'classname' => 'PluginExampleDropdown', 'classname' => 'PluginExampleDropdown',
'tablename' => 'glpi_plugin_example_dropdown',
'typename' => 'Example Dropdown Type', 'typename' => 'Example Dropdown Type',
'formpage' => 'front/dropdown.form.php', 'formpage' => 'front/dropdown.form.php'));
'searchpage' => 'front/dropdown.php'));
// Display a menu entry ? // Display a menu entry ?
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