php 为vtiger创建模块

x0fgdtte  于 12个月前  发布在  PHP
关注(0)|答案(1)|浏览(196)

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

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

$Vtiger_Utils_Log = true;

$MODULENAME = 'namava';

$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 = 'film';
    $field2->label = 'film On';
    $field2->uitype = 5;
    $field2->column = $field2->name;
    $field2->columntype = 'Date';
    $field2->typeofdata = 'D~O';
    $block->addField($field2);

    $field3 = new Vtiger_Field();
    $field3->name = 'actor';
    $field3->label = 'actor on';
    $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();
}

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

waxmsbnn

waxmsbnn1#

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

// Add a New module, and remove these 4 lines once the script is executed and the module exists in the vtiger_tab table.

$moduleInstance = new Vtiger_Module();
$moduleInstance->name = $MODULENAME;
$moduleInstance->parent = 'Tools';
$moduleInstance->save();

// This line creates new tables for your module
// 1. vtiger_modulename
// 2. vtiger_modulenamecf

$moduleInstance->initTables();

// 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.

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

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

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

相关问题