Sugar U: Session 7: An Introduction to Sugar Development, Going Way Beyond Studio

1,974 views
1,839 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,974
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
28
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sugar U: Session 7: An Introduction to Sugar Development, Going Way Beyond Studio

  1. 1. Sugar U.An Introduction to Sugar Development, Going Way Beyond Studio
  2. 2. Jeff Bickart @bickartjeff@neposystems.comwww.neposystems.com 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 2
  3. 3. Profile NEPO Systems: Founded 2008 SugarCRM Partner since 2008 (current Gold Partner) Customers Worldwide / Public & Private Sector Premium Sugar Support & Sugar Apps Jeff Bickart CTO – NEPO Systems SugarCRM developer since 2005 (v4.0.0a) Where everybody knows your name Apple Inc, Sun MicrosystemTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 3
  4. 4. Going Beyond Studio Where is everything kept? Directories of interest custom cache data modules include Where do my changes belong? custom, custom, custom SugarBeans LogicHooks SugarFieldsTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 4
  5. 5. SugarBeansdata/SugarBean.php SugarBean is a component, that represents persistent data maintained in a database Types basic, company, file, issue, person, sale Examples Accounts, Documents, Cases, Contacts, Opportunities Basic SugarBean All Beans extend basic which provides the fields: id, name, date_entered, date_modified, modified_user_id, created_by, description, deletedTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 5
  6. 6. SugarBeanTips & Tricks How to get data from the database retrieve, get_list, get_detail, get_full_list, retrieve_by_string_fields Obtain a Bean by ID Before 6.4 $account = new Account(); $account->retrieve($id); 6.4 $account = BeanFactory::getBean(‘Accounts’, $id); Obtain a set of Beans with filter $account = new Account(); $account->retrieve_by_string_fields(array(‘name’ => ‘SugarCRM’, ‘assigned_user_id’ => ‘1’)Tweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 6
  7. 7. SugarBeanRelationships $account = BeanFactory::getBean($id); Get All Related Objects $account->load_relationship(‘contacts’); Before 6.4 $contactList = $accounts->contacts->getBeans(new Contact()); 6.4 $contactList = $accounts->contacts->getBeans(); Get subset of Related Objects $contactList = $accounts->get_linked_beans(‘contacts’, ‘Contact’, array(‘date_entered’), 0, 5);Tweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 7
  8. 8. LogicHooks Allow you to add functionality to certain actions, such as before saving a bean, in an upgrade-safe manner. Module hooks before_delete - Fired before a record is deleted after_delete - Fired after a record is deleted before_restore - Fired before a record is undeleted after_restore - Fired after a record is undeleted after_retrieve - Fired after a record has been retrieved from the database before_save - Fired before a record is saved after_save - Fired after a record is saved process_record - Fired immediately prior to the database query resulting in a record being made current Other Types of LogicHooks Users module before_logout, after_logout, after_login, after_logout, before_logout, login_failed Application hooks after_ui_frame, after_ui_footer, server_round_tripTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 8
  9. 9. LogicHook Examplecustom/modules/Accounts/logic_hooks.php$hook_version = 1;$hook_array = Array();$hook_array[before_save] = Array();$hook_array[before_save][] = Array( 100, Reassign All Related Records, custom/modules/Accounts/ReassignHandler.php, ReassignHandler, reassignRecords);Tweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 9
  10. 10. Reassign All Related Recordsbefore_save LogicHook$user = new User();$user->disable_row_level_security = true;$user->retrieve($bean->assigned_user_id);foreach ($bean->field_defs as $field => $info) { if ($info[type] == link) { switch ($field) { default: $bean->load_relationship($field); foreach ($bean->$field->getBeans(new $info[bean_name]) as$focus) { if ($focus->id != "") { $focus->assigned_user_id = $bean->assigned_user_id; $focus->team_set_id = $user->team_set_id; $focus->team_id = $user->default_team; /* DO NOT SAVE THE EMAIL ADDRESSES */ $focus->in_workflow = true; $focus->save(false); } } } }}Tweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 10
  11. 11. SugarFields Custom Display of items on Screens Code goes into custom/include/SugarFields/Fields custom/include/SugarFields/Fields/Contact/: – DetailView.tpl EditView.tpl SearchView.tpl SugarFieldContact.php WirelessEditView.tpl Examples Override Existing Fields – Phone Formatting – Address – Images (Gravatar) sugarforge.org/projects/gravatar/ Custom Fields – Contact Update the custom/modules/<Module>/metadata – detailviewdefs.php, editviewdefs.php, etc… ▪ name => ’<field name>, ▪ type => contact’,Tweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 11
  12. 12. SugarFieldsExamplesTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 12
  13. 13. SugarFieldsExamples DetailView EditViewTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 13
  14. 14. Appendix Directory StructureTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 14
  15. 15. SugarBeanToggles $disable_row_level_security $update_date_modified $update_modified_by $update_date_enteredTweet: #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 15
  16. 16. Submit Session Feedback Select the SugarCon Mobile App: 1) Tap on this session 2) Tap on survey 3) Submit your feedback*Prizes for attendees who submit session feedback using the Mobile App 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 16
  17. 17. #SCON12 4/25/2012 ©2012 SugarCRM Inc. All rights reserved. 17

×