php Vtiger 7.1.是否有任何方法可以使用VTlib修改Field或Block的位置?

8wtpewkr  于 11个月前  发布在  PHP
关注(0)|答案(1)|浏览(168)

在vtiger中,数据库中有一个名为vtiger_field的表,存储与字段相关的所有内容。该表有一个名为sequence的列,表示这些字段的位置。虽然可以使用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的建议,我将不知道如何使用这些函数来修改块

6l7fqoea

6l7fqoea1#

Vtiger vtlib不支持字段和块序列更新。您必须准备一个查询来更新所有受更改影响的块或字段。

  1. Vtiger布局编辑器
    在这个屏幕中,Vtiger使用jQuery库来获取块或字段的序列。因此,当您在布局编辑器页面上单击保存时,它会从UI发布序列。
  2. Vtiger更新序列
    当请求被发送到服务器时,它会转到“Settings_LayoutEditor_Block_Action”类的“updateSequenceNumber”函数,该函数最终调用“Vtiger_Block_Model”类的“updateSequenceNumber”函数,并准备一个带有when case单个更新查询并执行。

提及类的文件路径
*Settings_LayoutEditor_Block_Action-Vtiger/modules/Settings/LayoutEditor/actions/Blocks. php
*Vtiger_Block_Model-Vtiger/modules/Vtiger/models/Blocks. php

相关问题