tags:

views:

286

answers:

2

Modifying download_count module to include information about users who downloaded files. Want to show this info on users' profile pages.

Here's the code:

function download_count_user($op, &$edit, &$account, $caterory = NULL) {
  if ($op == 'view') 
  {

   $result = db_query("SELECT filename FROM file_downloads_users WHERE user_id = %d", $account->uid);

   while ($file_array = db_fetch_object($result)) {
      $file_str .= $file->filename . '<br/>';
   }

   $items['downloads'] = array(
    'title' => t('Files'),
    'value' => $file_str,
        'class' => 'member'
    );
    return array(t('Downloads')=>$items);  
  }

}

Doesn't give me any errors but doesn't show anything on My Account page either.

+2  A: 

You don't want to modify a module. Drupal is built very very carefully to avoid having to hack core or contrib. Unless of course you are contributing a patch back.

The right way is to build your own custom module to do this (that would require the user downloads module) and implement the hook almost exactly what you're doing here.

  1. The function is getting run (module enabled, var_dump ing or krumo'ing causes output?, cache cleared)
  2. The way you are keying your variables is for Drupal 5.x and below. In D6, you add to $account->content. Which version of drupal are you using?

Check out user_user() (in user.module):

  $account->content['user_picture'] = array(
    '#value' => theme('user_picture', $account),
    '#weight' => -10,
  );
jskulski
i'm on 6 and i've tried adding to $account, didn't work
jskulski
Thanks! that worked
A: 
 $account->content['summary']['file_downloads'] =  array(
      '#type' => 'user_profile_item',
      '#title' => t('File Downloads'),
      '#value' => $file_str,
      '#weight' => 1
    );

related questions