SugarCRM 一对多 DetailView页面显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
需求:DetailView页面中显示与父表相关的子表ListView并可增加子表内容
    解决方案:
        1.两个模块
            bw_Consignments  提运单信息     父表
            bw_ConsignItems  提运单明细     子表    关系: 子表中ConsignmentID字段为父表中的id
        2.关系字段
            ConsignmentID 必须为主表字段
            如何创建主表字段 详见 主表-自定义字段
        3.增加关系
            \modules\bw_Consignments\vardefs.php    父表模块下 添加如下
 
             //BUILDER: included fields
                'bw_ConsignItems' =>          //子表模块名
                array (
                    'name' => 'bw_ConsignItems',    //子表模块名
                    'type' => 'link',
                    'relationship' => 'MR_bw_ConsignItems',   //关系名
                    'source'=>'non-db',
                    'vname'=>'LBL_REVMSGS',
                    ),
            //BUILDER:END of fields   
         
            //Relationships one-to-many               //注意位置不能错,否则生成的sql语句有问
            'relationships' => array(
                'MR_bw_ConsignItems' => array(
                    'lhs_module'=> 'bw_ConsignItems', 'lhs_table'=> 'bw_ConsignItems', 'lhs_key' => 'ConsignmentID', //子表模块
                    'rhs_module'=> 'bw_Consignments', 'rhs_table'=> 'bw_Consignments', 'rhs_key' => 'id',            //父表模块
                    'relationship_type'=>'one-to-many'),//关系
        4.设置subpanel的显示    
            \modules\bw_Consignments\layout_defs.php   父表模块下 添加如下
 
            $layout_defs['bw_Consignments'] = array(
                 'subpanel_setup'   => array(
                    //BUILDER:END of subpanels
 
                    'bw_consignitems' => array(                     //必须小写
                        'order' => 25,   
                        'module' => 'bw_ConsignItems',              //子表模块名
                        'subpanel_name' => 'default',  
                        'get_subpanel_data' => 'bw_ConsignItems',   //子表模块名
                        'add_subpanel_data' => 'bw_Consignments',   //父表模块名
                        'title_key' => 'LBL_MODULE_NAME',           //subpanel的标题
                        'top_buttons' => arrayarray('widget_class' => 'SubPanelTopCreateButton')          
                        ),
                     ),
                     
                    'ser_rights' => array(
                        'order' => 26,                                  //布局  多个SubPanel时显示的顺序
                        'module' => 'ser_Rights',
                        'subpanel_name' => 'default',
                        'get_subpanel_data' => 'ser_Rights',
                        'add_subpanel_data' => 'ser_right_id',
                        'title_key' => 'LBL_SER_RIGHTS_SUBPANEL_TITLE',//subpanel的标题 在父模块的 \language\zh_cn.lang.php 增加 'LBL_SER_RIGHTS_SUBPANEL_TITLE'=> '维权服务',
                        'top_buttons' => array(   //array('widget_class' => 'SubPanelTopCreateButton')        //新增 按钮 注掉则不显示按钮
                       ),
                     ),
  
                 ),
              );
        5.DetailView中显示
            \modules\bw_Consignments\DetailView.php
            ///////////////////////////////////////////////////////////////////////////////
            ////    SUBPANELS
            ///////////////////////////////////////////////////////////////////////////////
             
              require_once('include/SubPanel/SubPanelTiles.php');
              $subpanel = new SubPanelTiles($focus, 'MRConsignments');
              echo $subpanel->display();
             
            去掉上面注释的代码,即可在DetailView视图中显示subpanel
        6.子表保存时,将赋父表的id
             \modules\bw_ConsignItems\Save.php    //在子表模块中
             在下面代码后
             $sugarbean = new bw_ConsignItems();
             $sugarbean = populateFromPost('', $sugarbean);
             $sugarbean->bw_Consignment_id = $_POST['return_id'];
             添写
             if ($_REQUEST['return_module']=='bw_Consignment'){
                $sugarbean->ConsignmentID = $_REQUEST['return_id'];  //将父表id 赋给子表的关系字段 ConsignmentID
             }
        7.刷新关系(非常重要,不刷新则子表全部显示)
            系统管理 -> 升级 -> 重建关系(重建meta数据关系,删除cache文件)
  
        8.此步骤不写好像也行
            \modules\bw_ConsignItems\field_arrays.php
            $fields_array['bw_ConsignItem'] = array (
            'column_fields' => array(
              'id',
              'date_entered',
              'date_modified',
              'assigned_user_id',
              'modified_user_id',
              'created_by',
              'name',
              'description',
              'deleted',
            //BUILDER: included fields
              'ConsignmentID',              //关系字段  不写好像也行
            //BUILDER:END of column fields
  
        9.subpanel显示列
            在子表模块的subpanel文件夹下的 Default.php文件中
            \modules\bw_ConsignItems\default.php
                'list_fields' => array(
                    'name'         =>array(
                    'vname'         => 'LBL_LIST_NAME',
                        'widget_class'  => 'SubPanelDetailViewLink',
                    'width'         => '20%',
                    ),
                    //自定义列
                    'SequenceNumeric'         =>array(
                    'vname'         => 'LBL_SequenceNumeric',
                        'widget_class'  => 'SubPanelDetailViewLink',
                    'width'         => '20%',
                    ),
                    'MarksNumbers'         =>array(
                    'vname'         => 'LBL_MarksNumbers',
                        'widget_class'  => 'SubPanelDetailViewLink',
                    'width'         => '20%',
                    ),
                    //下面是修改,删除 按钮可删除则不显示(不删除,按钮也不好用) 
                    'edit_button'  =>array(
                        'widget_class'  => 'SubPanelEditButton',
                        'module'        => 'bw_ConsignItems',
                    'width'         => '4%',
                    ),
                    'remove_button'=>array(
                        'widget_class'  => 'SubPanelRemoveButton',
                        'module'        => 'bw_ConsignItems',
                        'width'         => '5%',
                    ),
                ),
            );
posted @   海乐学习  阅读(1079)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示