Counting forum topic posts by user

Hi, I'm looking to extend the group forum topic view by including the amount of posts a user has made inside the group.

I'm having a little trouble with it. I've seen how the vanilla groups plugin counts annotations for each forum topic, but I'm not sure how to tell elgg that I want to count annotations based on a specific user's guid.

Any help would be appreciated. I can follow simple instructions, but I'm not really a coder.

I've found the following:

 $count_annotations = $f->countAnnotations("group_topic_post");


.elgg_echo('groups:posts').": " . $count_annotations . "

Thanks in advance

  • Can anyone tell me why this doesn't work?

    $count = get_entities("object", "group_topic_post",page_owner_entity()->guid, "", 999999999, 0, true);




  • Ok, I've tried a lot of things. I'm currently looking at something like this.

    $post_owner = get_user($vars['entity']->owner_guid);

    $count = $post_owner->countAnnotations('group_topic_post');

    echo $count;

    But I still get the result of 0 no matter how many posts I make. Could it be that it won't display inside itself?

    Can anyone help me?

  • function list_entities_from_annotations($entity_type = "", $entity_subtype = "", $name = "", $value = "", $limit = 10, $owner_guid = 0, $group_guid = 0, $asc = false, $fullview = true, $viewtypetoggle = false) {

    maybe ?;-)

    discussions.php -->

        // Load Elgg engine
            require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
        // Display them
            $area2 = elgg_view_title(elgg_echo("groups:latestdiscussion"));
            $area2 .= list_entities_from_annotations("object", "groupforumtopic", "group_topic_post", "", 40, 0, 0, false, true);
            $body = elgg_view_layout("two_column_left_sidebar", '', $area2);

  • Thanks Dhrup, very kind of you.

  • @T,

    Hope that helps.. ;-) I have not done any heavy research into the code, but I do believe that that is the code you need to play with;-O Let me know when you get that working, cheers ;-)

  • Thanks Dhrup. Still struggling with it but getting closer. The code I'm using is the following:

    $postcount = get_entities_from_annotations($entity_type = "object", $entity_subtype = "groupforumtopic", $name = "group_topic_post", $value = "", $limit = 0, $owner_guid = "$post_owner", $group_guid = page_owner_entity()->guid, $asc = false, $fullview = false, $viewtypetoggle = true);

    $post_owner = get_user($vars['entity']->owner_guid)

    All of this is inside the groups/views/default/forum/topicposts.php file
    It is giving me a result now, but not quite what I was expecting. Here is some feedback:

    setting $limit to 0 counts every single discussion topic on the site. This disregards the following bit of code:

    $owner_guid = "$post_owner", $group_guid = page_owner_entity()->guid,

    And just counts all discussion topics no matter the group wuid or owner guid.
    setting $limit to 1 gives me a count of 0
    setting $limit to 2 gives me a count of 1

    At the moment I have started 2 topics in that group, but $postcount has never read as 2 yet.

    I will get this eventually.

    Sorry I should have mentioned what I'm looking to get is a combined count of both groupforumtopics and group_topic_posts for a single user inside a single group. I've added a little group rank as well which is working. Here is an example of the view:


  • If I understand correctly: what you want is a count of all annotations named "group_topic_post" which are annotating objects of subtype "groupforumtopic" in a certain group. Is that correct?

    Are you running 1.7+ by any chance?

  • That's essentially right. I'm not running 1.7+, I'm on 1.6.1 due to plugin requirements.

    ount of all annotations named "group_topic_post" which are annotating objects of subtype "groupforumtopic" by a certain user in a certain group.

    If user then goes and posts in another group that he is a member of, it will show a different post count depending on the number of group_topic_posts he has made in that group.

    I wanted to include the actual groupforumtopic as a post count as well but that would involve counting two different things which is far beyond my meagre talents.

  • Still struggling with this. The code I've got going now is the following. Please could anyone spare 5 minutes to check whether it actually makes sense. I'm still returning a post count of 0.

    $postcount = list_entities_from_annotations($entity_type = "object", $entity_subtype = "groupforumtopic", $name = "group_topic_post", $value = "", $limit = "999999999", $owner_guid = "$post_owner", $group_guid = "page_owner_entity()->guid", $asc = false, $fullview = false, $viewtypetoggle = true);



    } else {

                    $postcount = $postcount[0]->value;


    Then outputting like this:

    echo elgg_echo('group:user:posts');  

                             echo ":"; 

                             echo $postcount;


  • You don't need to "stringify" your variables.  In particular, this one ("page_owner_entity()->guid") is not doing what you expect.  Also, the function you're using is "list_entities".  But you actually want to count the annotations, so you're never going to get a correct count with this.