Is there a simple way to display the users post count post per category? eg. 6 blogs, 2 forum topics, 3 news entries.

Comments

liam mcdermott’s picture

Title: post count per content type » Display post count per content type
Version: 5.x-1.0-beta4 » 6.x-1.x-dev
Category: support » feature

Sorry for not getting to this sooner. There currently is no way to do this, but I am interested in adding it. I'm not adding new features to the Drupal 5 version, however, so this will work on Drupal 6+ only.

liam mcdermott’s picture

Marked: #311207: Link to Posts and Add Blog posts count as a duplicate of this.

Note: we should also provide a view which takes the content type as an argument, and link the value/label to the View. For example: Dave is browsing the forums and wants to see a list of blog posts, or forum topics, created by Bob. Dave should be able to click on the statistic value/label (e.g. forum posts: 100), next to Bob's name in the forums, and see a View listing the nodes of the content type Bob just clicked.

CompShack’s picture

we should also provide a view which takes the content type as an argument, and link the value/label to the View

PERFECT!

blup’s picture

Is there any progress in this feature?

liam mcdermott’s picture

Is there any progress in this feature?

Unfortunately not. :(

Unless someone comes up with a patch or some cash (4 hours @ €50/hour = €200) to pay for this to be coded and tested, I doubt I'll get around to it before I write the Drupal 7 version of this module. I'll gladly test/give guidance on any patches though.

neurovation.kiwi’s picture

Status: Active » Needs review
StatusFileSize
new10.37 KB

problem with posting - maybe a double post - sorry!

here comes a patch:

basicly introducing new statistics:

- post_count_comment (count of comments per user)
- post_count_type_'type' (count of posts per user and type)
i.e. post_count_type_blog, ...

haven't tested a lot yet.

gausarts’s picture

Subscribing. Thanks

ocamp’s picture

did anybody test the patch

a_c_m’s picture

Subscribe, will test in a week or so if no one else beats met too it.

neurovation.kiwi’s picture

StatusFileSize
new10.56 KB

Hi folks,

i did some more testing and here is a new patch (replacing #6).

cu
kiwi

liam mcdermott’s picture

Status: Needs review » Needs work

I'm really happy to see this feature coming down the line, great work neurovation.kiwi.

Unfortunately I can't get the patch to apply, am doing patch -p0 < user_stats.node_type_2.patch from the user_stats root directory. I even tried checking out User Stats from a day ago and two days ago, in case the two small revisions made today might have caused it to not apply. Are you using the HEAD or DRUPAL-6--1 branch? Unfortunately HEAD is horribly out of date, DRUPAL-6--1 is where all the work is happening.

So, unless I'm doing something obviously wrong, the patch needs a re-roll. I also have some comments on the contents of the patch (just from glancing over it):

  1. + * - post count per type (node_type or comment) should have a semi-colon on the end;
  2.      default:  
    +      // check if it is a possible query for node_type specific count
    +      if (substr($type, 0,  16) == "post_count_type_") {
    +        $data = _user_stats_get_stats_type($type, $uid);
    +        break;
    +      }
    

    The first word of the comment should be capitalised and a full stop added to the end;

  3. +function _user_stats_get_stats_type($type, $uid) {
    +  
    +  $data = 'n/a';
    

    Meh. Don't think we need that extra line-break in there, it should be:

    +function _user_stats_get_stats_type($type, $uid) {
    +  $data = 'n/a';
    
  4. +  // get available node_types
    +  $node_types = variable_get('user_stats_included_content_types', array());
    +  
    +  // type in question  
    

    Same as above: these comments need capitalisation and a full stop added to the end of the sentences. :)
    Also, do what with the ‘type in question’? This needs qualification.

  5. I'm thinking function _user_stats_get_stats_type($type, $uid) { should expect *just* a type, without the 'post_count_type_' prefix. That will mean we can remove the unclear line:
    +  // type in question  
    +  $node_type = substr($type, 16);
    
  6. +  // type in question  
    +  $node_type = substr($type, 16);
    +  if (in_array($node_type, $node_types)) {
    +    if (!user_stats_isset($type, $uid)) {
    +      user_stats_post_count_update('reset', $uid);
    +    }
    +    $query = db_query("SELECT value FROM {user_stats_values}
    +      WHERE name = '%s' AND uid = %d", $type, $uid);
    +    $data = db_result($query);
    +  }
    +  return $data;
    +}
    

    Minor niggle, but could you put an extra line break in before return $data? Thanks.

  7. +  return $data;
    +}
    +
    +
    +
    +
    +
     /**
      * Return data from the non-persistent User Stats cache. Single values
      * are returned according to type of statistic and unique user id.
    

    *gasp* extra line breaks! Please remove all but one of them, thanks. :)

  8.    if (!is_numeric($uid)) {
         trigger_error('UID is not a number.', E_USER_WARNING);
       }
    -
    +  
    +  
       static $user_stats_cache = array();
    

    Not sure how that extra line break snuck in there, but it too needs to be removed. Nuke it from orbit, it's the only way to be sure.

  9.        $values['login-count']            = check_plain(user_stats_get_stats('login_count', $uid));
    +      
    +      
    +      foreach (variable_get('user_stats_included_content_types', array()) as $type) {
    

    Could you delete the extra line break? Thanks!

  10. This:
         $tokens['user']['login-count']            = t("User's login count");
    +    foreach (variable_get('user_stats_included_content_types', array()) as $type) {
    +      $stat = 'post_count_type_' . $type;
    +      $val = 'post-count-type-' . $type;
    +      // @todo translate the type name
    +      $tokens['user'][$val] = t("User's post count for !type", array('!type' => $type));
    +    }
         return $tokens;
    

    is not consistent with this:

           $values['login-count']            = check_plain(user_stats_get_stats('login_count', $uid));
    +      
    +      
    +      foreach (variable_get('user_stats_included_content_types', array()) as $type) {
    +        $stat = 'post_count_type_' . $type;
    +        $val = 'post-count-type-' . $type;
    +        $values[$val] = check_plain(user_stats_get-stats($stat, $uid));
    +      }
    +      
           return $values;
    

    There should be one line break before and after each foreach loop.

    Also, I'm not sure if we need to translate the type name, it's going to be whatever the admin enters into the database isn't it? I'm not great at the translation side of things.

  11. + * @param $type optional
    + *   which node type should be operated on 
    

    The first letter of the first word should be capitalised and a full stop added to the end of the sentence. :)

  12. +  
    +  $name = 'post_count';
    +  if ($type) {
    +    $name .= '_' . $type;
    +  }
    +  if ($type == 'comment') {
    +    $name = 'post_count_comment';
    +  }
    

    This is confusing, can you please add an inline comment to the code explaining why we do this?

  13. +        // reset all to 0
    +        foreach (variable_get('user_stats_included_content_types', array()) as $type) {
    +          user_stats_cache_set('post_count_type_' . $type, $uid, 0);
    +        }
    +        // update the existing ones
    

    The usual: the first letter of the first word should be capitalised and a full stop added to the end of the sentence (for both comments).

  14. +        while( $row = db_fetch_array($result)) {
    

    Control structures should have one space between the statement and the opening parenthesis, with no spaces between the opening parenthesis and condition. So, this should be:

    +        while ($row = db_fetch_array($result)) {
    

This might seem like a lot, but it's pretty-much all code style issues, easily fixed (although I haven't been able to test whether it actually works or not yet). Great stuff. :)

codevoice’s picture

Subscribe

BeaPower’s picture

sub!

neurovation.kiwi’s picture

Hi Liam from #11

don't get me wrong - i'm open to criticism.

but if you took the time to point out all that stuff - why don't you just created a new patch (or changed the one i provided) ??

I'm just curious.

liam mcdermott’s picture

but if you took the time to point out all that stuff - why don't you just created a new patch (or changed the one i provided) ??

Writing all that didn't actually take much time, nowhere near as long as writing a patch myself. Since I didn't have the time to write a patch myself, I thought the least I could do was to review yours.

bflora’s picture

Subscribe. Would be very happy to see this added to User Stats.

madjr’s picture

sub
this would be very cool

BeaPower’s picture

What is the status of this?

gregoiresan’s picture

I guess it still needs work.

As a none expert, I'm nor sure what exactly does the patch #10 ??

Regarding the issues list, this feature would be greatly appreciated by the community. Anyone knows how to patch it ?

glitz’s picture

sub

BeaPower’s picture

any updates?

liam mcdermott’s picture

neurovation.kiwi did some good work in #10, but I couldn't get his patch to apply to User Stats. Either neurovation.kiwi, someone else will pick this up, or I'll get to it at some point.

Killpill’s picture

I'm pretty interested but am baffled by the complexity of adding this feature into the module.

A simple query like:


$sql = "SELECT type, COUNT(*) count FROM {node} GROUP BY type";

Would count the number of posts and group them by type. So I'm guessing the module itself needs an overhaul to implement this.

I do not know anything about caching or Views integration, so writing a patch would require me to learn quite a lot. I guess I should know that stuff anyways, since I mostly write my own functions when I need something.

Still much demand for a patch?

AntiNSA’s picture

Id like this patch