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 CiviContribute (Moderator: Donald Lobo) »
  • CiviContribute and User points
Pages: [1]

Author Topic: CiviContribute and User points  (Read 2328 times)

8ballsaysiwin@gmail.com

  • Guest
CiviContribute and User points
August 15, 2009, 12:43:08 pm
Using the UserpointsAPI, I want to award users of my site points when they contribute. I want to award the donor points for donating and I would ideally like to award the owner of a Personal Fundraising page points each time someone donates.

I am pretty sure I can write the code (I am not very experienced though), but can someone direct me to where they think the best place to put it would be. Should I write a separate module (if so, what hooks should I use)? Or should I patch an existing page or pages?

Thanks
« Last Edit: August 15, 2009, 01:07:46 pm by 8ballsaysiwin »

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 and User points
August 15, 2009, 03:44:18 pm

implement the postProcess hook: http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification

on the CRM_Contribute_Form_Contribution_Confirm form. If you are using paypal standard or pay later you will need to also veriify that the payment did complete. You can also implement a hook_civicrm_post on the contribution object

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

8ballsaysiwin@gmail.com

  • Guest
Re: CiviContribute and User points
January 10, 2010, 12:19:51 pm
So I finally got around to this, posting here in case it helps anyone else.

I do still have a problem, the donate part works, but the PCP part doesn't seem to work. Does anyone know what variables I am calling incorrectly?

Any help would be much appreciated. Thanks.

Code: [Select]
<?php

// donorpoints.module
// Gives user appropriate level of points when user clicks SAVE button on a donate form.

// Writen by 8ballsaysiwin 2010

define('DONORPOINTS_DONATE', 'donorpoints_donate');
define('DONORPOINTS_DONATE_PCP', 'donorpoints_donate_pcp');

function 
donorpoints_help( ) {
    switch (
$section) {
    case 
'admin/modules#description':
        return 
t('Implements hooks for CiviCRM to customize the CSD Application.');
    default :
        return;
    }
}

function 
donorpoints_userpoints($op, $params = array()) {
  switch(
$op) {
    case 
'setting':
      
$group = 'donate';
      
$form[$group] = array(
        
'#type'        => 'fieldset',
        
'#collapsible' => TRUE,
        
'#collapsed'   => TRUE,
        
'#title'       => t('Points for donations'),
      );

$form[$group][DONORPOINTS_DONATE] = array(
'#type' => 'textfield',
'#title' => t('Points for each dollar donated (ie this value will be multiplied by dollars donated)'),
'#default_value' => variable_get(DONORPOINTS_DONATE, 1),
'#size' => 5,
'#maxlength' => 5,
);

$form[$group][DONORPOINTS_DONATE_PCP] = array(
'#type' => 'textfield',
'#title' => t('Points for each dollar raised through a users personal donation page (ie this value will be multiplied by dollars donated)'),
'#default_value' => variable_get(DONORPOINTS_DONATE_PCP, 1),
'#size' => 5,
'#maxlength' => 5,
);

      
$form[$group]['donorpoints_tid'] = array(
        
'#type'          => 'select',
        
'#title'         => t('Category'),
        
'#default_value' => variable_get(donorpoints_tid, 0),
        
'#options'       => userpoints_get_categories(),
        
'#description'   => t('Points will be assigned to this category. You can modify what categories are available by modifying the <a href="!url">Userpoints taxonomy</a>.', 
          array(
'!url' => url('admin/content/taxonomy/'. variable_get(USERPOINTS_CATEGORY_DEFAULT_VID, '')))),
      );
      
      return 
$form;
  }
}

function 
donorpoints_civicrm_postProcess( $formName, $form ) {
  if ( 
is_a( $form, 'CRM_Contribute_Form_Contribution_Confirm' ) ) {
$amount = $form->get( 'amount' );
$amount = round($amount);
$pointsMultiple = variable_get(DONORPOINTS_DONATE, 1);
$points = $amount * $pointsMultiple;
$pointsParams = array(
'points'      => $points,
'uid'         => $user->uid,
'entity_id' => $user->uid,
'entity_type' => 'user',
'operation' => 'donate',
'tid'         => variable_get('donorpoints_tid', 0),
'reference' => 'donorpoints_donate',
);
userpoints_userpointsapi($pointsParams);

if ($form->get( 'pcp_id' )) {

$pointsMultiple = variable_get(DONORPOINTS_DONATE_PCP, 1);
$points = $amount * $pointsMultiple;

$pcpId = $form->get( 'pcp_id' );
db_set_active('civicrm');
$pcpCiviCRMUserId = db_fetch_object(db_query("SELECT contact_id FROM {civiCRM_pcp} WHERE id = %d", $pcpId));
$pcpUid = db_fetch_object(db_query("SELECT uf_id FROM {civicrm_uf_match} WHERE contact_id = %d", $pcpCiviCRMUserId));
db_set_active('default');

$pointsParams = array(
'points'      => $points,
'uid'         => $pcpUid,
'entity_id' => $user->uid,
'entity_type' => 'user',
'operation' => 'pcp',
'tid'         => variable_get('donorpoints_tid', 0),
'reference' => 'donorpoints_donate_pcp',
);

userpoints_userpointsapi($pointsParams);
}
}
}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • CiviContribute and User points

This forum was archived on 2017-11-26.