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 CiviMember (Moderator: Deepak Srivastava) »
  • Gift Memberships - update?
Pages: [1] 2 3

Author Topic: Gift Memberships - update?  (Read 16003 times)

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Gift Memberships - update?
August 31, 2011, 01:55:24 pm
Hi all,

I've come across several posts of people looking to implement Gift Memberships functionality. Eg:
(2009) http://forum.civicrm.org/index.php/topic,8590.msg37124.html#msg37124

If anyone has any updates / new thoughts on this topic - especially on how to go about implementing this in a sustainable way - I would appreciate it if you would share them.

Thanks,

-- Karin

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Re: Gift Memberships - update?
September 01, 2011, 04:44:17 pm
Ok, I've been digging in a bit, and I think I'm looking at trying to create a:

function buildOnBehalfIndividual()
in CRM/Contribute/Form/Contribution/Main.php

Right track?

-- Karin


EdP

  • I post frequently
  • ***
  • Posts: 260
  • Karma: 7
  • CiviCRM version: 4.4
  • CMS version: Joomla 2.5.x
Re: Gift Memberships - update?
September 02, 2011, 12:00:17 am
That's what I was directed to at the time. I never found the time to do it, but if you do manage it, let me know. I would still find it useful.

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: Gift Memberships - update?
September 02, 2011, 06:10:22 am

yes, seems like the right track

but might be worth it to write a half page specification on what you are doing and how it will work before u start digging into the code :)

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

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Re: Gift Memberships - update?
September 02, 2011, 10:22:51 am
Thanks, how about:

OnBehalfOrganization on a contribution page that is configured to purchase a Membership does exactly what you need to do an Individual Gift Membership, ie:

- it creates a contact record for recipient of gift membership
- it adds a contribution to that new contact record
- it adds a membership to that new contact record
- it emails transaction receipts to both the contact purchasing the gift membership as well as the recipient of the gift membership

except for [edits required]:
1. need to modify some ts and need collect some different form data (eg for Individual: First Name and Last Name).
[I've looked at this and started making some edits. Thus far this appears quite straightforward]

2. need to create a contact record of type Individual as opposed to of type Organization
[looking at this now -> trying to figure out where exactly in the code related to OnBehalfOrganization functionality the contact record is created.

That's where I'm at thus far. Still on right track?

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Re: Gift Memberships - update?
September 12, 2011, 01:09:41 pm
Ok, I've got this working on D6/3.3.6 [the charity that asked me about Gift Memberships is on 3.3.6]. It will take me some time to generalize/clean-up the functions I've added though. Would the 3.3.6 details be useful to anyone? Sorry, I have not looked at 4.x - I'm scrambling for time this week/month. Will try to find some more.

Does anyone know why the case statements in:

buildOnBehalfForm
in CRM/Contact/BAO/Contact/Utils.php

for 'Organization', 'Household' and default ('Individual')

already existed?

I've created a buildOnBehalfFormIND (and left buildOnBehalfForm as is) using the "don't understand it -> don't touch it" rule of thumb, but I'm curious to know if that part of the code was already being used or was perhaps a first step towards making the OnBehalf functionality Contact Type dependent?

Regards,

-- Karin





mathocracy

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: 6.26
  • MySQL version: 5.5.x
  • PHP version: 5.3.10
Re: Gift Memberships - update?
October 13, 2011, 09:13:53 am
Hi Karin,

I would very much like to learn all I can about integrating gift memberships into CiviCRM. Please send me a message with more information.

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Re: Gift Memberships - update?
October 13, 2011, 10:36:30 am
I've been working on generalizing this - I now have separate onBehalfOrganization and onBehalfIndividual functionality - except at the front-ed: in the Contribution Page configuration -> Title and Settings [the charity I did this for has a lot of Individuals paying on behalf of someone else, and organizations paying for an individual but couldn't think of any example the other way].

To make what I have done more useful to others, I need to do is figure out how to Edit the Contribution Page -> Title and Settings page - so that it can be configured to be either a onBehalfOrganization OR onBehalfIndividual. If anyone has any doc/tips on that - please let me know.

-- Karin

mathocracy

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: 6.26
  • MySQL version: 5.5.x
  • PHP version: 5.3.10
Re: Gift Memberships - update?
October 14, 2011, 07:40:18 am
I think the specific code that needs to be tweaked for the Settings page is in:

CRM/Contribute/Form/ContributionPage/Settings.php

Around line 104 I see the following code:

Code: [Select]
        // is on behalf of an organization ?
        $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), null, array('onclick' =>"showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);") );
        $options = array();
        $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Optional'), 1 );
        $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Required'), 2 );
        $this->addGroup($options, 'is_for_organization', ts('') );
        $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization'] );

I don't know what the back-end of this looks like, but I'm assuming you could start by adding another block for Individuals and turn both options into radio buttons so there is no conflict. I think you'd also need an 'On Behalf of" profile for Individuals as well.

Other relevant sections appear to include:

Line 181:
Code: [Select]
$params['is_for_organization']   = CRM_Utils_Array::value('is_organization', $params )
                                           ? CRM_Utils_Array::value('is_for_organization', $params, false)
                                           : 0;


CRM/Contribute/Form/ContributiongPage.php

Line 269:
Code: [Select]
         if (! isset($defaults['for_organization'])) {
            $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
        }

Line 284:
Code: [Select]
        if ( CRM_Utils_Array::value( 'is_for_organization', $defaults ) ) {
            $defaults['is_organization'] = 1;
        } else {
            $defaults['is_for_organization'] = 1;
        }

CRM/Form/ContributionBase.php
Line 644:

Code: [Select]
       if ( CRM_Utils_Array::value( 'hidden_onbehalf_profile', $this->_params ) ) {
            $this->assign('onBehalfName',    $this->_params['organization_name']);
            $locTypeId = array_keys( $this->_params['onbehalf_location']['email'] );
            $this->assign('onBehalfEmail',   $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']);
        }

CRM/Contribute/Form/Contribution/OnBehalfOf.php looks important too.

I'm not super experienced with hacking the guts of CiviCRM, but it looks like corresponding Contribution areas in BAO/DAO would need to be modified too.

Would you be able to share the code you have so far?
« Last Edit: October 14, 2011, 08:00:32 am by mathocracy »

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Re: Gift Memberships - update?
October 15, 2011, 09:51:54 am
Absolutely. If you have time to work on the front end that would be great. I'll Email you my civicrm_local.tar (not allowed here). I've clearly marked my edits with my initials KG - but if you have any questions please let me know. When you look at the code it may be useful to see what it looks like: http://www.lllc.ca/civicrm/contribute/transact?reset=1&id=10&action=preview

So -again- it's all working and functional from here -> but only b/c I am borrowing the id for OnBehalfOrganization and am using that to do OnBehalfIndividual things instead - I just rewrote the text on the Settings page (attached: .png). 

-- Karin

mathocracy

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: 6.26
  • MySQL version: 5.5.x
  • PHP version: 5.3.10
Re: Gift Memberships - update?
October 17, 2011, 07:09:53 am
Thanks Karin! Will dig through this.

mathocracy

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: 6.26
  • MySQL version: 5.5.x
  • PHP version: 5.3.10
Re: Gift Memberships - update?
October 17, 2011, 11:59:29 am
Karin.

OK I scanned your code and some of the CiviCRM code and have some more thoughts on how to proceed (below). If we're really creating a separate On Behalf of Individual functionality I think we might need to edit/add more code (in addition to what you sent me). Let me know what you think.

I think I found everything that references on-behalf-of functionality, but it's possible I overlooked something.

CRM/Contact/BAO/Contact/Utils.php
Include your function for adding on behalf of an individual, or modify existing buildOnBehalfForm

CRM/Contribute/BAO/ContributionPage.php
Add conditional for individual:
Code: [Select]
        if ( CRM_Utils_Array::value( 'is_for_organization', $values ) ) {
            if ( CRM_Utils_Array::value( 'membership_id', $values ) ) {
                $params['onbehalf_profile'] = array( array( 'membership_id', '=', $values['membership_id'], 0, 0 ) );
            } else if ( CRM_Utils_Array::value( 'contribution_id', $values ) ) {
                $params['onbehalf_profile'] = array( array( 'contribution_id', '=', $values['contribution_id'], 0, 0 ) );
            }
        }

CRM/Contribute/BAO/Contribution.php
Modify getOnbehalfIds to consider individuals in addition to organizations. Add another if-then block for case where on behalf contribution source is individual and contributor is individual. Ensure proper relationship between two individuals is accounted for?

Code: [Select]
    function getOnbehalfIds( $contributionId, $contributorId = null ) {
       
        $ids = array();
       
        if ( !$contributionId ) {
            return $ids;
        }
       
        // fetch contributor id if null
        if ( !$contributorId ) {
            require_once 'CRM/Core/DAO.php';
            $contributorId = CRM_Core_DAO::getFieldValue( 'CRM_Contribute_DAO_Contribution',
                                                          $contributionId, 'contact_id' );
        }
       
        require_once 'CRM/Core/PseudoConstant.php';
        $activityTypeIds = CRM_Core_PseudoConstant::activityType( true, false, false, 'name' );
        $activityTypeId  = array_search( 'Contribution', $activityTypeIds );
       
        if ( $activityTypeId && $contributorId ) {
            $activityQuery  = "
SELECT source_contact_id
  FROM civicrm_activity
 WHERE activity_type_id   = %1
   AND source_record_id   = %2";
           
            $params = array( 1 => array( $activityTypeId, 'Integer' ),
                             2 => array( $contributionId, 'Integer' ) );
           
            $sourceContactId = CRM_Core_DAO::singleValueQuery( $activityQuery , $params );
           
            // for on behalf contribution source is individual and contributor is organization
            if ( $sourceContactId && $sourceContactId != $contributorId ) {
                $relationshipTypeIds = CRM_Core_PseudoConstant::relationshipType( 'name' );
                // get rel type id for employee of relation
                foreach ( $relationshipTypeIds as $id => $typeVals ) {
                    if (   $typeVals['name_a_b'] == 'Employee of'  ) {
                        $relationshipTypeId = $id;
                        break;
                    }
                }
               
                require_once 'CRM/Contact/DAO/Relationship.php';
                $rel = new CRM_Contact_DAO_Relationship();
                $rel->relationship_type_id = $relationshipTypeId;
                $rel->contact_id_a         = $sourceContactId;
                $rel->contact_id_b         = $contributorId;
                if ( $rel->find(true) ) {
                    $ids['individual_id']   = $rel->contact_id_a;
                    $ids['organization_id'] = $rel->contact_id_b;
                }
            }
        }
       
        return $ids;
    }

CRM/Contribute/DAO/ContributionPage.php
Add corresponding variables for individuals

Code: [Select]
    /**
     * if true, signup is done on behalf of an organization
     *
     * @var boolean
     */
    public $is_for_organization;
    /**
     * This text field is shown when is_for_organization is checked. For example - I am contributing on behalf on an organization.
     *
     * @var text
     */
    public $for_organization;
    /**
     * if true, receipt is automatically emailed to contact on success
     *
     * @var boolean
     */

Code: [Select]
'is_for_organization' => array(
                    'name' => 'is_for_organization',
                    'type' => CRM_Utils_Type::T_BOOLEAN,
                ) ,
                'for_organization' => array(
                    'name' => 'for_organization',
                    'type' => CRM_Utils_Type::T_TEXT,
                    'title' => ts('On Behalf Of Organization') ,
                    'rows' => 2,
                    'cols' => 50,


CRM/Contribute/Form/Contribution/Confirm.php
There are several blocks of code here that appear to handle onbehalf-of-organization info. Perhaps we can make these conditional depending on if onbehalfindividual is chosen vs onbehalforganization? Can build off your existing code.

CRM/Contribute/Form/Contribution/Main.php
Build off your code. If we force use to choose on behalf of organization OR individual (but not both) on settings page then perhaps we can use conditionals here as well

CRM/Contribute/Form/Contribution/OnBehalfOf.php
preProcess and buildQuickForm function has to be expanded to consider onbehalf of individuals?

CRM/Contribute/Form/Contribution/ThankYou.php
Add conditional statement so $profileId is either from organization or individual?
Code: [Select]
$profileId = CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name' );

Code: [Select]
$fieldTypes = array( 'Contact', 'Organization' );

CRM/Contribute/Form/Contribution/ContributionBase.php
Also consider individual name???
Code: [Select]
if ( CRM_Utils_Array::value( 'hidden_onbehalf_profile', $this->_params ) ) {
            $this->assign('onBehalfName',    $this->_params['organization_name']);
            $locTypeId = array_keys( $this->_params['onbehalf_location']['email'] );
            $this->assign('onBehalfEmail',   $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']);
        }

CRM/Contribute/Form/ContributionPage/Custom.php
Include consideration for individual:
Code: [Select]
        $profileId       = CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name' );
       
        $excludeTypes    = array( 'Organization', 'Household', 'Participant', 'Activity' );

CRM/Contribute/Form/ContributionPage/Settings.php
I suggest we duplicate 'is on behalf of organization' block and make it an either-or choice between 'on behalf of org' and 'on behalf of indiv:

Code: [Select]
        // is on behalf of an organization ?
        $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), null, array('onclick' =>"showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);") );
        $options = array();
        $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Optional'), 1 );
        $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Required'), 2 );
        $this->addGroup($options, 'is_for_organization', ts('') );
        $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization'] );

Code: [Select]
  $params['is_for_organization']   = CRM_Utils_Array::value('is_organization', $params )
                                           ? CRM_Utils_Array::value('is_for_organization', $params, false)
                                           : 0;

CRM/Contribute/Form/ContributionPage.php
Add corresponding defaults for individual:

Code: [Select]
        if (! isset($defaults['for_organization'])) {
            $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
        }

Code: [Select]
        if ( CRM_Utils_Array::value( 'is_for_organization', $defaults ) ) {
            $defaults['is_organization'] = 1;
        } else {
            $defaults['is_for_organization'] = 1;
        }

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Re: Gift Memberships - update?
October 18, 2011, 09:20:38 am
Hi Joshua,

Ok, looks like you're serious about getting gift memberships implemented :). Shall we touch base off forum to work on this together and then back to forum when we have worked this out or when we get stuck [which ever comes first]?

-- Karin

mathocracy

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: 6.26
  • MySQL version: 5.5.x
  • PHP version: 5.3.10
Re: Gift Memberships - update?
October 19, 2011, 06:27:38 am
Certainly! :)

Eliet Henderson

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 4
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 7
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Gift Memberships - update?
November 16, 2011, 03:15:20 pm

Hello industrious gift membership hackers. Have you made further progress on this functionality? It's very exciting!

Pages: [1] 2 3
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Gift Memberships - update?

This forum was archived on 2017-11-26.