<?php
/**
* Implementation of hook_civicrm_tokens
*/
function callhooks_civicrm_tokens( &$tokens ) {
$tokens['contribution'] = array('contribution.last_total_amount', 'contribution.last_receive_date', 'contribution.last_financial_type', 'contribution.last_trxn_id');
}
function callhooks_civicrm_tokenValues( &$values, &$contactIDs, $job = null, $tokens = array(), $context = null) {
// KG NOTES
// Example from Lobo: https://civicrm.org/node/480
if ( is_array( $contactIDs ) ) {
$contactIDString = implode( ',', array_values( $contactIDs ) );
$single = false;
} else {
$contactIDString = "( $contactIDs )";
$single = true;
}
// Contribution tokens
$query = "
SELECT id, contact_id, financial_type_id, total_amount, receive_date, trxn_id
FROM civicrm_contribution
WHERE contact_id IN ( $contactIDString )
AND is_test = 0
ORDER BY receive_date DESC LIMIT 1
";
$dao = CRM_Core_DAO::executeQuery( $query );
while ( $dao->fetch( ) ) {
if ( $single ) {
$value =& $values;
} else {
if ( ! array_key_exists( $dao->contact_id, $values ) ) {
$values[$dao->contact_id] = array( );
}
$value =& $values[$dao->contact_id];
}
$value['contribution.last_total_amount'] = $dao->total_amount;
$value['contribution.last_receive_date'] = $dao->receive_date;
$value['contribution.last_financial_type'] = $dao->financial_type_id;
$value['contribution.last_trxn_id'] = $dao->trxn_id;
$test = 1;
}
}