vTigerCRM 6.5创建自定义模块
2017-11-27 本文已影响0人
misaka去年夏天
- 新建安装需要的配置文件和语言包
新建install_modules/Mymodule/languages/en_us/Mymodule.php
<?php
$languageStrings = array(
);
$jsLanguageStrings = array(
);
新建install_modules/Mymodule/languages/zh_cn/Mymodule.php
<?php
*************************************************************************************/
$languageStrings = array(
'Mymodule' => 'xxxx',
//.....
);
$jsLanguageStrings = array(
);
新建install_modules/Mymodule/modules/Mymodule/Mymodule.php
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
include_once 'modules/Vtiger/CRMEntity.php';
class Payments extends Vtiger_CRMEntity {
var $table_name = 'vtiger_mymodule';
var $table_index= 'mymoduleid';
/**
* Mandatory table for supporting custom fields.
*/
var $customFieldTable = Array('vtiger_mymodule', 'mymoduleid');
/**
* Mandatory for Saving, Include tables related to this module.
*/
var $tab_name = Array('vtiger_crmentity', 'vtiger_mymodule, 'vtiger_mymodulecf');
/**
* Mandatory for Saving, Include tablename and tablekey columnname here.
*/
var $tab_name_index = Array(
'vtiger_crmentity' => 'crmid',
'vtiger_mymodule => 'mymoduleid',
'vtiger_mymodulecf'=>'mymoduleid');
/**
* Mandatory for Listing (Related listview)
*/
var $list_fields = Array (
/* Format: Field Label => Array(tablename, columnname) */
// tablename should not have prefix 'vtiger_'
'Account Name' => Array('vtiger_mymodule', 'accountname'),
'Assigned To' => Array('crmentity','smownerid')
);
var $list_fields_name = Array (
/* Format: Field Label => fieldname */
'Account Name' => 'accountname',
'Assigned To' => 'assigned_user_id',
);
// Make the field link to detail view
var $list_link_field = 'accountname';
// For Popup listview and UI type support
var $search_fields = Array(
/* Format: Field Label => Array(tablename, columnname) */
// tablename should not have prefix 'vtiger_'
'Account Name' => Array('mymodule', 'accountname'),
'Assigned To' => Array('vtiger_crmentity','assigned_user_id'),
);
var $search_fields_name = Array (
/* Format: Field Label => fieldname */
'Account Name' => 'accountname',
'Assigned To' => 'assigned_user_id',
);
// For Popup window record selection
var $popup_fields = Array ('accountname');
// For Alphabetical search
var $def_basicsearch_col = 'accountname';
// Column value to use on detail view record text display
var $def_detailview_recname = 'accountname';
// Used when enabling/disabling the mandatory fields for the module.
// Refers to vtiger_field.fieldname values.
var $mandatory_fields = Array('accountname','assigned_user_id');
var $default_order_by = 'accountname';
var $default_sort_order='ASC';
/**
* Invoked when special actions are performed on the module.
* @param String Module name
* @param String Event Type
*/
function vtlib_handler($moduleName, $eventType) {
global $adb;
if($eventType == 'module.postinstall') {
// TODO Handle actions after this module is installed.
} else if($eventType == 'module.disabled') {
// TODO Handle actions before this module is being uninstalled.
} else if($eventType == 'module.preuninstall') {
// TODO Handle actions when this module is about to be deleted.
} else if($eventType == 'module.preupdate') {
// TODO Handle actions before this module is updated.
} else if($eventType == 'module.postupdate') {
// TODO Handle actions after this module is updated.
}
}
}
新建install_modules/Mymodule/manifest.xml
<?xml version='1.0'?>
<module>
<exporttime>2017-11-27 11:07:36</exporttime>
<name>Mymodule</name>
<label>Mymodule</label>
<parent>Support</parent>
<version>2.0</version>
<dependencies>
<vtiger_version>6.0.0rc</vtiger_version>
<vtiger_max_version>6.*</vtiger_max_version>
</dependencies>
<tables>
<table>
<name>vtiger_mymodule</name>
<sql><![CDATA[CREATE TABLE `vtiger_mymodule` (
`mymoduleid` int(11) NOT NULL,
`mymodule_no` varchar(30) NOT NULL,
`servicecontractsid` int(10) NOT NULL,
PRIMARY KEY (`mymoduleid`),
CONSTRAINT `fk_1_vtiger_mymodule` FOREIGN KEY (`mymoduleid`) REFERENCES `vtiger_crmentity` (`crmid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8]]>
</sql>
</table>
<table>
<name>vtiger_mymodulecf</name>
<sql><![CDATA[CREATE TABLE `vtiger_mymodulecf` (
`mymoduleid` int(19) NOT NULL,
PRIMARY KEY (`mymoduleid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8]]>
</sql>
</table>
</tables>
<blocks>
<block>
<label>LBL_PAYMENTS_INFORMATION</label>
<fields>
<field>
<fieldname>mymodule_no</fieldname>
<uitype>4</uitype>
<columnname>mymodule_no</columnname>
<tablename>vtiger_mymodule</tablename>
<generatedtype>1</generatedtype>
<fieldlabel>Payments No</fieldlabel>
<readonly>1</readonly>
<presence>0</presence>
<defaultvalue></defaultvalue>
<sequence>2</sequence>
<maximumlength>100</maximumlength>
<typeofdata>V~O</typeofdata>
<quickcreate>3</quickcreate>
<quickcreatesequence>0</quickcreatesequence>
<displaytype>1</displaytype>
<info_type>BAS</info_type>
<helpinfo><![CDATA[]]>
</helpinfo>
<masseditable>0</masseditable>
</field>
<field>
<fieldname>servicecontractsid</fieldname>
<uitype>51</uitype>
<columnname>servicecontractsid</columnname>
<tablename>vtiger_mymodule</tablename>
<generatedtype>1</generatedtype>
<fieldlabel>ServiceContract Name</fieldlabel>
<readonly>1</readonly>
<presence>2</presence>
<defaultvalue></defaultvalue>
<sequence>9</sequence>
<maximumlength>100</maximumlength>
<typeofdata>V~O</typeofdata>
<quickcreate>1</quickcreate>
<quickcreatesequence></quickcreatesequence>
<displaytype>1</displaytype>
<info_type>BAS</info_type>
<helpinfo><![CDATA[]]>
</helpinfo>
<masseditable>1</masseditable>
</field>
<field>
<fieldname>assigned_user_id</fieldname>
<uitype>53</uitype>
<columnname>smownerid</columnname>
<tablename>vtiger_crmentity</tablename>
<generatedtype>1</generatedtype>
<fieldlabel>Assigned To</fieldlabel>
<readonly>1</readonly>
<presence>2</presence>
<defaultvalue></defaultvalue>
<sequence>4</sequence>
<maximumlength>100</maximumlength>
<typeofdata>V~M</typeofdata>
<quickcreate>0</quickcreate>
<quickcreatesequence>2</quickcreatesequence>
<displaytype>1</displaytype>
<info_type>BAS</info_type>
<helpinfo><![CDATA[]]>
</helpinfo>
<masseditable>1</masseditable>
</field>
<field>
<fieldname>createdtime</fieldname>
<uitype>70</uitype>
<columnname>createdtime</columnname>
<tablename>vtiger_crmentity</tablename>
<generatedtype>1</generatedtype>
<fieldlabel>Created Time</fieldlabel>
<readonly>1</readonly>
<presence>0</presence>
<defaultvalue></defaultvalue>
<sequence>14</sequence>
<maximumlength>100</maximumlength>
<typeofdata>DT~O</typeofdata>
<quickcreate>3</quickcreate>
<quickcreatesequence></quickcreatesequence>
<displaytype>2</displaytype>
<info_type>BAS</info_type>
<helpinfo><![CDATA[]]>
</helpinfo>
<masseditable>0</masseditable>
</field>
<field>
<fieldname>modifiedtime</fieldname>
<uitype>70</uitype>
<columnname>modifiedtime</columnname>
<tablename>vtiger_crmentity</tablename>
<generatedtype>1</generatedtype>
<fieldlabel>Modified Time</fieldlabel>
<readonly>1</readonly>
<presence>0</presence>
<defaultvalue></defaultvalue>
<sequence>15</sequence>
<maximumlength>100</maximumlength>
<typeofdata>DT~O</typeofdata>
<quickcreate>3</quickcreate>
<quickcreatesequence></quickcreatesequence>
<displaytype>2</displaytype>
<info_type>BAS</info_type>
<helpinfo><![CDATA[]]>
</helpinfo>
<masseditable>0</masseditable>
</field>
<field>
<fieldname>modifiedby</fieldname>
<uitype>52</uitype>
<columnname>modifiedby</columnname>
<tablename>vtiger_crmentity</tablename>
<generatedtype>1</generatedtype>
<fieldlabel>Last Modified By</fieldlabel>
<readonly>1</readonly>
<presence>0</presence>
<defaultvalue></defaultvalue>
<sequence>16</sequence>
<maximumlength>100</maximumlength>
<typeofdata>V~O</typeofdata>
<quickcreate>3</quickcreate>
<quickcreatesequence></quickcreatesequence>
<displaytype>3</displaytype>
<info_type>BAS</info_type>
<helpinfo><![CDATA[]]>
</helpinfo>
<masseditable>0</masseditable>
</field>
</fields>
</block>
<block>
<label>LBL_CUSTOM_INFORMATION</label>
</block>
<block>
<label>LBL_DESCRIPTION_INFORMATION</label>
<fields>
<field>
<fieldname>description</fieldname>
<uitype>19</uitype>
<columnname>description</columnname>
<tablename>vtiger_crmentity</tablename>
<generatedtype>1</generatedtype>
<fieldlabel>Notes</fieldlabel>
<readonly>1</readonly>
<presence>2</presence>
<defaultvalue></defaultvalue>
<sequence>1</sequence>
<maximumlength>100</maximumlength>
<typeofdata>V~O</typeofdata>
<quickcreate>1</quickcreate>
<quickcreatesequence></quickcreatesequence>
<displaytype>1</displaytype>
<info_type>BAS</info_type>
<helpinfo><![CDATA[]]>
</helpinfo>
<masseditable>1</masseditable>
</field>
</fields>
</block>
</blocks>
<customviews>
<customview>
<viewname>All</viewname>
<setdefault>true</setdefault>
<setmetrics>false</setmetrics>
<fields>
<field>
<fieldname>mymoduleid</fieldname>
<columnindex>1</columnindex>
</field>
<field>
<fieldname>mymodule_no</fieldname>
<columnindex>0</columnindex>
</field>
</fields>
</customview>
</customviews>
<sharingaccess>
<default>public_readwritedelete</default>
</sharingaccess>
<actions>
<action>
<name><![CDATA[Export]]>
</name>
<status>enabled</status>
</action>
</actions>
<relatedlists>
<relatedlist>
<function>get_related_list</function>
<label>Account</label>
<sequence>1</sequence>
<presence>0</presence>
<actions>
<action>ADD</action>
<action>SELECT</action>
</actions>
<relatedmodule>Account</relatedmodule>
</relatedlist>
</relatedlists>
</module>
将install_modules/Mymodule/打包为zip文件。
cd install_modules/Mymodule
zip -q -r mymodule.zip ./
2、安装
访问
http://你的项目域名/index.php?module=ModuleManager&parent=Settings&view=List&block=2&fieldid=8
按步骤进行安装
3、如有报错,则追踪代码。
比如常见的vtiger_ws_entity表中没有插入刚才安装的模块的数据。
vtiger_entityname表中也需要新增一条刚才新加模块的记录
具体的报错要跟踪代码打断点。
vitger个大坑货。文档不全,代码冗杂,无力吐槽