Skip to end of metadata
Go to start of metadata

Templates and Debugging

Documentation at: http://wiki.civicrm.org/confluence/display/CRMDOC/Debugging

1. Enable debugging options from Admin Screen. Ensure that you can clean the templates_c directory and also reset the session. Check and find the log file.

2. Enable Mail Logging by setting the CIVICRM_MAIL_LOG config option in civicrm.settings.php:

civicrm.settings.php

3. Send an email or two. Ensure you can read the email sent

4. Locate the template for a few screens: New Individual, Admin Page

Customizing templates

1. Set the template path to a directory OUTSIDE civicrm root

2. Customize the New Individual template

3. Eliminate the Middle Name

4. Customize the Contact View template and add a Groups line (under the tags line). Make sure u add a few tags to the contact (to see the tags line).

Hint: Use the Smarty function crmAPI, check:

http://en.flossmanuals.net/civicrm/ch066_api/

5. Also run the REST API URL via the browser and see the return valueshttp://www.example.org/civicrm/ajax/rest?fnName=civicrm/contact/search&json=1

6. Following the model above, display the relationships for a contact using crmAPI function

Implementing Hooks

1. Create a Drupal Module: civitraining and enable it.

2. Implement the hook_civicrm_config hook and set the template path programmatically

Hint: http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmconfig
Hint: Check civitest.module.sample
Hint: Check the code for the sfschool module http://svn.civicrm.org/sfschool/branches/v3.2/drupal/sfschool/sfschool.module

3. Extra Credit: Set the PHP path also

4. Lets store NI Numbers (Country ID number) for Individuals

5. Inject a new form element in the New Individual Form (below external identifier). Call the element training_ni (Use the buildForm hook)

6. Customize the template to show this element

7. Implement the validate hook and ensure that the NI is valid.

Valid Number: AB 12 34 56 C
Invalid Number: 12 34 56 78 9

8. create a DB table in your civicrm db called training_ni with 3 columns (id, entity_id, ni)

9. Implement the postProcess hook and store the NI here (make sure you handle both the update and create case)

10. Go back to the buildForm hook and implement the setDefault function to retrieve and display the NI number

11. Go to the Contact page view and display the NI field (use hook_civicrm_pageRun)

12. Now create a custom group (that extends contact) called "Secret Info" and add a field "NI". You can play with the settings and see where CiviCRM displays the form. Check the schema of the table created by CiviCRM

Advanced PHP coding

1. . We'd like to store the SSN in an encrypted format. Implement hook_civicrm_custom to encrypt this field. For this exercise, lets use base64 encryption / decryption base64_encode and base64_decode

2. We don't want everyone to see the decrypted value. Create a drupal permission "access secret stuff". For all users with this permission, display the decrypted SSN. for the rest only show the last 4 digits

More hooks and customizations

1. Using customized templates, add a link to the end of every address to link to neighborhood summary information if there is a postcode

www.neighbourhood.statistics.gov.uk/dissemination/NeighbourhoodSummary.do?width=1440&a=3&i=1001&m=0&s=1284550555705&enc=1&profileSearchText=<POSTCODE>

2. Use the hook_civicrm_tabs to display the above information in a tab for a contact if there is a postcode for the primary address

3. Using the token hooks:

http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmtokens

http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmtokenValues

create a token to expose an organization contact primary contact name. This should be the individual who has an employee relationship with the organization and has "permissioning" flag enabled

CiviReport

CiviReport structure and customization

1. Use existing "Constituent Summary Report" and create a new report "My Constituent Summary Report"

2. Add First Name and Last Name to your Report
Hint: Add above fields to columns array

2. Add gender to above report. Make sure that the selector displays the label (male/female) and not the id
Hint: Add gender to fields. Then use alterDisplay() to modify the display

3. Add phone, job_title to event participant report
Hint:

  • You will have to add new table civicrm_phone and columns
  • You will also need to add LEFT JOIN for civicrm_phone table fromClause()

4. Add Duration col to Activity report and for bonus points, add a sum at the bottom (so folks can see total duration / time spent)

Advanced Users:

  • Package above report as CiviCRM extension

jQuery and CiviCRM

1. Create a contribution page with the dummy processor and use the Name and Address Profile in the "before" slot, so that it display after billing block

2. Customize the template to add a "HTML" checkbox. When checked, it copies billing information to the name and address profile (using a javascript/jQuery snippet)

Implement a javascript snippet to copy billing address to profile fieldshttp://forum.civicrm.org/index.php/topic,7719.msg50612.html#msg50612

3. Implement dependable custom fields.

Create a custom groups: "Dependable Fields" of type Individual with custom fields 

  • Issues: radio ( Road / Water /  Air )
  • Road Issue Description ( text )
  • Water Issue Description ( text )
  • Air Issue Description ( text )

When form loads we should only display Issues radio and then based selected radio button, display corresponding text box.

Some more details on Xavier's blog post and CiviCRM Public APIs

CiviCRM Profiles

Scenario:

We want to collect volunteer information: first name, last name, email, address, city, state and zip. So once profile is saved we also want to send an email to volunteer upon signs up. CiviCRM Profiles with a few hooks can be used to solve this problem.

1. Create a profile "Signup as a Volunteer" that has above fields

2. We need to do ajax dedupe check based on first name and last name. If matching contact is found show the matching contact with view link.

3. Use the post hook to send an email to contact

Views2 and other Civi-Drupal modules

1. Create a paid membership directory with name and address using Views2

2. Create a event listing and calendar with time and summary in a Views2 Block

3. If time permits, check the CiviCRM member <-> roles module and the permission options

Webform and CiviCRM

Scenario : Log a parent child meeting in a single form.

1. Create a set of fields for student info - First Name Last Name

2. Create a set of more fields for parent info - First Name, Last Name, Address Information, Email

3. Create a parent child relationship between the 2 contacts.

4. An activity of type "Meeting" should be logged between the parent & child.

Creating Custom Search

Custom Search Components

NI Number Search

Task: create a custom search that finds contacts based on their name, province and/or whose NI number starts with a specific sequence.

  1. Add a couple of different NI numbers to a couple of your contacts, some of them starting with the same sequence (and some not).
  2. Figure out the SQL needed to fetch the contacts with a given NI number.
  3. Copy an existing custom search (try to find a similar one…) to use it as a template for your own.
  4. Register your custom search component.
  5. Try out the existing search and modify it to fit your needs; test to see whether it works.
  6. Figure out the SQL needed to fetch the contacts based on their name, province and/or with an NI number starting from a given sequence – and modify your search to do this.

Find participants based on events’ custom data values

Task: Find participants that are attending events with custom data based on event custom data values.

  1. Extend an event with a set of custom data of your choice.
  2. Create a couple of events that use these custom data.
  3. Make a couple of contacts attend these events.
  4. Based on the steps for the previous exercise, create a custom search that finds the contacts that are participants of events matching the provided event custom data values. Hint: contacts are connected to events via the civicrm_participant table and event custom data are connected to events via the given custom data table.
Labels:

Creative Commons License
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-Share Alike 3.0 United States Licence.