Subpanels
Subpanels are used to display relationships with other modules. They reside in the DetailView of a page, and are defined within a few places in the code. Click the subpanels link above to see the details.
The references below are the places in the code where subpanels are generated from. Running rebuild relationships in the repair section in the admin panel is necessary after making changes to or creating subpanels.
Contents
* 1 Vardefs
o 1.1 one-to-many example
o 1.2 many-to-many example
* 2 Relationship Metadata
* 3 Layout Defs
* 4 Language
Vardefs
The module that contains the subpanel is where the vardefs array index is defined. There is an index referring to the module that will appear as the subpanel of type 'link'.
one-to-many example
For Accounts, the reference necessary for the Cases subpanel is defined as follows in the ./modules/Accounts/vardefs.php
Code:
'cases' => array (
'name' => 'cases',
'type' => 'link',
'relationship' => 'account_cases', //relationship definition is below
'module'=>'Cases',
'bean_name'=>'aCase',
'source'=>'non-db',
'vname'=>'LBL_CASES',
),
For a one-to-many, the 'relationship' index defined above must also be in the vardefs.
Code:
'account_cases' => array(
'lhs_module'=> 'Accounts',
'lhs_table'=> 'accounts',
'lhs_key' => 'id',
'rhs_module'=> 'Cases',
'rhs_table'=> 'cases',
'rhs_key' => 'account_id',
'relationship_type'=>'one-to-many'
),
Since this is a one to many, there is no need for a relationship table (Relationship Metadata), which is only defined in the ./metadata directory.
many-to-many example
For Accounts, the reference necessary for the Bugs subpanel is defined as follows in the ./modules/Accounts/vardefs.php
Code:
'bugs' => array (
'name' => 'bugs',
'type' => 'link',
'relationship' => 'accounts_bugs', //relationship table
'module'=>'Bugs',
'bean_name'=>'Bug',
'source'=>'non-db',
'vname'=>'LBL_BUGS',
),
Since this is many to many and there already exists a relationship table, there is no need to define the relationship in the vardefs. However, the Relationship Metadata must be defined as shown below.
Relationship Metadata
If you have a many-to-many relationship, a table must exist for the relationship.
In the ./metadata directory, the relationship must exist and included in the $dictionary array. To keep consistent with the above accounts_bugs example, here is the content of the accounts_bugsMetaData.php
Code:
$dictionary['accounts_bugs'] = array(
'table' => 'accounts_bugs', //the table that is created in the database
'fields' => array (
array('name' =>'id', 'type' =>'varchar', 'len'=>'36',), // the unique id for the relationship
array('name' =>'account_id', 'type' =>'varchar', 'len'=>'36'), // the id for the account
array('name' =>'bug_id', 'type' =>'varchar', 'len'=>'36'), // the id for the bug
array('name' => 'date_modified','type' => 'datetime'), // necessary
array('name' =>'deleted', 'type' =>'bool', 'len'=>'1', 'required'=>true, 'default'=>'0') // necessary
),
// the indices are necessary for indexing and performance
'indices' => array (
array('name' =>'accounts_bugspk', 'type' =>'primary', 'fields'=>array('id')),
array('name' =>'idx_acc_bug_acc', 'type' =>'index', 'fields'=>array('account_id')),
array('name' =>'idx_acc_bug_bug', 'type' =>'index', 'fields'=>array('bug_id')),
array('name' => 'idx_account_bug', 'type'=>'alternate_key', 'fields'=>array('account_id','bug_id'))
),
'relationships' => array(
'accounts_bugs' => array(
'lhs_module'=> 'Accounts', // the left hand module - should match $beanList index
'lhs_table'=> 'accounts', // the left hand table name
'lhs_key' => 'id', // the key to use from the left table
'rhs_module'=> 'Bugs', // the right hand module - should match $beanList index
'rhs_table'=> 'bugs', // the right hand table name
'rhs_key' => 'id', // the key to use from the right table
'relationship_type'=>'many-to-many', // relationship type
'join_table'=> 'accounts_bugs', // join table - table used to join items
'join_key_lhs'=>'account_id', // left table key - should exist in table field definitions above
'join_key_rhs'=>'bug_id' // right table key - should exist in table field definitions above
)
)
) Layout Defs
This is the file that contains the related modules to create subpanels for. It is stored in the $layout_defs array $layout_defs[<module>]['subpanel_setup'][<related_module>].
This example is from the account layout_defs.php
Code:
'contacts' => array(
'order' => 30,
'module' => 'Contacts',
'subpanel_name' => 'default', // in this case, it will use ./modules/Contacts/subpanels/default.php
'get_subpanel_data' => 'contacts',
'add_subpanel_data' => 'contact_id',
'title_key' => 'LBL_CONTACTS_SUBPANEL_TITLE',
'top_buttons' => array( // this array defines the top buttons
array('widget_class' => 'SubPanelTopCreateAccountNameButton'),
array('widget_class' => 'SubPanelTopSelectButton', 'mode'=>'MultiSelect')
),
),
Language
In the language file for the module containing the subpanel, the following values need to be added.
* The reference used in 'title_key' as shown above
o In the example, it would be $mod_strings['LBL_CONTACTS_SUBPANEL_TITLE'] = 'Contacts';
* The reference used in 'vname' as shown in the vardefs section
o In the example, it would be $mod_strings['LBL_CASES'] = 'Cases';
Bookmarks