civicrm development/customization brian shaughnessy lighthouse consulting & design

30
CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design www.lcdservices.biz

Upload: juniper-merritt

Post on 26-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

CiviCRMdevelopment/customization

Brian ShaughnessyLighthouse Consulting & Design

www.lcdservices.biz

Page 2: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

built to be customized!why?

Page 3: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

inevitability of audience not-for-profits…

o range widely in the services they provideo range widely in the business processes they

implement impossible to have one-size-fits-all overkill to move everything to configuration

options

Page 4: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

goals code review/architecture customization methods best practices examples

Page 5: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

architecture

DB DAO BAO Smarty Web

PEAR UserjQuery

Page 6: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

directory structure CRM: application templates: Smarty .tpl files packages: included libraries extern: externally triggered files (IPN) css Joomla

Page 7: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

directory structure: CRM component/feature area

o DAO: data access objectso BAO: business access objectso Formo Pageo [Controller/Selector/xml/StateMachine]

Page 8: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

example

Page 9: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

class/tpl correlation CRM/Event/Form/Registration/Register.php CRM_Event_Form_Registration_Register templates/CRM/

Event/Form/Registration/Register.tpl

Page 10: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

standard form flow ::preProcess ::setDefaultValues ::buildQuickForm ::formRule ::postProcess

Page 11: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

customization methods PHP overrides Smarty overrides

o file.extra.tpl addendum Joomla plugin CiviCRM extensions

o reportso searcho payment gatewayo modules*

Page 12: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

don’t hack core! just don’t do it…

unless you have no other choice…

Page 13: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

debugging tips print variables

o CRM_Core_Error::debug(‘varname’, $varObj); [log to screen]

o CRM_Core_Error::debug_var(‘varname’,$varObj); [log to file]

o CRM_Core_Error::debug_log_message($msg, TRUE/FALSE);[log to screen or file]

o CRM_Core_Error::backtrace(); tail log file

o /media/civicrm/ConfigAndLog/FILE.log

Page 14: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

debugging tips enable debugging display smarty variables

o append: &smartyDebug=1 search “.tpl” in page source to trace file log queries to file

o define( 'CIVICRM_DAO_DEBUG', 1 ); log mail to file

o define('CIVICRM_MAIL_LOG', '/path/to/mail.log');

Page 15: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

php/tpl overrides define location

o Administer > System Settings > Directories follow folder pattern for core files pros:

o complete control over code flow/layout without hacking core

cons:o must be maintained through upgrades

be sure to comment thoroughly!

Page 16: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

php override example report templates are a common area where

clients want customizations. the template defines the fields, filters, sort

options, calculations, action options, and display most of those options are defined in a large array

during class construction current employer report:

o remove countryo add relationship end dateo add relationship enabled/disabled

Page 17: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

smarty override example any page rendered by CiviCRM is pushed

through the Smarty templating engine the Smarty file contains the html and passed

variables to be rendered events and profiles may have ID-specific

subfolderso CRM/Event/Form/Registration/1/Register.tpl

Page 18: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

file.extra.tpl files instead of overriding Smarty files, you can

create a new file named filename.extra.tpl benefit: avoid modifying and maintaining the

entire .tpl file – only need to interact with the elements you are modifying

relies on js/jquery for most implementations limitations: template files included via

another template file is not captured by the .extra insertion code

Page 19: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

Joomla plugins use plugins to implement hooks (events) wiki.civicrm.org/confluence/display/CRMDOC

/Hook+Reference

within your plugin class, implement:o civicrm_hookName(…) { }

Page 20: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

hooks modify forms process impact objects before/after saving extension lifecycle ACL impact GUI (links, page, nav, etc.) other…

Page 21: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

plugin example CiviCRM has a user dashboard page that

summarizes the contact’s involvement with your organization

Let’s create a plugin to retrieve the contact’s product purchases from RedShop and include the list in the dashboard

Page 23: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

api:php standard format to work with objects

$params = array( 'version' => 3, 'last_name' => 'Doe', 'contact_type' => 'Individual',);$contact = civicrm_api('contact', 'get', $params);

Page 24: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

api:phpArray( [is_error] => 0 [version] => 3 [count] => 2 [values] => Array ( [4] => Array ( [contact_id] => 4 [contact_type] => Individual [contact_sub_type] => [sort_name] => Doe, John [display_name] => Mr. John Doe [do_not_email] => 0 [do_not_phone] => 0 [do_not_mail] => 0 [do_not_sms] => 1 [do_not_trade] => 0 [is_opt_out] => 0 [legal_identifier] => [external_identifier] => [nick_name] => J.D. [legal_name] => [image_URL] => [preferred_mail_format] => Both [first_name] => John [middle_name] => P. [last_name] => Doe [job_title] => Executive Director [birth_date] => [is_deceased] => 0 [deceased_date] => [household_name] => [organization_name] => [sic_code] => [contact_is_deleted] => 0 [gender_id] => 2 [gender] => Male [prefix_id] => 3 [prefix] => Mr. [suffix_id] => [suffix] => [current_employer] => Worldwide United for Food [address_id] => 4 [street_address] => 123 Main Street [supplemental_address_1] => [supplemental_address_2] => [city] => Albany [postal_code_suffix] => [postal_code] => 12208 [geo_code_1] => [geo_code_2] => [state_province_id] => 1031 [state_province_name] => New York [state_province] => NY [country_id] => 1228 [country] => United States [phone_id] => 2 [phone_type_id] => 1 [phone] => 800-123-4567 [email_id] => 4 [email] => [email protected] [on_hold] => 0 [im_id] => [provider_id] => [im] => [worldregion_id] => 2 [world_region] => America South, Central, North and Caribbean [id] => 4 )

Page 25: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

civicrm extensions CMS-agnostic can be submitted to the CiviCRM extension

directory installed through:

Administer » System Settings » Manage Extensions

payment processors, custom search, custom report, module*

Page 26: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

extension create folder in custom extension directory:

domain.type.name create info.xml to define the extension

parameters refer to documentation for xml options and

naming conventions create php and tpl files

o php files reside in base directoryo tpl files reside in

install/enable/run/test

Page 28: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

sample module extension custom birthday search via module provide advanced tools for search contacts by

birthday, including searching by month, year range, age range, day range

Page 29: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

resources www.civicrm.org book.civicrm.org/

[user admin and developer guides] wiki.civicrm.org/confluence/display/CRMDOC

/CiviCRM+Documentation [online documentation]

Page 30: CiviCRM development/customization Brian Shaughnessy Lighthouse Consulting & Design

community wiki: http://wiki.civicrm.org forum: http://forum.civicrm.org/ IRC: #civicrm on irc.freenode.net blogs: http://civicrm.org/blog/ bug: http://issues.civicrm.org