Hello, as there is no documentation avaible, could anybody provide me with some basic steps to get something to show up in a template ?

Cheers

Comments

liam mcdermott’s picture

Assigned: placebo333 » liam mcdermott
Priority: Normal » Critical

Documentation will be written, am just a bit busy at the moment. To get you started:

  1. Enable the module.
  2. In your node-forum.tpl.php template, enter this:
    print user_stats_get_stats('post_count', $node->uid);
  3. To get post counts etc. into comments, add the following to comment.tpl.php :
    print user_stats_get_stats('post_count', $comment->uid);
  4. Logged in as admin: have a look at a forum topic!
  5. There are two permissions you'll need to set for normal users to be able to see statistics: 'View IP addresses' and 'View statistics'. Permissions are in the usual spot for Drupal, Administer -> User management -> Access control.

If you want something other than post count, just enter another call to user_stats_get_stats() replacing 'post_count' with one of the following:

  • 'reg_days'
  • 'join_date'
  • 'login_days'
  • 'last_post'
  • 'ip_address'
  • 'online'

There's also the workflow-ng integration, that's useful if you want to change the users role after they've written a number of posts, or been a member for a number of days. I'll explain more of that if required.

liam mcdermott’s picture

Sorry, this was a double-post. Drupal seems to be overzealously caching so replies may not appear immediately.

Don't submit stuff again if it doesn't appear after you hit 'Post comment', it's just the cache being slow, wait 5–15 minutes. :)

nainainai’s picture

Too bad it count every post count only if there is a way to make it only count for the forum post.

tannerjfco’s picture

I'm a little confused on the aspect of the workflow-ng integration. I've enabled the module but I don't see how I can configure a new workflow in workflow-ng based on user stats options.

I'd basically like to use this in conjunction with workflow-ng to show a page to users on their first time logging in, is that something user stats can help with?

liam mcdermott’s picture

Too bad it count every post count only if there is a way to make it only count for the forum post.

Hi there nainainai, this is not the way to get a new feature into this project. This is the discussion on the topic of documentation, if you have a feature request (and yours seems like a good idea) please submit it as a new bug using the 'Request new feature' link from the project front page. :)

I am busy--not to mention strapped for cash--at the moment, so will probably not be able to work on any new features for the next couple of months. I am available for paid Drupal work, if you need this urgently.

I'm a little confused on the aspect of the workflow-ng integration. I've enabled the module but I don't see how I can configure a new workflow in workflow-ng based on user stats options.

Now this is on-topic. :)

Everything user_stats provides is added automagically to the workflow-ng user interface. As you probably know, that's under: Administer -> Site building -> Workflow-ng When selecting 'Add a new configuration', you'll see some extra events that are provided by user_stats, you'll also notice some extra conditions too.

user_stats and workflow-ng cannot tell you if a user is logging in for the first time, unfortunately. What they can tell you is:

  • how many days since the user signed-up;
  • how many posts the user has;

Would one of these offer a suitable compromise? For example, you could redirect the user to a special welcome page if they have 0 posts and their account was created in the last 10 days. I like the idea of having a 'first_login' feature though, if you need this feature would you mind creating a feature request? As mentioned above, am a little strapped for cash at the moment, but I am available for paid work if it's a priority.

I should get some documentation written before adding any new features though! :D

*** EDIT ***
Just a quick thought, Tannerjf. Have you looked at Login destination? That may be able to do what you need.

placebo333’s picture

cheers for the info, got it running finally :)

tannerjfco’s picture

Liam, thanks for the response. The alternatives you suggested could possibly work, however I'm just not seeing those conditions listed in workflow-ng. Am I missing something here?

liam mcdermott’s picture

Maybe a screenie will help. Can you see these options under workflow-ng's 'Add a new configuration' screen? These are what you'd use, I didn't post the exact configuration names above, more an explanation of what can be done. :)

Hope this helps.

liam mcdermott’s picture

I'd basically like to use this in conjunction with workflow-ng to show a page to users on their first time logging in, is that something user stats can help with?

Just thought of a way to do this, you don't actually need user_stats. I'll export the workflow-ng configurations here, hopefully you should be able to use them by pasting them, one-by-one, into the Import page.

Firstly, this adds the 'New user' role to members when they sign up (see at the bottom of this is a roles array, you'll need to change the '1000059' to the id of the role to add when the user signs up in your system):

array (
  'cfg_9' => 
  array (
    '#type' => 'configuration',
    '#altered' => false,
    '#event' => 'user_insert',
    '#label' => 'Add role on signup',
    '#active' => 1,
    '#module' => 'workflow-ng',
    0 => 
    array (
      '#type' => 'action',
      '#name' => 'workflow_ng_action_user_addrole',
      '#argument map' => 
      array (
        'account' => 'user',
      ),
      '#settings' => 
      array (
        'roles' => 
        array (
          0 => 1000059,
        ),
      ),
    ),
    '#name' => 'cfg_9',
  ),
)

The next configuration is fired when a user logs in. If they have the 'New user' role, we remove it and redirect them to a page:

array (
  'cfg_10' => 
  array (
    '#type' => 'configuration',
    '#altered' => false,
    '#event' => 'user_login',
    '#label' => 'Remove New user role then redirect',
    '#active' => 1,
    '#module' => 'workflow-ng',
    0 => 
    array (
      '#type' => 'action',
      '#name' => 'workflow_ng_action_drupal_goto',
      '#settings' => 
      array (
        'path' => 'newuserpage',
        'query' => '',
        'fragment' => '',
        'force' => 1,
        'path_args' => 
        array (
        ),
      ),
      '#label' => 'Page redirect to New user page',
    ),
    1 => 
    array (
      '#type' => 'action',
      '#name' => 'workflow_ng_action_user_removerole',
      '#argument map' => 
      array (
        'account' => 'user',
      ),
      '#settings' => 
      array (
        'roles' => 
        array (
          0 => 1000059,
        ),
      ),
      '#label' => 'Remove New user role',
    ),
    2 => 
    array (
      '#type' => 'condition',
      '#name' => 'workflow_ng_condition_user_hasrole',
      '#argument map' => 
      array (
        'account' => 'user',
      ),
      '#settings' => 
      array (
        'roles' => 
        array (
          0 => 1000059,
        ),
        'operation' => 'OR',
      ),
    ),
    '#name' => 'cfg_10',
  ),
)

Again, you'll probably need to change the role arrays so the '1000059' matches whatever 'New user' role you're assigning. Hope this makes sense.

tannerjfco’s picture

Makes sense, and looks like that will work. Thanks a lot! :)

liam mcdermott’s picture

Makes sense, and looks like that will work. Thanks a lot!

Glad to hear it. Good idea too, might use that configuration myself: thanks for the idea! :)

cs8c’s picture

This module doesn't work as advertised above (post #1), I'm using this for the comment.tpl.php and the 'join date' gives me a huge string of numbers and 'online' and 'last_post' show nothing at all.

icecreamyou’s picture

How would I get these variables to show up on the user profile, if I'm not using Bio or Nodeprofile?

liam mcdermott’s picture

How would I get these variables to show up on the user profile, if I'm not using Bio or Nodeprofile?

This is possible with just the profile module. See under Administer -> User management -> Profiles, on that page is a list of options labelled 'Visibility'. Change that to one of the Public field options and save. Fixed. :)

CompShack’s picture

Reply to comment #12

Use the following custom date to format your date

print format_date(user_stats_get_stats('join_date', $comment->uid), 'custom', 'm/d/y');
Flying Drupalist’s picture

Thanks for the doc. The online code:
print user_stats_get_stats('online', $comment->uid);

only displays a single digit for online. How do I make it display an icon in place of the digit.

Thanks.

liam mcdermott’s picture

@#16 try this:

print (user_stats_get_stats('online', $comment->uid) ? 'Online' : 'Offline'); 
CompShack’s picture

Liam, I'm a programmer in real life - not in PHP though :( and i don't see "if statements" written this way that often. I'm all about making less and less lines of code and your approche above does just that. If it is true (value 1) then online, else offline.

Well done my friend.

Flying Drupalist’s picture

Thanks a bunch Liam, that works well. How do I get an image in there?

liam mcdermott’s picture

In reply to #19 I've got documentation already written, it'll be released shortly. This is taken from there:

<img alt="User is <?php print (user_stats_get_stats('online', $node->uid) ? 'online' : 'offline'); ?>" src="<?php print base_path() . path_to_theme() .'/'. (user_stats_get_stats('online', $node->uid) ? 'online.png' : 'offline.png'); ?>" />
i don't see "if statements" written this way that often. [...]
Well done my friend.

Well I'd love to claim credit for thinking that one up, but you'll see it in quite a few themes. Not recommended for modules though, as it reduces readability. :)

Flying Drupalist’s picture

Immensely helpful, thank you again.

Flying Drupalist’s picture

Anon users also see no post counts and an incorrect join date. The off/online thing works though.

liam mcdermott’s picture

I've written documentation for this module! Please have a look at it and raise support/bug/feature requests for anything you're trying to do that I've missed. :)

http://www.apaddedcell.com/an-introduction-user-stats-module-drupal

liam mcdermott’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.