You are here

function rules_action_new_referral in User Referral 7

Rules action callback

1 string reference to 'rules_action_new_referral'
referral_rules_action_info in ./referral.rules.inc
Implements hook_rules_action_info().

File

./referral.rules.inc, line 223
Rules integration

Code

function rules_action_new_referral($target_user, $ref_user, $host = 'system', $uri = 'system') {
  $result = db_query_range('SELECT referral_uid FROM {referral} WHERE uid = :uid', 0, 1, array(
    'uid' => $user->uid,
  ))
    ->fetchField();
  if (!$result) {
    $query = db_insert('referral')
      ->fields(array(
      'uid' => $target_user->uid,
      'referral_uid' => $ref_user->uid,
      'created' => time(),
      'host' => $host,
      'http_referer' => $uri,
    ))
      ->execute();
    if (!$query) {
      watchdog('rules', 'INSERT of referral data failed.', array(), WATCHDOG_ERROR);
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}