You are here

function download_count_block in Download Count 6.2

Implementation of hook_block().

File

./download_count.module, line 228
Tracks file downloads for files stored in the drupal files table using the private files setting or custom private filefield.

Code

function download_count_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks['files']['info'] = t('Top Downloaded Files');
      $blocks['downloaders']['info'] = t('Top Downloaders');
      $blocks['users']['info'] = t('Top Downloaded Users');
      $blocks['nodes']['info'] = t('Top Downloaded Nodes');
      return $blocks;
    case 'configure':
      $form['download_count_' . $delta . '_block_limit'] = array(
        '#type' => 'textfield',
        '#title' => t('Number of items to display'),
        '#size' => 5,
        '#default_value' => variable_get('download_count_' . $delta . '_block_limit', 10),
      );
      $form['download_count_' . $delta . '_show_size'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display aggregated filesize'),
        '#default_value' => variable_get('download_count_' . $delta . '_show_size', 0),
      );
      $form['download_count_' . $delta . '_show_last'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display last download datetime'),
        '#default_value' => variable_get('download_count_' . $delta . '_show_last', 0),
      );
      if ($delta == 'files') {
        $form['download_count_files_file_links'] = array(
          '#type' => 'checkbox',
          '#title' => t('Display files names as links (based on permissions).'),
          '#default_value' => variable_get('download_count_files_file_links', 1),
        );
      }
      return $form;
    case 'save':
      variable_set('download_count_' . $delta . '_block_limit', $edit['download_count_' . $delta . '_block_limit']);
      variable_set('download_count_' . $delta . '_show_size', $edit['download_count_' . $delta . '_show_size']);
      variable_set('download_count_' . $delta . '_show_last', $edit['download_count_' . $delta . '_show_last']);
      $delta == 'files' ? variable_set('download_count_files_file_links', $edit['download_count_files_file_links']) : NULL;
      break;
    case 'view':
      switch ($delta) {
        case 'files':
          $blocks['subject'] = t('Top Downloaded Files');
          $blocks['content'] = _download_count_block_contents('files');
          break;
        case 'downloaders':
          $blocks['subject'] = t('Top Downloaders');
          $blocks['content'] = _download_count_block_contents('downloaders');
          break;
        case 'users':
          $blocks['subject'] = t('Top Downloaded Users');
          $blocks['content'] = _download_count_block_contents('users');
          break;
        case 'nodes':
          $blocks['subject'] = t('Top Downloaded Nodes');
          $blocks['content'] = _download_count_block_contents('nodes');
          break;
      }
      return $blocks;
  }
}