You are here

function invite_stats_block in Invite 5.2

Same name and namespace in other branches
  1. 5 invite_stats.module \invite_stats_block()
  2. 6.2 invite_stats.module \invite_stats_block()

Implementation of hook_block().

File

./invite_stats.module, line 50
Displays some statistics about sent invitations.

Code

function invite_stats_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0] = array(
      'info' => t('Top inviters/User rank'),
    );
    return $blocks;
  }
  else {
    if ($op == 'view') {
      switch ($delta) {
        case 0:
          if (user_access('view invite statistics')) {
            if (arg(0) == 'user' && is_numeric(arg(1)) && ($account = user_load(array(
              'uid' => arg(1),
            )))) {
              $block = array(
                'subject' => t("@user's invite rank", array(
                  '@user' => $account->name,
                )),
                'content' => invite_stats_display_user_rank($account->uid),
              );
            }
            else {
              $block = array(
                'subject' => t('Top inviters'),
                'content' => invite_stats_display_top_inviters(),
              );
            }
          }
          break;
      }
      return $block;
    }
    else {
      if ($op == 'configure') {
        switch ($delta) {
          case 0:
            $form['invite_num_ranks'] = array(
              '#type' => 'textfield',
              '#title' => t('Number of inviters'),
              '#default_value' => variable_get('invite_num_ranks', 5),
              '#size' => 3,
              '#maxlength' => 3,
              '#description' => t('Show this number of inviters in the Top inviters and User rank blocks.'),
              '#required' => TRUE,
            );
            return $form;
        }
      }
      else {
        if ($op == 'save') {
          switch ($delta) {
            case 0:
              variable_set('invite_num_ranks', (int) $edit['invite_num_ranks']);
              break;
          }
        }
      }
    }
  }
}