我有一个模块和一个子面板,另一个模块与此关联。 如下图所示-
在上图中,它是关系中模块的子面板, 我已经在数据库的关系表中添加了一列。
我的要求是在该子面板列表视图中添加该字段,如红色矩形中的图像所示,根据我的知识,理想情况下在工作室中是不可能的。 如果有人有想法做这样的事情,请分享。
答案 0 :(得分:1)
自定义SuiteCRM模块的开发可能需要一段时间,以便在两个模块之间的关系表中方便地存储其他数据。除非您对SuiteCRM底层架构有深入的了解,否则在工作室或模块制造商中这是不可能的,即使对于有经验的编码人员而言,也不是那么简单。
步骤1 ,您需要做的第一件事是在元数据中为关系定义新字段。我将在自定义模块FP_events
和Contacts
之间的关系中添加该字段。关系fp_events_contacts
是many to many
,子面板将在FP_events模块上的联系人子面板中显示该字段。
此文件位于custom/metadata/fp_events_contactsMetaData.php
在下面的代码中,我向字段数组添加了一个名为date_cancelled
的字段date
。
$dictionary["fp_events_contacts"] = array (
'true_relationship_type' => 'many-to-many',
'relationships' =>
array (
'fp_events_contacts' =>
array (
'lhs_module' => 'FP_events',
'lhs_table' => 'fp_events',
'lhs_key' => 'id',
'rhs_module' => 'Contacts',
'rhs_table' => 'contacts',
'rhs_key' => 'id',
'relationship_type' => 'many-to-many',
'join_table' => 'fp_events_contacts_c',
'join_key_lhs' => 'fp_events_contactsfp_events_ida',
'join_key_rhs' => 'fp_events_contactscontacts_idb',
),
),
'table' => 'fp_events_contacts_c',
'fields' =>
array (
0 =>
array (
'name' => 'id',
'type' => 'varchar',
'len' => 36,
),
1 =>
array (
'name' => 'date_modified',
'type' => 'datetime',
),
2 =>
array (
'name' => 'deleted',
'type' => 'bool',
'len' => '1',
'default' => '0',
'required' => true,
),
3 =>
array (
'name' => 'fp_events_contactsfp_events_ida',
'type' => 'varchar',
'len' => 36,
),
4 =>
array (
'name' => 'fp_events_contactscontacts_idb',
'type' => 'varchar',
'len' => 36,
),
5 =>
array (
'name' => 'invite_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'Not Invited',
),
6 =>
array (
'name' => 'accept_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'No Response',
),
7 =>
array (
'name' => 'email_responded',
'type' => 'int',
'len' => '2',
'default' => '0',
),
8 =>
array (
'name' => 'date_cancelled',
'type' => 'date',
),
),
'indices' =>
array (
0 =>
array (
'name' => 'fp_events_contactsspk',
'type' => 'primary',
'fields' =>
array (
0 => 'id',
),
),
1 =>
array (
'name' => 'fp_events_contacts_alt',
'type' => 'alternate_key',
'fields' =>
array (
0 => 'fp_events_contactsfp_events_ida',
1 => 'fp_events_contactscontacts_idb',
),
),
),
);
将所需的字段添加到字段数组后,请从SuiteCRM的管理面板中进行快速修复和重建,然后执行建议的SQL查询,这会将字段添加到关系的数据库表中。 (我通过进入phpmyadmin
并查看fp_events_contacts_c
表来仔细检查是否添加了字段。)
第2步现在,您的字段已经定义并且在实际的数据库表中,但是如果您希望将字段实际显示在子面板中,则仅在字段的一半位置。接下来要做的是在vardefs
中为关系定义新字段。这是通过在custom / Extensions文件夹中添加文件来完成的,例如:custom/Extension/modules/Contacts/Ext/Vardefs/CAN_BE_ANY_NAME.php
在此文件中,为您添加的每个字段添加以下三个定义。请注意所有定义之间的所有字段名称和ID都应匹配,因为此处的次要输入错误会阻止这些字段显示在子面板中,并且可能会很麻烦:
$dictionary['Contact']['fields']['e_date_cancelled'] =
array (
'name' => 'e_date_cancelled',
'rname' => 'id',
'relationship_fields'=>array('id' => 'cancelled_id', 'date_cancelled' => 'event_cancelled'),
'vname' => 'LBL_CONT_ACCEPT_CANCELLED',
'type' => 'relate',
'link' => 'fp_events_contacts',
'link_type' => 'relationship_info',
'join_link_name' => 'fp_events_contacts',
'source' => 'non-db',
'importable' => 'false',
'duplicate_merge'=> 'disabled',
'studio' => false,
);
$dictionary['Contact']['fields']['event_cancelled'] =
array(
'massupdate' => false,
'name' => 'event_cancelled',
'type' => 'date',
'studio' => 'false',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'importable' => 'false',
);
$dictionary['Contact']['fields']['cancelled_id'] =
array(
'name' => 'cancelled_id',
'type' => 'varchar',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'studio' => array('listview' => false),
);
步骤3 ,最后要做的就是在子面板的实际布局定义中定义字段。在这种情况下,该文件位于:custom/modules/Contacts/metadata/subpanels/FP_events_subpanel_fp_events_contacts.php
在下面的代码中,请注意,我将字段event_cancelled
(在步骤2 vardefs中定义)添加到list_fields
数组中,并在数组的更下方添加了e_date_cancelled
和{ {1}},并将其用法标记为cancelled_id
。
query_only
此外,请记住在这种情况下将标签$subpanel_layout['list_fields'] = array (
'name' =>
array (
'name' => 'name',
'vname' => 'LBL_LIST_NAME',
'sort_by' => 'last_name',
'sort_order' => 'asc',
'widget_class' => 'SubPanelDetailViewLink',
'module' => 'Contacts',
'width' => '23%',
'default' => true,
),
'account_name' =>
array (
'name' => 'account_name',
'module' => 'Accounts',
'target_record_key' => 'account_id',
'target_module' => 'Accounts',
'widget_class' => 'SubPanelDetailViewLink',
'vname' => 'LBL_LIST_ACCOUNT_NAME',
'width' => '22%',
'sortable' => false,
'default' => true,
),
'phone_work' =>
array (
'name' => 'phone_work',
'vname' => 'LBL_LIST_PHONE',
'width' => '15%',
'default' => true,
),
'email1' =>
array (
'name' => 'email1',
'vname' => 'LBL_LIST_EMAIL',
'widget_class' => 'SubPanelEmailLink',
'width' => '20%',
'sortable' => false,
'default' => true,
),
'event_status_name' =>
array (
'vname' => 'LBL_STATUS',
'width' => '10%',
'sortable' => false,
'default' => true,
),
'event_accept_status' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_STATUS',
),
'event_cancelled' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_CANCELLED',
),
'edit_button' =>
array (
'vname' => 'LBL_EDIT_BUTTON',
'widget_class' => 'SubPanelEditButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'remove_button' =>
array (
'vname' => 'LBL_REMOVE',
'widget_class' => 'SubPanelRemoveButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'e_accept_status_fields' =>
array (
'usage' => 'query_only',
),
'event_status_id' =>
array (
'usage' => 'query_only',
),
'e_invite_status_fields' =>
array (
'usage' => 'query_only',
),
'event_invite_id' =>
array (
'usage' => 'query_only',
),
'e_date_cancelled' =>
array (
'usage' => 'query_only',
),
'cancelled_id' =>
array (
'usage' => 'query_only',
),
'first_name' =>
array (
'name' => 'first_name',
'usage' => 'query_only',
),
'last_name' =>
array (
'name' => 'last_name',
'usage' => 'query_only',
),
'salutation' =>
array (
'name' => 'salutation',
'usage' => 'query_only',
),
'account_id' =>
array (
'usage' => 'query_only',
),
);
添加到自定义语言字符串中。
我将其添加到:LBL_ACCEPT_CANCELLED
custom/Extension/application/Ext/Language/en_us.Advanced OpenEvents.php
但是如果添加到mod字符串中,它可能会起作用。
现在,从管理面板进行另一快速修复和重建,您的自定义关系字段现在应该显示在子面板上。现在,您可以通过查询或SuiteCRM bean框架将数据添加到模块控制器的这些字段中。
请注意,您可能必须手动进入数据库,并在这些字段中添加一些虚拟数据以确认它们正在显示(假设您尚未将任何数据添加到新字段中)。
干杯!