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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CiviContribute - Export: Map Contact Tags and Contact Custom Greeting
Pages: [1]

Author Topic: CiviContribute - Export: Map Contact Tags and Contact Custom Greeting  (Read 1269 times)

jbachmann

  • Guest
CiviContribute - Export: Map Contact Tags and Contact Custom Greeting
October 08, 2009, 03:56:37 pm
I'm working for a client who has a few requirements which would be solved if they were able to map the following two elements to be displayed in the resulting CSV file when doing a Contribution Export:

1. All tags, space delimited in a single column, associated with the Contact who owns the Contribution row
2. The custom_greeting column from the Contact database table

I know that we can export tags on the Contact Export, so I feel confident that it could be done at the Contribution level as well.
My client is ALWAYS selecting 'Customize' as the 'Greeting Type', and the 'Custom Greeting' field will ALWAYS be populated, I really just need to be able to dump the civicrm_contact.custom_greeting values to the export rows.

In 2.2.8 (don't know about 3.0), when 'Greeting Type' is selected in the export field mapping, the 'Custom Greeting' column is NOT auto generated like it is for Contact Export.

If any of this has changed in 3.0, I would like to know, however upgrading at this point in time is not an option.

If anyone has done any kind of modification to the Contribution Export, please let me know. If anyone at least knows where in the source I should be looking to accomplish this task, that would also be very helpful to know.


Thanks in advance!

- Jordan Bachmann

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: CiviContribute - Export: Map Contact Tags and Contact Custom Greeting
October 08, 2009, 06:34:49 pm

All exports are driven via the search engine, so the code is here:

CRM/Contact/BAO/Query.php

all exports go via: CRM/Export/Form/*

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

jbachmann

  • Guest
Re: CiviContribute - Export: Map Contact Tags and Contact Custom Greeting
October 08, 2009, 06:47:20 pm
Since I'm looking to alter results of the Contribution Export, would I instead being dealing with  CRM/Contribution/BAO/Query.php ?

The fields I want to add are Contact specific, so I may be wrong.

jbachmann

  • Guest
Re: CiviContribute - Export: Map Contact Tags and Contact Custom Greeting
October 09, 2009, 07:43:43 am
Because I HATE finding forum posts that pose the same questions that I'm looking to answer, but contain no answer, I've decided to post my solution.

We came up with a solution that's not particularly elegant, but it gets the job done for now.

To reiterate, we were trying to have the 'custom_greeting' column from the civicrm_contact and a delimited list of tag names be exportable for Contribution records.
We did NOT want to use any tokens with the 'custom_greeting' field (not sure if this actually makes a difference).
We did NOT care whether or not 'Custom Greeting' or 'Tag(s)' showed up on the manual mapping screen when setting up the export fields, we ALWAYS wanted them to be exported.

These alterations will effect Contact, Contribution and Participant Export results.


In 'CRM/Export/BAO/Export.php', around 195 you'll find the following block of code:

Code: [Select]
       foreach( $ids as $keys => $values ) {
            if ( CRM_Utils_Array::value( 'greeting_type', $returnProperties ) ) {
                $greetingTypeValue = CRM_Core_DAO::getFieldValue(
                                                                 'CRM_Contact_DAO_Contact',
                                                                 $values,
                                                                 'greeting_type_id'
                                                                );
                if ( $greetingTypeValue == 4 ) {
                    $returnProperties['custom_greeting'] = 1;
                }
            }
        }

That code seems to work just dandy for Contact Export, but not at all for Contribution Export. Due to time constraints, we simply forced 'custom_greeting' into an active state by doing the following:

1. Comment out the code displayed above.
2. Copy the the following line to just below the block of code displayed above:
Code: [Select]
$returnProperties['custom_greeting'] = 1;
Now the 'custom_greeting' column will always be available in the CSV for both Contact and Contribution Exports.

As for tags, we employed a similar solution: Just below '$returnProperties['custom_greeting'] = 1;' we added $returnProperties['tags'] = 1;'


Code: [Select]
       
//        foreach( $ids as $keys => $values ) {
//            if ( CRM_Utils_Array::value( 'greeting_type', $returnProperties ) ) {
//                $greetingTypeValue = CRM_Core_DAO::getFieldValue(
//                                                                 'CRM_Contact_DAO_Contact',
//                                                                 $values,
//                                                                 'greeting_type_id'
//                                                                );
//                if ( $greetingTypeValue == 4 ) {
//                    $returnProperties['custom_greeting'] = 1;
//                }
//            }
//        }
        $returnProperties['custom_greeting'] = 1;
        $returnProperties['tags'] = 1;


I know that this is not the 'proper' way to solve the problem, however it was fast and easy to implement and solved the underlying business requirement that we had in record time.


Thanks,
- Jordan
« Last Edit: October 09, 2009, 07:47:04 am by jbachmann »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CiviContribute - Export: Map Contact Tags and Contact Custom Greeting

This forum was archived on 2017-11-26.