php 为vtiger创建模块

x0fgdtte  于 2024-01-05  发布在  PHP
关注(0)|答案(1)|浏览(270)

我想创建一个模块,并在vtiger中开发它,所以我创建了一个包含一些脚本的文件。我在某个地方找到了这个,我用了它。据说它可以工作,并使表和运行后,如果你再次运行脚本,你给了这个错误Module already present - choose a different name。我的问题是没有与新模块相关的文件夹,也没有工具子菜单中的模块!如果我想更新它,例如添加任何字段或更改一些东西。如何做?
这是我在vtiger根目录下的文件:

  1. <?php
  2. include_once 'vtlib/Vtiger/Module.php';
  3. $Vtiger_Utils_Log = true;
  4. $MODULENAME = 'namava';
  5. $moduleInstance = Vtiger_Module::getInstance($MODULENAME);
  6. if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
  7. echo "Module already present - choose a different name.";
  8. } else {
  9. $moduleInstance = new Vtiger_Module();
  10. $moduleInstance->name = $MODULENAME;
  11. $moduleInstance->parent = 'Tools';
  12. $moduleInstance->save();
  13. // Schema Setup
  14. $moduleInstance->initTables();
  15. // Field Setup
  16. $block = new Vtiger_Block();
  17. $block->label = 'LBL_' . strtoupper($moduleInstance->name) . '_INFORMATION';
  18. $moduleInstance->addBlock($block);
  19. $blockcf = new Vtiger_Block();
  20. $blockcf->label = 'LBL_CUSTOM_INFORMATION';
  21. $moduleInstance->addBlock($blockcf);
  22. $field1 = new Vtiger_Field();
  23. $field1->name = 'summary';
  24. $field1->label = 'Summary';
  25. $field1->uitype = 2;
  26. $field1->column = $field1->name;
  27. $field1->columntype = 'VARCHAR(255)';
  28. $field1->typeofdata = 'V~M';
  29. $block->addField($field1);
  30. $moduleInstance->setEntityIdentifier($field1);
  31. $field2 = new Vtiger_Field();
  32. $field2->name = 'film';
  33. $field2->label = 'film On';
  34. $field2->uitype = 5;
  35. $field2->column = $field2->name;
  36. $field2->columntype = 'Date';
  37. $field2->typeofdata = 'D~O';
  38. $block->addField($field2);
  39. $field3 = new Vtiger_Field();
  40. $field3->name = 'actor';
  41. $field3->label = 'actor on';
  42. $field3->uitype = 71;
  43. $field3->column = $field3->name;
  44. $field3->columntype = 'VARCHAR(255)';
  45. $field3->typeofdata = 'V~M';
  46. $block->addField($field3);
  47. $field3 = new Vtiger_Field();
  48. $field3->name = 'description';
  49. $field3->label = 'Description';
  50. $field3->uitype = 19;
  51. $field3->column = 'description';
  52. $field3->table = 'vtiger_crmentity';
  53. $blockcf->addField($field3);
  54. // Recommended common fields every Entity module should have (linked to core table)
  55. $mfield1 = new Vtiger_Field();
  56. $mfield1->name = 'assigned_user_id';
  57. $mfield1->label = 'Assigned To';
  58. $mfield1->table = 'vtiger_crmentity';
  59. $mfield1->column = 'smownerid';
  60. $mfield1->uitype = 53;
  61. $mfield1->typeofdata = 'V~M';
  62. $block->addField($mfield1);
  63. $mfield2 = new Vtiger_Field();
  64. $mfield2->name = 'CreatedTime';
  65. $mfield2->label = 'Created Time';
  66. $mfield2->table = 'vtiger_crmentity';
  67. $mfield2->column = 'createdtime';
  68. $mfield2->uitype = 70;
  69. $mfield2->typeofdata = 'T~O';
  70. $mfield2->displaytype = 2;
  71. $block->addField($mfield2);
  72. $mfield3 = new Vtiger_Field();
  73. $mfield3->name = 'ModifiedTime';
  74. $mfield3->label = 'Modified Time';
  75. $mfield3->table = 'vtiger_crmentity';
  76. $mfield3->column = 'modifiedtime';
  77. $mfield3->uitype = 70;
  78. $mfield3->typeofdata = 'T~O';
  79. $mfield3->displaytype = 2;
  80. $block->addField($mfield3);
  81. // Filter Setup
  82. $filter1 = new Vtiger_Filter();
  83. $filter1->name = 'All';
  84. $filter1->isdefault = true;
  85. $moduleInstance->addFilter($filter1);
  86. $filter1->addField($field1)->addField($field2, 1)->addField($field3, 2)->addField($mfield1, 3);
  87. // Sharing Access Setup
  88. $moduleInstance->setDefaultSharing();
  89. }

字符串
我还使用了另一种方法来创建模块的 backbone 与php vtlib/tools/console.php,但我的问题是,它只创建一个字段,我不知道如何添加更多的字段在代码中与这种方式
请告诉我怎么做。

waxmsbnn

waxmsbnn1#

1.错误:模块已存在-请选择其他名称
这意味着你已经执行了你的脚本,或者你正在尝试用一个现有的模块名创建一个模块。在你的脚本文件中查看if条件。
1.添加新字段
如果你仍然想添加更多的字段,那么你需要删除if条件和这段代码。

  1. // Add a New module, and remove these 4 lines once the script is executed and the module exists in the vtiger_tab table.
  2. $moduleInstance = new Vtiger_Module();
  3. $moduleInstance->name = $MODULENAME;
  4. $moduleInstance->parent = 'Tools';
  5. $moduleInstance->save();
  6. // This line creates new tables for your module
  7. // 1. vtiger_modulename
  8. // 2. vtiger_modulenamecf
  9. $moduleInstance->initTables();
  10. // This code block adds a new Block and adds an entry in vtiger_blocks. If it does not exist then you can re-execute else remove it from a script.
  11. $block = new Vtiger_Block();
  12. $block->label = 'LBL_' . strtoupper($moduleInstance->name) . '_INFORMATION';
  13. $moduleInstance->addBlock($block);

字符串
1.在菜单中添加模块
在脚本中添加此行,以在菜单中添加模块名称

  1. Settings_MenuEditor_Module_Model::addModuleToApp($moduleInstance->name, $moduleInstance->parent);

展开查看全部

相关问题