How to Create a sub-panel and build relationships

How to Create a sub-panel and build relationships on the
modules Oqc-Contract, oqc-Offering, oqc_products.

Attention: Every time you need to make a change like this it’s smart to backup the files to be
modified and a backup the database. It must not be done when there are users on-line on the
system.
The module of OpenQuotesandContracts, can be downloaded at the site of sugarforge
in projects, the modules were developed to work with mozzila. This manual will explainain
how to create relationship with other modules, also create the sub-panels of these
relationships. All customizations are not Upgrade-SAFE, or if made some customization the
set up files, should be kept to verify the possibility of having integration with other future
versions of sugarCRM.
Many to many relationships on sugar CRM are made with some steps.
– Define the link of relationship on the vardefs of both modules on the relationship
– Create a metadata file with the fields of DB and definition of the relationship
– Set up the database table
– Create Subpanels
VARDEFS
On vardefs file of the modules is necessary to create some lines to define the link field of
the relationship many-to-many. In oqc_X modules is used in the file
OpenQuotesandContracts.php on the path:
/sugarcrm/custom/Extension/modules/oqc_Contract/Ext/Vardefs/
On this file is necessary to specify the field of their relationship, by adding the following
lines. For example with the Project s module:
//Contracts and Project’s relationship test
‘project’,
‘type’ => ‘link’,
‘relationship’ => ‘oqc_Contract_project’,
‘source’ => ‘non-db’,
);
?>
//Contracts and Project’s relationship test
In the original modules of sugarCRM this file doesn’t exists, so it is necessary to create a
file with same name: OpenQuotesandContracts.php on the path:
/sugarcrm/custom/Extension/modules/Project/Ext/Vardefs/ (if doesn’t exist this path you
need to create it)
In the file it must be specified the link field of the relationship with the contracts. Example
With module projects:
//Relationship test
‘oqc_contract’,
‘type’ => ‘link’,
‘relationship’ => ‘oqc_Contract_project’,
‘source’ => ‘non-db’,
);
?>
//Relationship test
METADATA
In the metadata file must be defined the relationship between the modules, Fields of the
database are also defined in this file. There is a file for each relationship, since it is a Manyto-
Many relationship. You must creathe the file oqc_ _
MetaData.php on the path:
/sugarcrm/metadata/
It is recommended to copy a file that already exists in that model with similar relationship.
Example with Project’s module:
file: /sugarcrm/metadata/oqc_Contract_projectMetaData.php:
( note that the project module is in lower case)
$dictionary[“oqc_Contract_project”] = array (
‘table’ => ‘oqc_contract_project’,
‘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’ => ‘oqc_contract_ida’,
‘type’ => ‘varchar’,
‘len’ => 36,
),
4 =>
array (
‘name’ => ‘project_idb’,
‘type’ => ‘varchar’,
‘len’ => 36,
),
),
‘indices’ =>
array (
0 =>
array (
‘name’ => ‘oqc_contract_projectpk’,
‘type’ => ‘primary’,
‘fields’ =>
array (
0 => ‘id’,
),
),
1 =>
array (
‘name’ => ‘oqc_contract_project_ida1’,
‘type’ => ‘index’,
‘fields’ =>
array (
0 => ‘oqc_contract_ida’,
),
),
2 =>
array (
‘name’ => ‘oqc_contract_project_idb2’,
‘type’ => ‘index’,
‘fields’ =>
array (
0 => ‘project_idb’,
),
),
3 =>
array (
‘name’ => ‘oqc_contract_project_idc3’,
‘type’ => ‘index’,
‘fields’ =>
array (
0 => ‘oqc_contract_ida’,
1 => ‘project_idb’,
),
),
),
‘relationships’ =>
array (
‘oqc_Contract_project’ =>
array (
‘lhs_module’ => ‘oqc_Contract’,
‘lhs_table’ => ‘oqc_contract’,
‘lhs_key’ => ‘id’,
‘rhs_module’ => ‘Project’,
‘rhs_table’ => ‘project’,
‘rhs_key’ => ‘id’,
‘relationship_type’ => ‘many-to-many’,
‘join_table’ => ‘oqc_contract_project’,
‘join_key_lhs’ => ‘oqc_contract_ida’,
‘join_key_rhs’ => ‘project_idb’,
),
),
);
?>
Table files
So that sugar can repair and build the table you must create a line to refer the metadata file.
On the files: OpenQuotesandContracts.php and tabledictionary.ext.php, respectively, on the
paths:
/sugarcrm/custom/Extension/application/Ext/TableDictionary/
/sugarcrm/custom/application/Ext/TableDictionary/
you must insert a line before ?>. Example with Project’s module:
include(‘metadata/oqc_Contract_projectMetaData.php’);
REBUILDING TABLES AND RELATIONSHIPS
After modifing and creating all these files is necessary to enter in sugarcrm on the browser,
go into admin> repair and repair relationships,quick repair and repair DB (database). When
repaired the database is repared sugar will create the table with the fields defined in your
metadata file.
Creating a Sub-panel
In order to create a subpanel on the oqc_something modules it must be created some
definitions on the file: OpenQuotesandContracts.php on the path:
/sugarcrm/custom/Extension/modules/oqc_Contract/Ext/Layoutdefs/
On this file must be created lines to define the sub-panel of the original sugarCRM module,
in my case, project. Example with Project’s module.
//Teste subpainel de projetos em contratos
100,
‘module’ => ‘Project’,
‘subpanel_name’ => ‘default’,
‘get_subpanel_data’ => ‘project’,
‘add_subpanel_data’ => ‘project_idb’,
‘title_key’ => ‘lbl_project’, //this key must be translated on the en_us.lang file
);
?>
//teste subpainel de projetos em contratos
To set up the title of the sub-panel is necessary to put a line on the language file, in my case
was made with Portuguese pt_br.lang.php for English must be done to file en_us.lang.php
on the path:
/sugarcrm/modules/oqc_Contract/language/
This must be done on the language cache file( pt_br.lang.php) as well, on the path:
sugarcrm/cache/modules/oqc_Contract/language/pt_br.lang.php
The key on the previous step must be used: Example with lbl_project:
$mod_strings = array (
‘lbl_project’=> ‘Projetos’,
than Repair extensions and Quick repair.
To set up a oqc Sub-panel on the Original Module (in my case Project), since the
relationship and table are already defined, you just need to define the sub-panel on the
original module on the path: (is it doesn’t exists than create it, create the file as well)
sugarcrm/custom/Extension/modules/Project/Ext/Layoutdefs/OpenQuotesAndContracts.php
Example with projectsXoqc_contract:
note oqc_contract
in lower case
‘order’ => 100,
‘module’ => ‘oqc_Contract’,
‘subpanel_name’ => ‘default’,
‘get_subpanel_data’ => ‘oqc_contract’,
‘add_subpanel_data’ => ‘oqc_Contract_ida’,
‘title_key’ => ‘LBL_OQC_CONTRACT_SUBPANEL_TITLE’,
);
?>
Quick repair it, and it should be ready to use!

Advertisements

One thought on “How to Create a sub-panel and build relationships

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s