CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • format of mailing labels for married contacts
Pages: [1]

Author Topic: format of mailing labels for married contacts  (Read 2631 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
format of mailing labels for married contacts
October 03, 2009, 04:44:38 pm
I am trying to figure out the best approach for generating mailing labels for households / married couples.   I am using 2.2.8.  What I would for a household is: "Jim and Mary Smith" to appear as the first line of the label.  If one person has a title, then it should be "Dr. Jim and Mary Smith.   If they do not share a last name then it should be "Jim Smith and Mary Jones"

One idea I had was to use the "hooks" such as hook_civicrm_tokens and  hook_civicrm_tokenValues  to create my own token, but it doesn't seem like the tokens that can be used for CiviMail can be used for mailing labels.     

I also looked at the blog entry at http://civicrm.org/node/558   and thought about moving to version 3.0 using the new "postal greeting" field. But, This would require information about someone's spouse in their contact record and mark half on the contacts "Do not mail" event though there are times when I DO want to communicate with the spouse. Plus someone would have to manually enter the desired postal greeting for half of the contacts of the database. Plus, doesn't this defeat the whole purpose of recording a "spouse" relationship in the database? ANy time someone gets married or divorced, someone would have to update the postal greeting in addition to creating/removing the "spouse" relationship.

Any suggestions are welcome.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: format of mailing labels for married contacts
October 04, 2009, 07:38:42 am

The token hooks do work with the mailing labels also

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: format of mailing labels for married contacts
October 04, 2009, 11:02:41 am
I wrote a hook to create a new token called "contact.joint_greeting" as is documented at http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-Proceduresforimplementinghooks%28forJoomla%29

This is working when I use my new token to generate PDF letters.    I have also changed the "global settings" for address so the mailing label format is specified as:
{contact.joint_greeting}
{contact.addressee}
{contact.street_address}
{contact.supplemental_address_1}
{contact.supplemental_address_2}
{contact.city}{, }{contact.state_province}{ }{contact.postal_code}
{contact.country}

But when I generate my mailing labels, the new token is ignored.


Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: format of mailing labels for married contacts
October 04, 2009, 01:43:20 pm

1. can u check if your hook is being invoked for the labels case

2. can u add some debugging code here: CRM/Contact/Form/Task/Label.php, function postProcess and try to see whats happening and why. I see the hook is being called in that function (CRM_Utils_Hook::tokenValues)

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: format of mailing labels for married contacts
October 04, 2009, 05:47:46 pm
I did some debugging:  My hooks ARE being called. It successfully gets my custom token "contact.joint_greeting"

But in the section of code:
else {
                $found = false;
                
                
                // we should replace all the tokens that are set in mailing label format
                foreach ( $mailingFormatProperties as $key => $dontCare ) {
                    if ( CRM_Utils_Array::value( $key, $contact ) ) {
                        $found = true;
                        break;
                    }
                }


The variable "$mailingFormatProperties" has my token as just "joint_greeting" .  It also seems to be looking for the data to fill the label from the $contact variable, not the array returned from the hook.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: format of mailing labels for married contacts
October 05, 2009, 06:47:43 am

i'll take a look at this sometime this week or so

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: format of mailing labels for married contacts
October 05, 2009, 08:16:43 am
I'll put what I have found out so far in the issue tracker.   
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: format of mailing labels for married contacts
October 05, 2009, 10:20:33 am
This issue is now on the JIRA issue tracker at: http://issues.civicrm.org/jira/browse/CRM-5178
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: format of mailing labels for married contacts
October 05, 2009, 10:36:13 am

i fixed it on your site. there were two issues:

1. your hook implementation was a bit broken

2. the mailing label token substitution behaves a bit differently than the other stuff. This is a bug and needs to be fixed. You can work around it by doing the following in your hook:

Code: [Select]

function joomla_civicrm_tokens( &$tokens ){
 
  $tokens['contact'] = array( 'contact.joint_greeting', 'joint_greeting' );


}

function joomla_civicrm_tokenValues( &$values, &$contactIDs ) {
    if ( is_array( $contactIDs ) ) {
        $single = false;
        foreach ( $contactIDs as $cid ) {
          $values[$cid]['joint_greeting'] = $values[$cid]['contact.joint_greeting'] = 'George and Jane Jetson';
        }
    } else {
        $values[$contactIDs]['joint_greeting'] = $values[$contactIDs]['contact.joint_greeting']  = 'Single George and Jane Jetson';
        $single = true;
    }
 }

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: format of mailing labels for married contacts
October 05, 2009, 03:40:44 pm
I have been testing the new code. My token now works for mailing labels, but stopped working for the action "Print PDF letters".   
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: format of mailing labels for married contacts
October 07, 2009, 09:25:54 pm

i'm pretty sure this is because of a bad hook implemenation. The code below should be:

Code: [Select]
function joomla_civicrm_tokenValues( &$values, &$contactIDs ) {
    if ( is_array( $contactIDs ) ) {
        foreach ( $contactIDs as $cid ) {
          $values[$cid]['joint_greeting'] = $values[$cid]['contact.joint_greeting'] = 'George and Jane Jetson';
        }
    } else {
        $values['joint_greeting'] = $values['contact.joint_greeting']  = 'Single George and Jane Jetson';
    }
 }

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • format of mailing labels for married contacts

This forum was archived on 2017-11-26.