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) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Feedback Requested - First stab at an extension to define onBehalf relationship
Pages: [1]

Author Topic: Feedback Requested - First stab at an extension to define onBehalf relationship  (Read 1950 times)

glovadev

  • I’m new here
  • *
  • Posts: 1
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.x
  • MySQL version: 5.1.67
  • PHP version: 5.3.23
Feedback Requested - First stab at an extension to define onBehalf relationship
June 06, 2013, 11:29:32 am
I am doing a POC for a service organization that has roughly 331 chapters.  If the POC pans out, we might be coming back here for help so I figured I would try and contribute first. Quid pro quo, so to speak.

The parent organization has a number of yearly fund raisers and each chapter competes to raise the most money bu directly donating or having chapter members,relatives, associates, etc donate on behalf of the chapter. None of the chapters have employees so I am taking a stab at writing an extension that will allow the contribution admins to set the type of on behalf relationship. Thing is, I have been stepping through the code and *think* this might work but before I complete it, and contribute it should there be interest, I want to make sure I am not going to cause any issues.

Basically, I am using an option group and the civicrm_pre hook to intercept the request and check to see if there is an alternate relationship defined in the option group for that contribution page. Here is the code I have so far. It is not completed as I am unsure if this will cause other issues...

function onbehalfof_civicrm_pre( $op, $objectName, $id, &$params ) {
    switch ($objectName) {
    case 'Relationship';
        // check if this is a form post by looking for quick form key
        if ( isset($_POST['qfKey']) ) {
            $qfkey = $_POST['qfKey'];
            // set up the name of the contribution page key in the CIVICRM Session array
            $contributeArray = 'CRM_Contribute_Controller_Contribution_' . $qfkey;
            // check to see if this relationship is being created by a contribution form
            if ( isset($_SESSION['CiviCRM'][$contributeArray]['id']) ) {
                // get the contribution page id
                $contributionPageId=$_SESSION['CiviCRM'][$contributeArray]['id'];
                // API get the option group id that has the relationship types in it
                $apiQueryParams = array(
                    'name' => 'contribution_org_relationship_override',
                    'version' => 3,
                );
                $result = civicrm_api( 'option_group','get',$apiQueryParams);
                // if the option group exists
                if ( $result['is_error'] == 0 ) {
                    // API get the values
                    $optionGroupId = $result['id'];
                    $apiQueryParams = array(
                        'option_group_id' => $optionGroupId,
                        'version' => 3,
                    );
                    $optionValuesResult = civicrm_api( 'option_value','get',$apiQueryParams );
                    // if values exist, loop through them and look for a value with the 'name' field = to the page id
                    if ( $optionValuesResult['is_error'] == 0 ) {
                        foreach ( $optionValuesResult['values'] as $optValue ) {
                            // check to see if the page id = name and if so set the params
                            if ( $optValue['is_active'] == 1 && $optValue['name'] == $contributeArray]['id'] ) {
                                // API get relationship type id
                               // set the <typeId>_a_b to the $params['relationship_type_id']
                               // continue
                            }
                        }
                    }
                }
            }
        }
       
        break;
    default:
      // nothing to do
  }
}

I think I should also be checking to make sure the onbehalf stuff exists but have not done that yet. And should probably consider evaluating the related contacts so the Employer Of field does not get filled in?
Thanks in advance.
AJ

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Feedback Requested - First stab at an extension to define onBehalf relationship

This forum was archived on 2017-11-26.