june 10th: the sugarcrm platform

28

Upload: matthew-cooke

Post on 11-Aug-2015

82 views

Category:

Business


1 download

TRANSCRIPT

Page 1: June 10th: The SugarCRM Platform
Page 2: June 10th: The SugarCRM Platform

Intro

• Power Hour– Developer / Admin Resource– Promote Successful Implementations

• Ticomix– SugarCRM “Advanced” Partner– 2014 Rising Star– Consulting, Development & Support– www.ticomixcrm.com– @TicomixCRM / @TicomixInc

• Webinar Logistics

Page 3: June 10th: The SugarCRM Platform

About Jeff Bickart• Sugar Developer since version 4.0a• Director of Engineering of a Voice-Enabled CRM

startup• Chief Technology Officer, NEPO Systems −

SugarCRM GOLD Partner • CRM Evangelist, Ticomix• Contact Information– @bickart– www.linkedin.com/in/bickart

Page 4: June 10th: The SugarCRM Platform

Sugar Development 101Sugar as a Platform• MVC (Module View Controller)

– Server Side– Client Side

• ORM (Object Relationship Mapping)– Beans– Relationships

• API (Application Programming Interfaces)– REST– SOAP

• How and where to add customizations– Extension Framework– Logic Hooks

• Debugging tips and techniques– IDE – Xdebug– Logging

Page 5: June 10th: The SugarCRM Platform

Development 101• Directories of Interest

– custom– cache– data– Modules– include– vendor– sidecar

• Where do my changes belong?– custom– custom– custom– modules

Page 6: June 10th: The SugarCRM Platform

Model, View and Controller (MVC)SuiteCRM, Sugar 6, Sugar 7 #bwc• Model

– SugarBeans• View (Sugar 6 and Sugar 7 #bwc)

– Displaying information to the browser• Detail View• Edit View• List View

– Two parts to a view• metadata

– Example: custom/modules/Accounts/metadata/editviewdefs.php

• class loader– Example: custom/modules/Accounts/views/view.edit.php

• Controller– actions such as

• Display• Save• Etc.

Page 7: June 10th: The SugarCRM Platform

Model, View and Controller (MVC)Sugar 7 (client)• Model

– Backbone.js• gives structure to web applications by providing models with key-value binding and custom events,

collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

• View– Layouts

• Layouts are components which render the overall page. They are used to define the rows, columns, and fluid layouts that the content is displayed to the user in.

– Views• Views are components which render data from a context and may or may not include field components.

Example views include not only record and list views but also widgets• Utilizes HandleBars and Controllers

– Fields• Fields render widgets for individual values pulled from the models and handle formatting (or stripping the

formatting of) field values. Just like Layouts and Views, Fields also extend Backbone Views• Utilizes HandleBars and Controllers

Page 8: June 10th: The SugarCRM Platform

Object Relationship Mapping (ORM)

• Beans– CRUD (Create, Read, Update, Delete)– Defined via Variable Definitions (i.e., vardefs) and

Templates• Relationships– Are the basis for linking information within the system

Page 9: June 10th: The SugarCRM Platform

Sugar Object Templates• Basic

– The building blocks needed to communicate with the DB. – Fields

• id, name, date_entered, date_modified, created_by, modified_user_id, created_by, description, deleted

– Associated Relationships• Company

– Additional information that pertains to a company; addresses, industry, revenue, etc.• File

– Addition logic in order to be able to upload and maintain files in a module• Issue

– This is the basis of cases• Person

– Additional information as it pertains to a person; first_name, last_name, email addresses, etc.• Sale

– The building blocks of an Opportunity; amount fields

Page 10: June 10th: The SugarCRM Platform

Object Relational Model• 99.9% of the time you do NOT need to write SQL!• If you think that you need SQL you are doing something WRONG!• Sugar is Object Oriented• SugarBean

– Performs all operations with the DB• Create, Retrieve, Update, Delete

– All Modules extend the SugarBean– Examples

• Leads -> Person -> Basic -> SugarBean• Accounts -> Company -> Basic -> SugarBean• Opportunity -> Sale -> Basic -> SugarBean

Page 11: June 10th: The SugarCRM Platform

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, deleted

Page 12: June 10th: The SugarCRM Platform

Vardefs (variable definitions)• Sugar uses a file based approach to store all of the information to

describe each field as it relates to a module and how that information should be stored in the DB

• Every module that communicates to the DB will need a vardefs.php file– <module>/vardefs.php– At the end of the file, you must tell Sugar which template to base your

module upon• if (!class_exists('VardefManager')) {

require_once 'include/SugarObjects/VardefManager.php';}VardefManager::createVardef('TCX_Passwords', 'TCX_Passwords', array('basic', 'team_security', 'assignable'));

Page 13: June 10th: The SugarCRM Platform

VardefsContinued

• Quick Repair and Rebuild– Builds the aggregated version of the Vardefs into

cache/modules/<mymodule>/<MyModule>Vardefs.php• Sugar uses this file for

– communicating to the DB– display subpanels– Join field– Adding fields to the DB

– Aggregated Version comes From• modules/<mymodule>/vardefs.php• Template

– Include/SugarObjects/templates/

• fields_meta_data (fields added via Studio)• custom/Extension/modules/<mymodule>/Ext/Vardefs

– sugarfield_field_name.php – generated when using Studio

Page 14: June 10th: The SugarCRM Platform

SugarBeanTips & Tricks

• Obtain a Bean by ID• $account = BeanFactory::getBean(‘Accounts’, $id);• $account = BeanFactory::getBean(‘Accounts’, $id,

array(‘disable_row_level_security’ => true));

• Obtain a set of Beans with filter– Sugar 6

• $account = BeanFactory::newBean(‘Accounts’);• $results = $accounts->get_list("", "accounts.assigned_user_id = '1'", 0);

– Sugar 7• $accounts = BeanFactory::newBean('Accounts');• $query = new SugarQuery();• $query->from($accounts)->where()->equals('assigned_user_id','1');• $results = $accounts->fetchFromQuery($query);

Page 15: June 10th: The SugarCRM Platform

SugarBeanRelationships

• $account = BeanFactory::getBean($id);• Get All Related Objects

– $account->load_relationship(‘contacts’);– $contactList = $accounts->contacts->getBeans();– $contactIDs = $accounts->conacts->get();

• Get subset of Related Objects– Sugar 6

• $contactList = $accounts->get_linked_beans(‘contacts’, ‘Contact’, array(‘date_entered’), 0, 5);

– Sugar 7• $current = $accounts->contacts->query(

array( 'where' => array( 'lhs_field' => ’type', 'operator' => '=', 'rhs_value' => ’Customer’ ) )

Page 16: June 10th: The SugarCRM Platform

APIs

• Sugar 6– SOAP• <sugarcrm>/service/v4_1/soap.php

– REST• <sugarcrm>/service/v4_1/soap.php

• Sugar 7– <sugarcrm>/rest/v10– Documentation• <sugarcrm/rest/v10/help

Page 17: June 10th: The SugarCRM Platform

Customizations

Page 18: June 10th: The SugarCRM Platform

Sugar 6 Root Directory Structure• data - This directory contains files related to SugarCRM's Model. You will find information about SugarBean as well as how relationship

are connected to the SugarBean• examples - In this directory you will find a variety of examples on how to connect external sources into SugarCRM. There is a SOAP

example and some example configurations about • include -- SugarCRM's framework and 3rd party libraries, except Zend and Xtemplate, used by SugarCRM• install -- Logic to install SugarCRM. Once installed the files in this directory are unused• jssource -- Original JavaScript files before they have been minified.• log4php -- Deprecated logger replaced with include/SugarLogger: SugarCRM no longer uses log4php but the directory remains• metadata -- This directly contains "join table" definitions. For example the definition of the accounts_contacts table• ModuleInstall --Utilized by Upgrade Wizard, Module Loader and silentUpgrade to update the SugarCRM environment• modules -- SugarCRM MVC for each section of the application. Examples include accounts and contacts• portal -- Customer Portal: This code only works for Sugar Enterprise and Sugar Ultimate • service -- WebServices are supported from here both REST and SOAP• soap -- Deprecated version of the SOAP WebService, see the service directory for updated versions• themes -- User Interface definitions that Sugar supports are located in this directory• upload -- new location in 6.4. This is where uploaded files will be stored. Prior to 6.4 this directory was under cache• xtemplate -- A library by PHP Xtemplate that is provided for backward compatibility. SugarCRM now uses the smarty Template Engine.

smarty can be found at include/smarty• zend -- Portions of the Zend Framework that are used by SugarCRM• cache -- This directory is used by SugarCRM application to store converted metadata that can be displayed by the SugarCRM application.

Items include screens, and data • custom --All upgrade safe customization will go into this set of directories. Anything that is in here is safe from SugarCRM upgrade wizard

Page 19: June 10th: The SugarCRM Platform

Sugar 7 Directory Structure• Ext

– The Extension Framework can now be used from the core of Sugar including within the core modules. So it is now possible to create system wide extensions in custom/Ext

• ModuleInstall• api• cache• clients

– Sugar UX code;– Sugar now supports multiple clients

• base – Standard UX• portal – Portal UX

– UX Elements such as SugarFields, Layouts, View, Dashlets

• custom• data• examples• include• install• jssource

– JavaScript source code

• metadata• mobile

– Access to mobile view of the product for example: https://crm.ticomix.com/mobile

• modules• portal2

– Enterprise portal

• service• sidecar

– files used by the new UX, sidecar. Document can be found here: https://jsduck.test.ticomix.net/

• soap• styleguide

– Files used by the sytleguide available in Sugarhttps://crm.ticomix.com/#Styleguide

• themes• upgrade• upload• vendor

– All code not created by sugar has been moved to the vendor directory which is consistent with composer

Page 20: June 10th: The SugarCRM Platform

Logic Hooks• Similar in nature to Workflows• Not limited in functionality• Examples:

– Communicate with 3rd Party Web Services– Update data by assignment– Send Notification(s)

• Location– Sugar’s documentation doesn’t specify where Logic Hooks should reside. – Module Logic Hooks

• custom/modules/<module>/LogicHooks - keeps them all together• Prefer if you have a separate file for each Logic Hook; Easier to update a single file without effecting other Logic Hooks

– custom/modules/<module>logic_hooks.php<?php/ $hook_version = 1; $hook_array = Array(); $hook_array['after_save'] = Array(); $hook_array['after_save'][] = Array(10, 'Assign Authorize.Net to the Contact', 'custom/modules/Leads/LogicHooks/UpdateAuthorizeNet.php','UpdateAuthorizeNet', 'addContactToAuthorizeNet');

Page 21: June 10th: The SugarCRM Platform

Logic HooksSugar 6• Application Hooks

– after_entry_point– after_ui_footer– after_ui_frame– server_round_trip

• Module Hooks– after_delete– after_relationship_add– after_relationship_delete– after_restore– after_retrieve– after_save– before_delete– before_relationship_add– before_relationship_delete– before_restore

– before_save– handle_exception– process_record

• User Hooks– after_login– after_logout– before_logout– before_login– login_failed

• Job Queue Hooks– job_failure– job_failure_retry

• SNIP Hooks– after_email_import– before_email_import

Page 22: June 10th: The SugarCRM Platform

Logic HooksSugar 7• Application Hooks

– after_entry_point– after_ui_footer– after_ui_frame– server_round_trip

• Module Hooks– after_delete– after_relationship_add– after_relationship_delete– after_relationship_update– after_restore– after_retrieve– after_save– before_delete– before_relationship_add– before_relationship_delete– before_restore– before_save– handle_exception– process_record

• User Hooks

– after_load_user– after_login– after_logout– before_logout– login_failed

• Job Queue Hooks– job_failure– job_failure_retry

• SNIP Hooks– after_email_import– before_email_import

• API Hooks– after_routing– before_api_call– before_filter– before_respond– before_routing.

• Web Logic Hooks– Web Logic Hooks allow for administrators to post

record and event information to a specified URL when certain sugar events take place

Page 23: June 10th: The SugarCRM Platform

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

Page 24: June 10th: The SugarCRM Platform

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); }

} } }}

Page 25: June 10th: The SugarCRM Platform

Debuging

Page 26: June 10th: The SugarCRM Platform

Logging

• $GLOBALS[‘log’]->– fatal– error– warn– info– debug

• _ppl

Page 27: June 10th: The SugarCRM Platform

Debuging

• xdebug

Page 28: June 10th: The SugarCRM Platform

Future WebinarsTopics Subject to Change

• Future Topics– Using the SugarJobQueue– LogicHooks– Deploying Packages – Layouts– Views– Fields– Building a Wizard