courtly
courtly
courtly
courtly

Upcoming Events

San Francisco CiviCRM Meetup - February 8th, 2012
February 8th, 2012
Come meet others from the Bay Area who are interested in, using or developing (more...)

UK usergroup - London meetup
February 8th, 2012
Come and meet others from the UK that are using CiviCRM or are interested in (more...)

London user and administrator training
February 23rd, 2012
A comprehensive two day hands on training course covering the configuration, (more...)

CiviCRM London sprint Feb 2012
February 27th, 2012
Following the CiviCRM training here in London, we will have a CiviCRM code (more...)

UK South West - CiviCRM Meetup
March 20th, 2012
Come meet others from the Area who are interested in, using or developing for (more...)

[Bristol, UK] user and administrator training
March 21st, 2012
A comprehensive hands on training course covering the configuration, (more...)

San Francisco user and administrator training
March 29th, 2012
A comprehensive two day hands on training course covering the configuration, (more...)

CiviCRM Usability, Test and Code Sprint - San Francisco (March 2012)
March 29th, 2012
This usability, code and test sprint is targeted at CiviCRM users and (more...)

CiviCon 2012 San Francisco Bay Area - April 2nd 2012
April 2nd, 2012
CiviCon is THE annual event bringing together the people who use, develop, (more...)

CiviCRM Documentation, Test and Code Sprint - after CiviCon San Francisco (April 2012)
April 4th, 2012
This sprint is targeted at CiviCRM users and developers who want to work on (more...)

CiviCRM Components

Tools for engaging your supporters...

CiviContribute


CiviEvent


CiviMail


CiviMember


CiviReport


Extending contact demographic information with a custom group

Not Just a Contact Database

These optional components give you more power to connect and engage your supporters.

  • civiCASE

  • Case management for clients and constituents.

  • civiEVENT

  • Online event registration and participant tracking.

  • civiMEMBER

  • Online signup and membership management.

  • civiMAIL

  • Personalized email blasts and newsletters.

  • civiREPORT

  • Report generation and template management.

December 7, 2009 - 19:01 — lobo

We are working with PTP and Dharmatech to incorporate their work on Canvass and Phonebank into CiviCRM v3.1. Initially we plan to package and release this as the civicrm_canvass drupal module

As part of this work, we need to "extend" the core demographic information in a seamless manner. CiviCRM holds the gender / birth date / deceased date as core fields. However PTP also wanted to collect additional demographic information: ethnicity, primary language, secondary language and number of kids. We plan on storing this additinal demographic data as a custom group. We had to inject this custom group into the demographic section for the contact view and edit forms. We also wanted to hide the custom group showing up as a tabbed pane in the contact view screen.

We accomplished all this using the all powerful and mighty hook system. We could inject a complete custom group into the edit field by implementing the buildForm hook and using some internal CiviCRM functions

        // grab the set of custom fields and their type from the DB
	// ensure that you have the demographic custom group ID set
        $groupTree =& CRM_Core_BAO_CustomGroup::getTree( 'Contact',
                                                         $form,
                                                         $form->getVar( 'id' ),
                                                         CIVICRM_CANVASS_DEMOGRAPHICS_ID,
                                                         null, null );

        // we should use simplified formatted groupTree
        $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree( $groupTree, 1, $form );

        // if there are fields to process
        if ( isset($groupTree) && is_array($groupTree) ) {
            $defaults = array( );
            CRM_Core_BAO_CustomGroup::setDefaults( $groupTree, $defaults);
            $form->setDefaults( $defaults );

            // lets build all the form elements with one nice function call
            CRM_Core_BAO_CustomGroup::buildQuickForm( $form, $groupTree, false, 1,
                                                      CIVICRM_CANVASS_DEMOGRAPHICS_PREFIX );
        }

We also need to modify the templates to inject these custom fields at the right place. I had to restructure the contact edit template so that the demographics had their own separate tpl. This makes it much easier to override just the demographics tpl. I added the following lines of code to the restructured tpl towards the end of the file:

  {foreach from=$demographics_groupTree item=cd_edit key=group_id}
     {foreach from=$cd_edit.fields item=element key=field_id}
        
        {include file="CRM/Custom/Form/CustomField.tpl"}
        
{/foreach} {/foreach}

Edit Demographics Page

The changes for contact page view were along similar lines. You can check the svn repository for the specific view related changes.

View Demographics Page

To hide the custom tab from showing up in the contact view screen, we implemented the hook_civicrm_tabs as follows:

function civicrm_canvass_civicrm_tabs( &$tabs, $contactID ) {
    foreach ( $tabs as $tabID => $tabValue ) {
        if ( $tabValue['title'] == CIVICRM_CANVASS_DEMOGRAPHICS_TITLE ) {
            unset( $tabs[$tabID] );
        }
    }
}

Due to some core civicrm changes, this code will only work in 3.1 and later. I also did not add the custom fields to the advanced search form.

( categories: )

Comments

I am not a programmer, can I

I am not a programmer, can I just add the dob and gender to a custom data group with other demographics?

multi-language and multietnics?

What will be about people speakin mro of a language?
(My girlfriedn is speaking 5 laguages, and who know about future?)

And about people born from the mix of an India and an European and he live around the world, which will be him etnicity?

Custom fields are configurable

All the fields in the screenshot above - OTHER THAN Gender, Date of Birth and Is Deceased - are defined in the Demographics custom data group. This means you can add, remove or change things like language(s), ethnicity, etc. to meet your needs.