CiviCon2013 Joomla Developerx

CiviCRM/Joomla
development/customization
Brian Shaughnessy
Lighthouse Consulting & Design
www.lcdservices.biz
why customize?
 not-for-profits…
o range widely in the services they provide
o range widely in the business processes they
implement
п‚§ impossible to have one-size-fits-all
п‚§ overkill to move everything to configuration
options
goals
п‚§
п‚§
п‚§
п‚§
code review/architecture
customization methods
best practices
examples
architecture
DB
DAO
PEAR
BAO
Smarty
Web
jQuery
User
directory structure
п‚§
п‚§
п‚§
п‚§
п‚§
п‚§
CRM: application
templates: Smarty .tpl files
packages: included libraries
extern: externally triggered files (IPN)
css
Joomla
directory structure: CRM
п‚§ component/feature area
o
o
o
o
o
DAO: data access objects
BAO: business access objects
Form
Page
[Controller/Selector/xml/StateMachine]
example
class/tpl correlation
п‚§ CRM/Event/Form/Registration/Register.php
п‚§ CRM_Event_Form_Registration_Register
п‚§ templates/CRM/
Event/Form/Registration/Register.tpl
standard form flow
п‚§
п‚§
п‚§
п‚§
п‚§
::preProcess
::setDefaultValues
::buildQuickForm
::formRule
::postProcess
customization methods
п‚§ PHP overrides
п‚§ Smarty overrides
o file.extra.tpl addendum
п‚§ Joomla plugin
п‚§ CiviCRM extensions
o
o
o
o
reports
search
payment gateway
modules*
don’t hack core!
 just don’t do it…
unless you have no other choice…
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
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');
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!
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 country
o add relationship end date
o add relationship enabled/disabled
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
subfolders
o CRM/Event/Form/Registration/1/Register.tpl
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
Joomla plugins
п‚§ use plugins to implement hooks (events)
п‚§ wiki.civicrm.org/confluence/display/CRMDOC
/Hook+Reference
п‚§ within your plugin class, implement:
o civicrm_hookName(…) { }
hooks
п‚§
п‚§
п‚§
п‚§
п‚§
п‚§
modify forms process
impact objects before/after saving
extension lifecycle
ACL
impact GUI (links, page, nav, etc.)
other…
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
api v3
п‚§ wiki.civicrm.org/confluence/display/CRMDOC
/API+Reference
п‚§ drupal.demo.civicrm.org/civicrm/ajax/doc/api
#explorer
п‚§ Bindings: PHP/AJAX/REST/Smarty
п‚§ Actions: Create/Delete/Get/GetCount/
GetSingle/GetFields/GetValue/Replace/
Update
п‚§ Chainable
api:php
п‚§ standard format to work with objects
$params = array(
'version'
=> 3,
'last_name'
=> 'Doe',
'contact_type' => 'Individual',
);
$contact = civicrm_api('contact', 'get', $params);
Array
(
[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
api:php
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*
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 directory
o tpl files reside in
п‚§ install/enable/run/test
extension
п‚§ wiki.civicrm.org/confluence/display/CRMDOC
/Extensions
п‚§ wiki.civicrm.org/confluence/display/CRMDOC
/Extension+Reference
п‚§ wiki.civicrm.org/confluence/display/CRMDOC
/Create+a+Module+Extension
п‚§ github.com/totten/civix/
п‚§ civicrm.org/extensions
sample civi module
п‚§ custom birthday search via module
п‚§ provide advanced tools to search contacts by
birthday, including searching by month, year
range, age range, day range
joomla extensions
п‚§ various states of development/version
compatibility
п‚§ http://wiki.civicrm.org/confluence/display/CR
MDOC/Joomla%21+Extensions+for+CiviCRM+
%283rd+party%29
п‚§ http://civicrm.org/extensions
п‚§ http://extensions.joomla.org/extensions/exte
nsion-specific/civicrm
п‚§ https://github.com/lcdservices
extensions
п‚§
п‚§
п‚§
п‚§
п‚§
п‚§
п‚§
п‚§
CiviSearch plugin
CiviCRM Group Sync component
CiviAuthenticate plugin
CiviEvent module
CiviUser component
CiviLinker plugin
Gloriant CiviCRM component
CiviLead
resources
п‚§ www.civicrm.org
п‚§ book.civicrm.org/
[user admin and developer guides]
п‚§ wiki.civicrm.org/confluence/display/CRMDOC
/CiviCRM+Documentation
[online documentation]
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