Results 1 to 4 of 4

Thread: Replicating the Task module

  1. #1
    nikemir is offline Member
    Join Date
    Jun 2006
    Posts
    8

    Thumbs up Replicating the Task module

    Dear developers, I have been playing around with SugarCRM for the past 2 weeks and the more I dive into the codes, the more confused I get. So I do really need your help.

    All I wanted to do is replicate the "Tasks" module, by the name of "Collections" task. I have copied the whole Tasks folder and renamed it, even every string in the folder. Also, I exported the Tasks table and renamed every string in the sql file and imported as Collections. It works fine, I do have the module working (edit + view).

    However, the next problem is like this:

    1. I went to "Cases"
    2. Edit an existing "case"
    3. Create "Task"
    4. Success, the "Task" appears below the buttons as an entry

    5. Create "Collection" (the one i replicated)
    6. Success, but the "Collection" didn't appear as an entry the way "Task" and "Calls" did!

    When I went to "View Collections", the entry is there. It's just the matter of making "Collection" entries viewable in "Cases".
    Please do guide me, I do get confused between terms such as Subpanels and etc.
    I do understand php, so you can post the codes as well


    Dear friends, it's okay! I found the dev' pdf files teaching how to make a new subpanel! THANKS!!
    Last edited by nikemir; 2006-06-29 at 10:55 PM.

  2. #2
    sadek's Avatar
    sadek is offline Sugar Team Member
    Join Date
    Sep 2005
    Posts
    244

    Default Re: Replicating the Task module

    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';

  3. #3
    nikemir is offline Member
    Join Date
    Jun 2006
    Posts
    8

    Default Re: Replicating the Task module

    Thank you for the reply, your answer is very detailed.
    Managed to get a lot edited in module i made with Module Builder.

    Thanks again.

  4. #4
    sadek's Avatar
    sadek is offline Sugar Team Member
    Join Date
    Sep 2005
    Posts
    244

    Default Re: Replicating the Task module

    Just trying to transfer knowledge. Glad to hear it helped.

    -Sadek

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •