在vtiger 6中创建自定义模块

时间:2014-06-19 08:04:16

标签: module vtiger

你好,我是vtiger的新手。现在我想知道的是如何在不使用现有模块设计器或其他相同的东西的情况下创建costum模块。例如,我想创建一个自定义模块,用于保存某个人的姓名和姓氏。实际上我在互联网上研究,我没有找到关于如何在vtiger 6中专门创建costum模块的明确教程。你有关于如何在vtiger 6中创建costum模块的任何好的教程或链接。非常感谢您的帮助。

4 个答案:

答案 0 :(得分:8)

我在制作实体模块时发现了一些有趣的教程,这就是链接。 http://community.vtiger.com/help/vtigercrm/developers/extensions/examples/entity-module.html它正在发挥作用。

答案 1 :(得分:6)

首先在模块中创建一个新文件夹(module name without space)并将文件从vtlib/ModuleDir/6.0.0文件复制到modules / newmodule中创建的文件夹

使用您的模块名称(没有空格)更改ModuleName.php的名称,并在ModuleName.php中更改languages\en_us个文件。

打开modulename.php to change the class name, $table_name , $table_index&也可以在languages\en_us中使用您的模块名称。

在根目录下创建任何名称的新文件。插入以下代码以添加字段和模块。

<?php
include_once 'vtlib/Vtiger/Module.php';

$Vtiger_Utils_Log = true;

$MODULENAME = 'Persons';

$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
    echo "Module already present - choose a different name.";
} else {
    $moduleInstance = new Vtiger_Module();
    $moduleInstance->name = $MODULENAME;
    $moduleInstance->parent= 'Tools';
    $moduleInstance->save();

    // Schema Setup
    $moduleInstance->initTables();

    // Field Setup
    $block = new Vtiger_Block();
    $block->label = 'LBL_'. strtoupper($moduleInstance->name) . '_INFORMATION';
    $moduleInstance->addBlock($block);

    $blockcf = new Vtiger_Block();
    $blockcf->label = 'LBL_CUSTOM_INFORMATION';
    $moduleInstance->addBlock($blockcf);

    $field1  = new Vtiger_Field();
    $field1->name = 'lastname';
    $field1->label= 'Last Name';
    $field1->uitype= 2;
    $field1->column = $field1->name;
    $field1->columntype = 'VARCHAR(255)';
    $field1->typeofdata = 'V~M';
    $block->addField($field1);

    $moduleInstance->setEntityIdentifier($field1);

    $field2  = new Vtiger_Field();
    $field2->name = 'firstname';
    $field2->label= 'First Name';
    $field2->uitype= 1;
    $field2->column = $field2->name;
    $field2->columntype = 'VARCHAR(255)';
    $field2->typeofdata = 'V~M';
    $block->addField($field2);

    // Recommended common fields every Entity module should have (linked to core table) 
    $mfield1 = new Vtiger_Field();
    $mfield1->name = 'assigned_user_id';
    $mfield1->label = 'Assigned To';
    $mfield1->table = 'vtiger_crmentity';
    $mfield1->column = 'smownerid';
    $mfield1->uitype = 53;
    $mfield1->typeofdata = 'V~M';
    $block->addField($mfield1);

    $mfield2 = new Vtiger_Field();
    $mfield2->name = 'CreatedTime';
    $mfield2->label= 'Created Time';
    $mfield2->table = 'vtiger_crmentity';
    $mfield2->column = 'createdtime';
    $mfield2->uitype = 70;
    $mfield2->typeofdata = 'T~O';
    $mfield2->displaytype= 2;
    $block->addField($mfield2);

    $mfield3 = new Vtiger_Field();
    $mfield3->name = 'ModifiedTime';
    $mfield3->label= 'Modified Time';
    $mfield3->table = 'vtiger_crmentity';
    $mfield3->column = 'modifiedtime';
    $mfield3->uitype = 70;
    $mfield3->typeofdata = 'T~O';
    $mfield3->displaytype= 2;
    $block->addField($mfield3);

    // Filter Setup
    $filter1 = new Vtiger_Filter();
    $filter1->name = 'All';
    $filter1->isdefault = true;
    $moduleInstance->addFilter($filter1);
    $filter1->addField($field1)->addField($field2, 1)->addField($field3, 2)->addField($mfield1, 3);

    // Sharing Access Setup
    $moduleInstance->setDefaultSharing();

    // Webservice Setup
    $moduleInstance->initWebservice();

    mkdir('modules/'.$MODULENAME);
    echo "OK\n";
}
?>

答案 2 :(得分:5)

创建新的自定义模块有一个简单的Console tool

打开cmd提示符,转到vtlib / tools文件夹并执行Console.php文件:

>cd C:\{$YourPathToVtiger}\apache\htdocs\vtigerCRM\vtlib\tools
>php -f Console.php

键入&#39; 1&#39;用于创建新模块并设置&#34;模块名称&#34;和&#34;实体字段&#34; (实体字段是当您打开该模块的实例时,将在窗口顶部以粗体显示的字段)。

现在创建并安装了新模块,您可以从vTiger GUI轻松自定义它(添加新字段,工作流等)。

答案 3 :(得分:4)

在Vtiger的根文件夹中创建bootstrap vtlib脚本,以激活具有特定文件名的模块条目。

<强> create_expense.php

<?php
include_once 'vtlib/Vtiger/Module.php';

$Vtiger_Utils_Log = true;

$MODULENAME = 'Expenses';

$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
    echo "Module already present - choose a different name.";
} else {
    $moduleInstance = new Vtiger_Module();
    $moduleInstance->name = $MODULENAME;
    $moduleInstance->parent= 'Tools';
    $moduleInstance->save();

    // Schema Setup
    $moduleInstance->initTables();

    // Field Setup
    $block = new Vtiger_Block();
    $block->label = 'LBL_'. strtoupper($moduleInstance->name) . '_INFORMATION';
    $moduleInstance->addBlock($block);

    $blockcf = new Vtiger_Block();
    $blockcf->label = 'LBL_CUSTOM_INFORMATION';
    $moduleInstance->addBlock($blockcf);

    $field1  = new Vtiger_Field();
    $field1->name = 'summary';
    $field1->label= 'Summary';
    $field1->uitype= 2;
    $field1->column = $field1->name;
    $field1->columntype = 'VARCHAR(255)';
    $field1->typeofdata = 'V~M';
    $block->addField($field1);

    $moduleInstance->setEntityIdentifier($field1);

    $field2  = new Vtiger_Field();
    $field2->name = 'expenseon';
    $field2->label= 'Expense On';
    $field2->uitype= 5;
    $field2->column = $field2->name;
    $field2->columntype = 'Date';
    $field2->typeofdata = 'D~O';
    $block->addField($field2);

    $field3  = new Vtiger_Field();
    $field3->name = 'expenseamount';
    $field3->label= 'Amount';
    $field3->uitype= 71;
    $field3->column = $field3->name;
    $field3->columntype = 'VARCHAR(255)';
    $field3->typeofdata = 'V~M';
    $block->addField($field3);

    $field3  = new Vtiger_Field();
    $field3->name = 'description';
    $field3->label= 'Description';
    $field3->uitype= 19;
    $field3->column = 'description';
    $field3->table = 'vtiger_crmentity';
    $blockcf->addField($field3);

    // Recommended common fields every Entity module should have (linked to core table)
    $mfield1 = new Vtiger_Field();
    $mfield1->name = 'assigned_user_id';
    $mfield1->label = 'Assigned To';
    $mfield1->table = 'vtiger_crmentity';
    $mfield1->column = 'smownerid';
    $mfield1->uitype = 53;
    $mfield1->typeofdata = 'V~M';
    $block->addField($mfield1);

    $mfield2 = new Vtiger_Field();
    $mfield2->name = 'CreatedTime';
    $mfield2->label= 'Created Time';
    $mfield2->table = 'vtiger_crmentity';
    $mfield2->column = 'createdtime';
    $mfield2->uitype = 70;
    $mfield2->typeofdata = 'T~O';
    $mfield2->displaytype= 2;
    $block->addField($mfield2);

    $mfield3 = new Vtiger_Field();
    $mfield3->name = 'ModifiedTime';
    $mfield3->label= 'Modified Time';
    $mfield3->table = 'vtiger_crmentity';
    $mfield3->column = 'modifiedtime';
    $mfield3->uitype = 70;
    $mfield3->typeofdata = 'T~O';
    $mfield3->displaytype= 2;
    $block->addField($mfield3);

    // Filter Setup
    $filter1 = new Vtiger_Filter();
    $filter1->name = 'All';
    $filter1->isdefault = true;
    $moduleInstance->addFilter($filter1);
    $filter1->addField($field1)->addField($field2, 1)->addField($field3, 2)->addField($mfield1, 3);

    // Sharing Access Setup
    $moduleInstance->setDefaultSharing();

    // Webservice Setup
    $moduleInstance->initWebservice();

    mkdir('modules/'.$MODULENAME);
    echo "OK\n";
}

现在按照以下文件夹结构创建新文件夹。

目录结构

vtigercrm/
    modules/
        Expenses/
            Expenses.php - class Expenses
    languages/
        en_us/
            Expenses.php

接下来创建一个Expenses.php类文件

<?php

include_once 'modules/Vtiger/CRMEntity.php';

class Expenses extends Vtiger_CRMEntity {
    var $table_name = 'vtiger_expenses';
    var $table_index= 'expensesid';

    var $customFieldTable = Array('vtiger_expensescf', 'expensesid');

    var $tab_name = Array('vtiger_crmentity', 'vtiger_expenses', 'vtiger_expensescf');

    var $tab_name_index = Array(
            'vtiger_crmentity' => 'crmid',
            'vtiger_expenses' => 'expensesid',
            'vtiger_expensescf'=>'expensesid');

    var $list_fields = Array (
            /* Format: Field Label => Array(tablename, columnname) */
            // tablename should not have prefix 'vtiger_'
            'Summary' => Array('expenses', 'summary'),
            'Assigned To' => Array('crmentity','smownerid')
    );
    var $list_fields_name = Array (
            /* Format: Field Label => fieldname */
            'Summary' => 'summary',
            'Assigned To' => 'assigned_user_id',
    );

    // Make the field link to detail view
    var $list_link_field = 'summary';

    // For Popup listview and UI type support
    var $search_fields = Array(
            /* Format: Field Label => Array(tablename, columnname) */
            // tablename should not have prefix 'vtiger_'
            'Summary' => Array('expenses', 'summary'),
            'Assigned To' => Array('vtiger_crmentity','assigned_user_id'),
    );
    var $search_fields_name = Array (
            /* Format: Field Label => fieldname */
            'Summary' => 'summary',
            'Assigned To' => 'assigned_user_id',
    );

    // For Popup window record selection
    var $popup_fields = Array ('summary');

    // For Alphabetical search
    var $def_basicsearch_col = 'summary';

    // Column value to use on detail view record text display
    var $def_detailview_recname = 'summary';

    // Used when enabling/disabling the mandatory fields for the module.
    // Refers to vtiger_field.fieldname values.
    var $mandatory_fields = Array('summary','assigned_user_id');

    var $default_order_by = 'summary';
    var $default_sort_order='ASC';
}