在vtiger中,数据库中有一个名为vtiger_field的表,它存储与字段相关的所有内容。 该表有一列称为序列,它表示这些字段所处的位置。 虽然可以使用php代码来修改字段的位置,但我想知道是否有一种方法可以使用Vtlib来移动字段位置。
这个问题也适用于修改表 vtiger_blocks 中的块的位置
$blockData = array();
// Get tabid
$sql = mysql_query("SELECT tabid FROM vtigercrm71.vtiger_tab where name = 'ServiceContracts';",$DBconn);
$row = mysql_fetch_assoc($sql);
$moduleId = $row['tabid'];
// get BlockId of the block intended to be moved
$sql = mysql_query("SELECT blockid FROM vtigercrm71.vtiger_blocks where blocklabel = 'Renewal Details';",$DBconn);
$row = mysql_fetch_assoc($sql);
$blockId = $row['blockid'];
// get sequence of the block to be moved under
$sql = mysql_query("SELECT sequence FROM vtigercrm71.vtiger_blocks where blocklabel = 'LBL_SERVICE_CONTRACT_INFORMATION';",$DBconn);
$row = mysql_fetch_assoc($sql);
$blockSequence = $row['sequence'];
// Get blocks in that module
$sql = mysql_query("SELECT blockid,sequence FROM vtigercrm71.vtiger_blocks where tabid = ".$moduleId.";",$DBconn);
while($row = mysql_fetch_assoc($sql))
{
$blockData[] = array(
'blockid' => $row['blockid'],
'sequence' => $row['sequence']
);
}
$moveToSequence = $blockSequence + 1; //No of sequence need to be moved to
$targetSequence = null;
// set the sequence of the block needed to be moved
foreach($blockData as $block)
{
if ($blockId == $block['blockid'])
{
$targetSequence = $block['sequence'];
break;
}
}
// Update the block sequences from a lower sequence to a higher sequence
foreach($blockData as $block)
{
$sequence = $block['sequence'];
$blockId = $block['blockid'];
if($block['sequence'] == $targetSequence)
{
$sequence = $moveToSequence;
}
elseif ($block['sequence'] >= $moveToSequence && $block['sequence'] < $targetSequence)
{
$sequence = $block['sequence'];
$sequence + 1;
}
mysql_query("UPDATE vtigercrm71.vtiger_blocks SET sequence = '".$sequence."' WHERE (blockid = '".$blockId."');",$DBconn);
}
echo'<br>Block Sequence Changed<br>';
上面是我自己编写的用于更改块的顺序/位置的代码。 所有这些都太长和混乱,只是移动单个块序列,这就是为什么我试图找到是否有一种方法可以使用 vtlib 来更改序列
2023 年 4 月 12 日编辑: 在尝试找到使用 CRM 编辑块位置时出现的弹出窗口后,我想我设法找到了用于修改块的代码。但是,我不太明白它是如何工作的,而且有 2 个具有相同功能但存储库不同的文件。
“VtigerCRM/layouts/vlayout/modules/Settings/LayoutEditor/resources/LayoutEditor.js”中的那个:
/**
* Function to regiser the event to make the blocks sortable
*/
makeBlocksListSortable : function() {
var thisInstance = this;
var contents = jQuery('#layoutEditorContainer').find('.contents');
var table = contents.find('.blockSortable');
contents.sortable({
'containment' : contents,
'items' : table,
'revert' : true,
'tolerance':'pointer',
'cursor' : 'move',
'update' : function(e, ui) {
thisInstance.updateBlockSequence();
}
});
},
/**
* Function which will update block sequence
*/
updateBlockSequence : function() {
var thisInstance = this;
var progressIndicatorElement = jQuery.progressIndicator({
'position' : 'html',
'blockInfo' : {
'enabled' : true
}
});
var sequence = JSON.stringify(thisInstance.updateBlocksListByOrder());
var params = {};
params['module'] = app.getModuleName();
params['parent'] = app.getParentModuleName();
params['action'] = 'Block';
params['mode'] = 'updateSequenceNumber';
params['sequence'] = sequence;
AppConnector.request(params).then(
function(data) {
progressIndicatorElement.progressIndicator({'mode' : 'hide'});
var params = {};
params['text'] = app.vtranslate('JS_BLOCK_SEQUENCE_UPDATED');
Settings_Vtiger_Index_Js.showMessage(params);
},
function(error) {
progressIndicatorElement.progressIndicator({'mode' : 'hide'});
}
);
},
/**
* Function which will arrange the sequence number of blocks
*/
updateBlocksListByOrder : function() {
var thisInstance = this;
var contents = jQuery('#layoutEditorContainer').find('.contents');
contents.find('.editFieldsTable').each(function(index,domElement){
var blockTable = jQuery(domElement);
var blockId = blockTable.data('blockId');
var actualBlockSequence = blockTable.data('sequence');
var expectedBlockSequence = (index+1);
if(expectedBlockSequence != actualBlockSequence) {
blockTable.data('sequence', expectedBlockSequence);
}
thisInstance.updatedBlockSequence[blockId] = expectedBlockSequence;
});
return thisInstance.updatedBlockSequence;
},
另一个位于“VtigerCRM/layouts/v7/modules/Settings/LayoutEditor/resources/LayoutEditor.js”中:
/**
* Function to regiser the event to make the blocks sortable
*/
makeBlocksListSortable: function () {
var thisInstance = this;
var contents = jQuery('#layoutEditorContainer').find('.contents');
var table = contents.find('.blockSortable');
contents.sortable({
'containment': contents,
'items': table,
'revert': true,
'tolerance': 'pointer',
'cursor': 'move',
'update': function (e, ui) {
thisInstance.updateBlockSequence();
}
});
},
/**
* Function which will update block sequence
*/
updateBlockSequence: function () {
var thisInstance = this;
app.helper.showProgress();
var sequence = JSON.stringify(thisInstance.updateBlocksListByOrder());
var params = {};
params['module'] = thisInstance.getModuleName();
params['parent'] = app.getParentModuleName();
params['action'] = 'Block';
params['mode'] = 'updateSequenceNumber';
params['sequence'] = sequence;
params['selectedModule'] = jQuery('#selectedModuleName').attr('value');
app.request.post({'data': params}).then(
function (err, data) {
app.helper.hideProgress();
if (err === null) {
app.helper.showSuccessNotification({'message': app.vtranslate('JS_BLOCK_SEQUENCE_UPDATED')});
} else {
app.helper.showErrorNotification({'message': err.message});
}
});
},
/**
* Function which will arrange the sequence number of blocks
*/
updateBlocksListByOrder: function () {
var thisInstance = this;
var contents = jQuery('#layoutEditorContainer').find('.contents');
contents.find('.blockSortable:visible').each(function (index, domElement) {
var blockTable = jQuery(domElement);
var blockId = blockTable.data('blockId');
var actualBlockSequence = blockTable.data('sequence');
var expectedBlockSequence = (index+1);
if (expectedBlockSequence != actualBlockSequence) {
blockTable.data('sequence', expectedBlockSequence);
}
thisInstance.updatedBlockSequence[blockId] = expectedBlockSequence;
});
return thisInstance.updatedBlockSequence;
},
现在如果我遵循 Ruben 的建议,我将不知道如何使用这些函数来修改块
Vtiger vtlib 不支持字段和块序列更新。您必须准备一个查询来更新受更改影响的所有块或字段。
在此屏幕中,Vtiger 使用 jQuery 库来获取块或字段的序列。因此,当您在“布局编辑器”页面上单击“保存”时,它会从 UI 发布序列。
当请求发送到服务器时,它会转到“Settings_LayoutEditor_Block_Action”类、“updateSequenceNumber”函数,最终调用“Vtiger_Block_Model”类、“updateSequenceNumber”函数,并准备一个使用 when case 进行单个更新查询并执行。
提到的类的文件路径