You are here

function referral_user in User Referral 6

Same name and namespace in other branches
  1. 5 referral.module \referral_user()

File

./referral.module, line 200

Code

function referral_user($op, $array = NULL, $arg_user) {
  global $user;
  switch ($op) {
    case 'insert':

      // The user is being created, save the complete referral data
      _referral_user_save($arg_user->uid);
      break;
    case 'delete':

      // The user is being deleted
      _referral_user_delete($arg_user->uid);
      break;
    case 'load':

      // Add user's referral link to user object
      $arg_user->referral_link = "referral/" . _referral_uid2ref($arg_user->uid);
      break;
    case 'view':
      $referrals = array();
      $link = "referral/" . _referral_uid2ref($arg_user->uid);
      if (!variable_get(REFERRAL_DISPLAY_MODE, 0)) {
        if (user_access(REFERRAL_PERM_USE)) {
          if ($user->uid == $arg_user->uid) {

            // User is viewing own page, show referrals
            $referrals[] = array(
              '#title' => t('Your referral link'),
              '#value' => url($link, array(
                'query' => NULL,
                'fragment' => NULL,
                'absolute' => TRUE,
              )),
              '#type' => 'user_profile_item',
            );
            $referrals[] = array(
              '#title' => t('Referrals'),
              '#value' => l(t('View users you have referred'), 'referral/view'),
              '#type' => 'user_profile_item',
            );
          }
        }
      }
      if (!$user->uid) {
        $referrals[] = array(
          '#title' => t('Referral link'),
          '#value' => l(t('Register to this site using my referral link'), $link),
          '#type' => 'user_profile_item',
        );
        referral_set_cookie(arg(1));
      }
      if ($referrals) {
        $referrals['#type'] = 'user_profile_category';
        $referrals['#title'] = t('Referrals');
        $referrals['#weight'] = 10;
        $arg_user->content['Referrals'] = $referrals;

        // return array('Referrals' => $referrals); // obsolete from drupal 5
      }
      break;
  }
}