主模块代码框架: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with "<source lang="php"> <?php /* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) ---Put here your own copyright and developer email--- * ...")
 
No edit summary
Line 1: Line 1:
<source lang="php">
<source lang="php">
<?php
<?php
/* Copyright (C) 2004-2018 Laurent Destailleur  <eldy@users.sourceforge.net>
/*版权信息
*Copyright (C) 2004-2018 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) ---Put here your own copyright and developer email---
  * Copyright (C) ---Put here your own copyright and developer email---
  *
  *
Line 19: Line 20:


/**
/**
  * \defgroup  mymodule    Module MyModule
  * 文档描述
*  \defgroup  mymodule    Module MyModule
  *  \brief      MyModule module descriptor.
  *  \brief      MyModule module descriptor.
  *
  *
Line 26: Line 28:
  *  \brief      Description and activation file for module MyModule
  *  \brief      Description and activation file for module MyModule
  */
  */
//包含文件
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';




// 类名,应以小写mod开头
// The class name should start with a lower case mod for Dolibarr to pick it up
// The class name should start with a lower case mod for Dolibarr to pick it up
// so we ignore the Squiz.Classes.ValidClassName.NotCamelCaps rule.
// so we ignore the Squiz.Classes.ValidClassName.NotCamelCaps rule.
// @codingStandardsIgnoreStart
// @codingStandardsIgnoreStart
/**
/**
*  描述并激活自定义类
  *  Description and activation class for module MyModule
  *  Description and activation class for module MyModule
  */
  */
Line 39: Line 46:
// @codingStandardsIgnoreEnd
// @codingStandardsIgnoreEnd
/**
/**
* 构造器、定义名、结构、目录、信息框、权限
*
* Constructor. Define names, constants, directories, boxes, permissions
* Constructor. Define names, constants, directories, boxes, permissions
*
*
Line 45: Line 54:
public function __construct($db)
public function __construct($db)
{
{
//加载全局变量 $langs,$conf
         global $langs,$conf;
         global $langs,$conf;


         $this->db = $db;
         $this->db = $db;


// Id for module (must be unique).
//模块ID(唯一)
//Id for module (must be unique).
// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
$this->numero = 500000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
$this->numero = 500000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
// Key text used to identify module (for permissions, menus, etc...)
//识别模块的关键字(为权限管理、目录等)
//Key text used to identify module (for permissions, menus, etc...)
$this->rights_class = 'mymodule';
$this->rights_class = 'mymodule';


// Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
//家族分类,用来归类模块,于'主页'-'设置'-'模块'界面
//Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
// It is used to group modules by family in module setup page
// It is used to group modules by family in module setup page
$this->family = "other";
$this->family = "other";
// Module position in the family on 2 digits ('01', '10', '20', ...)
//模块在家族里的位置(2位数) Module position in the family on 2 digits ('01', '10', '20', ...)
$this->module_position = '90';
$this->module_position = '90';
// Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
// Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
//$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
//$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));


// Module label (no space allowed), used if translation string 'ModuleMyModuleName' not found (MyModue is name of module).
// 模块标签(无空格)Module label (no space allowed), used if translation string 'ModuleMyModuleName' not found (MyModue is name of module).
$this->name = preg_replace('/^mod/i','',get_class($this));
$this->name = preg_replace('/^mod/i','',get_class($this));
// Module description, used if translation string 'ModuleMyModuleDesc' not found (MyModue is name of module).
// 模块描述Module description, used if translation string 'ModuleMyModuleDesc' not found (MyModue is name of module).
$this->description = "MyModuleDescription";
$this->description = "MyModuleDescription";
// Used only if file README.md and README-LL.md not found.
// Used only if file README.md and README-LL.md not found.
Line 73: Line 89:
$this->editor_url = 'https://www.example.com';
$this->editor_url = 'https://www.example.com';


// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
//版本名,可用的包括:Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
$this->version = '1.0';
$this->version = '1.0';
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
// Name of image file used for this module.
// 模块的图像文件名Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
$this->picto='generic';
$this->picto='generic';


// Defined all module parts (triggers, login, substitutions, menus, css, etc...)
// 定义所有模块组成。Defined all module parts (triggers, login, substitutions, menus, css, etc...)
// for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable)
// for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable)
// for specific path of parts (eg: /mymodule/core/modules/barcode)
// for specific path of parts (eg: /mymodule/core/modules/barcode)
Line 88: Line 104:
$this->module_parts = array(
$this->module_parts = array(
                        'triggers' => 1,                                // Set this to 1 if module has its own trigger directory (core/triggers)
                        'triggers' => 1,                                // Set this to 1 if module has its own trigger directory (core/triggers)
'login' => 0,                                    // Set this to 1 if module has its own login method file (core/login)
'login' => 0,                                    // Set this to 1 if module has its own login method file (core/login)
'substitutions' => 1,                            // Set this to 1 if module has its own substitution function file (core/substitutions)
'substitutions' => 1,                            // Set this to 1 if module has its own substitution function file (core/substitutions)
'menus' => 0,                                    // Set this to 1 if module has its own menus handler directory (core/menus)
'menus' => 0,                                    // Set this to 1 if module has its own menus handler directory (core/menus)
'theme' => 0,                                    // Set this to 1 if module has its own theme directory (theme)
'theme' => 0,                                    // Set this to 1 if module has its own theme directory (theme)
                        'tpl' => 0,                                      // Set this to 1 if module overwrite template dir (core/tpl)
                        'tpl' => 0,                                      // Set this to 1 if module overwrite template dir (core/tpl)
'barcode' => 0,                                  // Set this to 1 if module has its own barcode directory (core/modules/barcode)
'barcode' => 0,                                  // Set this to 1 if module has its own barcode directory (core/modules/barcode)
'models' => 0,                                  // Set this to 1 if module has its own models directory (core/modules/xxx)
'models' => 0,                                  // Set this to 1 if module has its own models directory (core/modules/xxx)
'css' => array('/mymodule/css/mymodule.css.php'), // Set this to relative path of css file if module has its own css file
'css' => array('/mymodule/css/mymodule.css.php'), // Set this to relative path of css file if module has its own css file
'js' => array('/mymodule/js/mymodule.js.php'),          // Set this to relative path of js file if module must load a js on all pages
'js' => array('/mymodule/js/mymodule.js.php'),          // Set this to relative path of js file if module must load a js on all pages
'hooks' => array('data'=>array('hookcontext1','hookcontext2'), 'entity'=>'0') // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context 'all'
'hooks' => array('data'=>array('hookcontext1','hookcontext2'), 'entity'=>'0') // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context 'all'
                        );
                        );


// Data directories to create when module is enabled.
// 数据目录,Data directories to create when module is enabled.
// Example: this->dirs = array("/mymodule/temp","/mymodule/subdir");
// Example: this->dirs = array("/mymodule/temp","/mymodule/subdir");
$this->dirs = array();
$this->dirs = array();


// Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module.
// 设置页面,Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module.
$this->config_page_url = array("setup.php@mymodule");
$this->config_page_url = array("setup.php@mymodule");


Line 120: Line 136:
//$this->always_enabled = true; // If true, can't be disabled
//$this->always_enabled = true; // If true, can't be disabled


// Constants
// 常量,Constants
// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
Line 137: Line 153:




// Array to add new pages in new tabs
// 增加选项卡,Array to add new pages in new tabs
         $this->tabs = array();
         $this->tabs = array();
// Example:
// Example:
Line 166: Line 182:




         // Dictionaries
         // 字典,Dictionaries
$this->dictionaries=array();
$this->dictionaries=array();
         /* Example:
         /* Example:
Line 184: Line 200:




         // Boxes/Widgets
         // 信息框/插件,Boxes/Widgets
// Add here list of php file(s) stored in mymodule/core/boxes that contains class to show a widget.
// Add here list of php file(s) stored in mymodule/core/boxes that contains class to show a widget.
         $this->boxes = array(
         $this->boxes = array(
Line 228: Line 244:




// Main menu entries
// 主菜单条目 Main menu entries
$this->menu = array(); // List of menus to add
$this->menu = array(); // List of menus to add
$r=0;
$r=0;


// Add here entries to declare new menus
// 增加菜单条目,Add here entries to declare new menus


/* BEGIN MODULEBUILDER TOPMENU */
/* 项部菜单,BEGIN MODULEBUILDER TOPMENU */
$this->menu[$r++]=array('fk_menu'=>'',                 // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
$this->menu[$r++]=array('fk_menu'=>'',                 // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'top',                 // This is a Top menu entry
'type'=>'top',                 // This is a Top menu entry
Line 248: Line 264:
'user'=>2);                 // 0=Menu for internal users, 1=external users, 2=both
'user'=>2);                 // 0=Menu for internal users, 1=external users, 2=both


/* END MODULEBUILDER TOPMENU */
/* 项部菜单结束,END MODULEBUILDER TOPMENU */


/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
/* 对象左侧菜单开始,BEGIN MODULEBUILDER LEFTMENU MYOBJECT
$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=mymodule',     // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=mymodule',     // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left',                 // This is a Left menu entry
'type'=>'left',                 // This is a Left menu entry
513

edits

Navigation menu