模块开发: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 28: Line 28:
* 设置参数 MAIN_FEATURES_LEVEL 的值为 2 ( 设置 / 其他 )(或者修改llx_const表中该项的记录的value值为2)
* 设置参数 MAIN_FEATURES_LEVEL 的值为 2 ( 设置 / 其他 )(或者修改llx_const表中该项的记录的value值为2)
* 在主页 - 设置 -模块 中 激活 ModuleBuilder.
* 在主页 - 设置 -模块 中 激活 ModuleBuilder.
* 点击右上角的‘Bug’图标开始使用(或者在浏览器中输入'''yourhost/modulebuilder''')
* 点击右上角的‘Bug’图标开始使用(或者在浏览器中输入'yourhost/modulebuilder')
 


=模块实例=
=模块实例=
Line 43: Line 44:
* 创建目录 '''/htdocs/''mymodule''/core/modules'''. 从目录dev/skeletons拷贝文件modMyModule.class.php到新建目录。
* 创建目录 '''/htdocs/''mymodule''/core/modules'''. 从目录dev/skeletons拷贝文件modMyModule.class.php到新建目录。


将 modMyModule.class.php 改名,名称对应于您的模块。 名称以 'mod'开头,以.class.php结尾。 (例如:要创建模块 'NewName', 对应的模块名为'modNewName.class.php').
将 modMyModule.class.php 改名,名称对应于您的模块。 名称以 'mod'开头,以.class.php结尾。 (例如:要创建模块 'NewName', 对应的模块名为'modNewName.class.php').
接下来修改此文件的内容如下:
接下来修改此文件的内容如下:
* 替换所有 "modMyModule",对应于模块名称。 此值须以'mod'开头且仅含字符 (例如,模块为 'NewName', 替换所有 "modMyModule" 为 "modNewName")。
* 替换所有 "modMyModule",对应于模块名称。 此值须以'mod'开头且仅含字符 (例如,模块为 'NewName', 替换所有 "modMyModule" 为 "modNewName")。
Line 62: Line 63:
{{Template模块目录树}}
{{Template模块目录树}}


== Create your SQL tables and the PHP DAO class (optional) ==
== 创建数据表和表的PHP类文件 (可选) ==
'''When''': If your module needs to manage data of its own
'''何时''': 模块有自己的数据


=== Create your .sql file ===
=== 创建 .sql 文件 ===
If your module is designed to manage data of its own, which are not available in the standard version of Dolibarr, it is necessary to define SQL tables to store the data.
If your module is designed to manage data of its own, which are not available in the standard version of Dolibarr, it is necessary to define SQL tables to store the data.


Line 89: Line 90:
Files must be operational for the database mysql. Rem: The files of other databases are not maintained. They will be read and converted on the fly by the driver of the other database.
Files must be operational for the database mysql. Rem: The files of other databases are not maintained. They will be read and converted on the fly by the driver of the other database.


=== Test your .sql files ===
=== 测试 .sql 文件 ===


Once the files ready, you can return to Dolibarr to disable the module, drop those tables in database and reactivate the module. The tables should be recreated by the activation of the module. If this is not the case, check your scripts by passing them by hand, or check the Dolibarr logs.
Once the files ready, you can return to Dolibarr to disable the module, drop those tables in database and reactivate the module. The tables should be recreated by the activation of the module. If this is not the case, check your scripts by passing them by hand, or check the Dolibarr logs.
Line 107: Line 108:
'''Since Dolibarr 6.0, the file dev/skeletons/build_class_from_table.php is no more provided. To build a class from a table you should use the ModuleBuilder modules provided as standard module.'''
'''Since Dolibarr 6.0, the file dev/skeletons/build_class_from_table.php is no more provided. To build a class from a table you should use the ModuleBuilder modules provided as standard module.'''


== The tab management (optional) ==
== 选项卡管理(可选) ==


=== Add or remove your own tabs on object sheets ===
=== 增删对象的选项卡 ===
'''When''': To add a tab on an object (invoices, orders, proposals, member ...)
'''何时''': 增加对象选项卡 (对象是指‘发票’、‘订单’、‘提议’、‘会员’等等)


To do this go into the file descriptor of module previously created and edit the $this->tabs array:
To do this go into the file descriptor of module previously created and edit the $this->tabs array:
Line 133: Line 134:
To feed the contents of the tab with data from the database, see the next chapter.
To feed the contents of the tab with data from the database, see the next chapter.


=== Show tabs navigation into your own pages ===
=== 在你的页上显示选项卡导航 ===
'''When''': To show all standard tabs of an object (produit, tiers, etc.) on your page.
'''When''': To show all standard tabs of an object (produit, tiers, etc.) on your page.


Line 206: Line 207:
'''When''': If the purpose of your module is to add features that require new or modified screens.
'''When''': If the purpose of your module is to add features that require new or modified screens.


=== Create a new PHP screen ===
=== 创建新 PHP 屏显 ===
You must then create your PHP pages that will show/edit data from tables using the skeleton templates provided as an example in the directory '''modulebuilder/myobject_page.php''' (For the development of a script from the command line, see [[Script development]]).
You must then create your PHP pages that will show/edit data from tables using the skeleton templates provided as an example in the directory '''modulebuilder/myobject_page.php''' (For the development of a script from the command line, see [[Script development]]).


Line 253: Line 254:
</source>
</source>


=== Add some fields into existing forms ===
=== 现在表单增加新字段 ===
You may want to provide a module that add more fields into forms (input and view) of some elements.  
You may want to provide a module that add more fields into forms (input and view) of some elements.  


Line 264: Line 265:
{{ToComplete}}
{{ToComplete}}


=== Replace parts of screen that are templated (version 3.3+) ===
=== 替换模板的部分内容 (version 3.3+) ===
Some parts of Dolibarr screen are isolated into native PHP template files.
Some parts of Dolibarr screen are isolated into native PHP template files.
You can develop a module to overwrite such templates with yours.
You can develop a module to overwrite such templates with yours.
{{ToComplete}}
{{ToComplete}}


=== Add/replace part of fields supported by hooks ===
=== 增/换部分字段(需钩子支持) ===
See chapter [[Hooks_system#Implement_the_Hook]] to know how to use Dolibarr existing hooks to add/replace code at Dolibarr hooks place.
See chapter [[Hooks_system#Implement_the_Hook]] to know how to use Dolibarr existing hooks to add/replace code at Dolibarr hooks place.


=== Database access ===
=== 数据通道 ===
If you need to edit some data in database inside you own table, use the PHP class generated before.
If you need to edit some data in database inside you own table, use the PHP class generated before.


Line 311: Line 312:
</source>
</source>


=== Define style of your pages ===
=== 页面风格 ===
To have the look of your own pages to match the Dolibarr theme, it is necessary to use the Dolibarr CSS styles.
To have the look of your own pages to match the Dolibarr theme, it is necessary to use the Dolibarr CSS styles.


Line 321: Line 322:
* class="'''button'''" on HTML fields with type ''input type="submit"''.
* class="'''button'''" on HTML fields with type ''input type="submit"''.


=== Use the Dolibarr date picker ===
=== 使用Dolibarr日期选择器 ===
If you want to use the Dolibarr date selector (with its calendar popup) into your pages, use the following line:
If you want to use the Dolibarr date selector (with its calendar popup) into your pages, use the following line:
<source lang="php">
<source lang="php">
Line 337: Line 338:
</source>
</source>


== Add your own setup page (optional) ==
== 新增设置页 (可选) ==
'''When''': If your module needs parameters, which are to be provided by the user, for proper setting up of the module.
'''When''': If your module needs parameters, which are to be provided by the user, for proper setting up of the module.


=== Create your page to edit parameters ===
=== 创建页面以编辑参数 ===
If your module needs several parameters to be setup, you must create a page to edit options (these options will be saved in the [[Table llx_const|table '''llx_const''']]).
If your module needs several parameters to be setup, you must create a page to edit options (these options will be saved in the [[Table llx_const|table '''llx_const''']]).
Create a page named '''mymodule_setuppage.php''' that shows a form for possible options to update them into the above mentioned table.
Create a page named '''mymodule_setuppage.php''' that shows a form for possible options to update them into the above mentioned table.
Line 346: Line 347:
Put this PHP page into the directory '''/admin''' of your module (e.g. mymodule/admin/mymodule_setuppage.php).
Put this PHP page into the directory '''/admin''' of your module (e.g. mymodule/admin/mymodule_setuppage.php).


=== Modify the descriptor file of your module ===
=== 修改模块主文件 ===
Then, within the descriptor file of your module, modify the variable '''config_page_url''' to set name of this PHP page.
Then, within the descriptor file of your module, modify the variable '''config_page_url''' to set name of this PHP page.
If the page is in the directory '''admin/''', then the path is not required, e.g. like this:
If the page is in the directory '''admin/''', then the path is not required, e.g. like this:
Line 357: Line 358:
</source>
</source>


=== Test your page ===
=== 测试页面 ===
Go into page '''Home->Setup->Modules''', you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page.
Go into page '''Home->Setup->Modules''', you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page.


== Define your entries in menu (optional) ==
== 增加菜单条目 (可选) ==
'''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu.
'''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu.


=== Define your menu entries ===
=== 增加菜单条目 ===
For this, you must define into the module descriptor, the array this->menu that declare all menus added by your module.
For this, you must define into the module descriptor, the array this->menu that declare all menus added by your module.
This array contains entries that will appear once your module is activated.
This array contains entries that will appear once your module is activated.
Line 408: Line 409:
To show menu or not depending on a permission, modify property '''perms''' in array. See chapter on permissions later to see how to add permissions.
To show menu or not depending on a permission, modify property '''perms''' in array. See chapter on permissions later to see how to add permissions.


=== Test your menu entries ===
=== 测试菜单 ===
Disable and reenable your module under Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok).
Disable and reenable your module under Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok).


== Add your own permissions (optional) ==
== 新增权限 (可选) ==
'''When''': If you want to add new permissions.
'''When''': If you want to add new permissions.


Line 441: Line 442:
</source>
</source>


== Define you own box (optional) ==
== 信息窗 (可选) ==
'''When''': If your module need to provide one or several new boxes to show on home page.
'''When''': If your module need to provide one or several new boxes to show on home page.


=== Define your box ===
=== 信息窗 ===
For this, modify the array $this->boxes into the module descriptor file.
For this, modify the array $this->boxes into the module descriptor file.
All you have to do is to add 2 lines for each box file you will create into directory '''htdocs/mymodule/core/boxes'''
All you have to do is to add 2 lines for each box file you will create into directory '''htdocs/mymodule/core/boxes'''
Line 469: Line 470:
'''When''': If your module provide new predefined database export profiles (for its own tables or for already existing tables of another module).
'''When''': If your module provide new predefined database export profiles (for its own tables or for already existing tables of another module).


=== Define export ===
=== 导出 ===
For this uncomment and modify arrays $this->export_xxx in your module descriptor file.
For this uncomment and modify arrays $this->export_xxx in your module descriptor file.


Line 498: Line 499:
You should see into the HTML header, a line that declare your style sheet.
You should see into the HTML header, a line that declare your style sheet.


== Add your Javascript functions (optional) ==
== 增加JS函数功能 (可选) ==
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)


Line 510: Line 511:
</source>
</source>


== Run your own code on any Dolibarr event (optional) ==
== 执行Dolibarr事件代码 (可选) ==
'''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''.
'''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''.


Line 516: Line 517:
and [[Interfaces_from_foreign_systems_toward_Dolibarr]]
and [[Interfaces_from_foreign_systems_toward_Dolibarr]]


== Insert your code inside Dolibarr hooks positions (optional) ==
== 钩子代码 (可选) ==
'''When''': When you want to add code or replace Dolibarr code into another situation than a business event (See previous chapter for adding code during a business event).
'''When''': When you want to add code or replace Dolibarr code into another situation than a business event (See previous chapter for adding code during a business event).


Line 522: Line 523:




== Add your own numbering rules ==
== 添加编码规则 ==
'''When''': When you need a new rule for generated ref of elements that is not covered by existing rules.
'''When''': When you need a new rule for generated ref of elements that is not covered by existing rules.


See page [[Create numbering module]].
See page [[Create numbering module]].


== Add your document template (optional) ==
== 创建文档模板 (optional) ==
'''When''': When you want to personalized your own generated PDF or ODT documents.
'''When''': When you want to personalized your own generated PDF or ODT documents.


Line 534: Line 535:
Documentation to add your own template is available on page [[Create_a_PDF_document_template]] or [[Create_an_ODT_document_template]].
Documentation to add your own template is available on page [[Create_a_PDF_document_template]] or [[Create_an_ODT_document_template]].


== Add your skin (optional) ==
== 创建主题 (optional) ==
'''When''': When you want to personalized your colors/fonts/images.
'''When''': When you want to personalized your colors/fonts/images.


Line 541: Line 542:
To add your own skin, read page [[Skins]].
To add your own skin, read page [[Skins]].


=Some coding rules and predefined functions =
=一些编码规则和预定义函数 =
The coding rules to be followed are defined in the [[Developer documentation]], under section "General Information - Language and standards development".
The coding rules to be followed are defined in the [[Developer documentation]], under section "General Information - Language and standards development".


A lot of predefined features for developers are also available and described into page [[Developer documentation]] under section "Technical components of Dolibarr".
A lot of predefined features for developers are also available and described into page [[Developer documentation]] under section "Technical components of Dolibarr".


=Using MDA =
=使用 MDA =
A method to generate a functional module from a UML model has been developed. More information on the page [[UML2Dolibarr - Build a module using MDA]].
A method to generate a functional module from a UML model has been developed. More information on the page [[UML2Dolibarr - Build a module using MDA]].


=Create a package to distribute and install your module =
=创建一个安装包来分发和安装您的模块 =
This process must be used to generate a package to submit it on the http://www.dolistore.com market place.
This process must be used to generate a package to submit it on the http://www.dolistore.com market place.
But you can use it to have a package easy to distribute on your on network.
But you can use it to have a package easy to distribute on your on network.
Line 572: Line 573:
** If quality is enough and license permits it, code might be added inside main Dolibarr sources (except if you disagree for that).
** If quality is enough and license permits it, code might be added inside main Dolibarr sources (except if you disagree for that).


= Enabling/activation condition of external module on DoliStore =
= Delistor上的外部模块的启用/激活条件 =


See [[Module_Dolistore_Validation_Rules|Validation Rules]]
See [[Module_Dolistore_Validation_Rules|Validation Rules]]
513

edits

Navigation menu