Support for tokens

5 replies [Last post]
aidan
Offline
Joined: 10/28/2009
Status: 
Answered

It would be nice to use the Token module for all emails generated by the affiliate system, this would make the emails a lot more flexable and would unify the admin page.

A tutorial on getting started is here, http://drupal.org/node/307140

If you need a working example, you can take a look at the regcode module on d.o

Leighton Whiting
Offline
Joined: 06/02/2009
Aidan, The modules already

Aidan,
The modules already provide their own token system. What would the benefits of integrating the Tokens (and introducing another dependency) be? Is it so that you can use hook_token_values to change the tokens?

Sincerely,
Leighton Whiting

aidan
Offline
Joined: 10/28/2009
Hi, My client needs to be

Hi,

My client needs to be able to send emails in the format "Hi !firstname, ...", which means I need access to the proflie values.

I also need to be able to send them a link to their affiliate manager page, which lives at /user/x/affiliates, which depends on the userid meaning I can't hardcode it.

The token module allows anyone to substitute in tokens, which is really handy ... it also provides a nice token replacement helper to show all of the available tokens.

I also provide some additional tokens for other emails the system generates:

<?php

/**
 * Implements hook_token_list().
 */
function x_token_list($type = 'site') {
  $tokens = array();
 
  if ($type === 'profile') {
    $tokens['affiliate']['affiliate_balance']        = t('The affiliates current balance.');
    $tokens['affiliate']['affiliate_ap_earnings']    = t('The affiliates earnings for the current accounting period.');
    $tokens['affiliate']['affiliate_total_earnings'] = t('The affiliates total earnings.');
  }
 
  return $tokens;
}

/**
 * Implements hook_token_values().
 */
function x_token_values($type, $object = NULL, $options = array()) {
  $tokens = array();
 
  if ($type === 'profile') {
    $account =& $object;     
    $since = variable_get('radar_affiliates_notifications_lastsent', 0);
    $tokens['affiliate_balance']        = number_format($account->af_balance, 2);
    $tokens['affiliate_ap_earnings']    = number_format(db_result(db_query('SELECT SUM(amount) FROM {ms_affiliates_history} WHERE date > %d AND amount > 0 AND uid = %d', $since, $account->uid)), 2);
    $tokens['affiliate_total_earnings'] = number_format(db_result(db_query('SELECT SUM(amount) FROM {ms_affiliates_history} WHERE amount > 0 AND uid = %d', $account->uid)), 2);
  }
 
  return $tokens;
}

?>

Leighton Whiting
Offline
Joined: 06/02/2009
Okay, I will put this on the

Okay, I will put this on the feature list for the next release, since tomorrow's release is already in feature lock.

Sincerely,
Leighton Whiting

Leighton Whiting
Offline
Joined: 06/02/2009
Actually, I have put in token

Actually, I have put in token support in this release. I set it up so that if you don't have Token installed, it will fall back on the old system.

Sincerely,
Leighton Whiting

aidan
Offline
Joined: 10/28/2009
Awesome, can't wait to see

Awesome, can't wait to see it! You're doing a great job

Twitter Feed