Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I was browsing around the new Organic Groups for Drupal 7 and I must say that it is very impressive. Unfortunately, some little functions such as Post Count, Member Count and Join link that were available when OG integrated with Views in Drupal 6.X are no longer available as fields in the current implementation of OG + Views integration (Drupal 7). Is this a bug, something that should pushed to the views module or is there something that I am missing?
Thanks in advance
Comment | File | Size | Author |
---|---|---|---|
#64 | og membership.jpg | 57.03 KB | jh81 |
#56 | drupal_6_og_groups_list.png | 58.6 KB | drupalshrek |
#50 | People in group S1 | Site-Install.jpg | 54.94 KB | amitaibu |
#39 | results.jpg | 123.94 KB | seb.pisarski |
#33 | og-member-count.png | 168.75 KB | sal-h |
Comments
Comment #2
kehan CreditAttribution: kehan commentedI would like the join link functionality, so I'm subscribing here too
Comment #3
John_B CreditAttribution: John_B commentedIs there a workaround to create a member count with Views? It is beyond my skill, but there must be a way! It is an important feature for some types of site.
Comment #4
kehan CreditAttribution: kehan commentedI think I may have worked this out but I haven't tried it yet. Using latest views 7.x-1.x-dev under advanced view settings you can choose group by. I think this can lead to the ability to count things like number of users. You would need to somehow pull in users by the group audience field. I may get around to trying this later today and will let you know how it goes.
Comment #5
idiotprayer CreditAttribution: idiotprayer commented@kehan,
you may be on to something. I hadn't thought about using views that way for this problem. I'm not so sure of how the counter works in views, but this could eventually cause a performance drag on your query? There has been some mention before of using a counter in an entity field attached to the group. I started trying to work on this, but haven't had time, so I'm left with some very rough code using a seperate statistics table. If anyone is interested, it's a sandbox project at http://drupal.org/sandbox/idiotprayer/1086720. It does work for post count and comment count, however, I couldn't figure out the logic for updating member counts...
@amitaibu, Any hints on how to do this? There doesn't seem to be a d7 version of 'hook_og.' A field_update hook on the group_audience field maybe?
Comment #6
kehan CreditAttribution: kehan commentedHi @idiotprayer. I'm afraid I didn't get around to doing this today. I would guess that there woudln't be that much perfomance drag on views cos the naming of the function (group by) implies it's a database operation so would be pretty quick.
Let me know how you get on as I'm moving onto a different project next week.
Comment #7
amitaibu@idiotprayer,
I think porting og-statats should be done in a different way -- there is no need for custom tables. The count information can be added to fields that are attached to the group node.
Comment #8
idiotprayer CreditAttribution: idiotprayer commentedAgree, that is the better way, just a bit trickier for me. I will revisit the code I had for that version of the port.
Any suggestions regarding the strategy for member count?
Comment #9
amitaibuGetting members/ nodes count is almost the same, you need to query the og_membership entity:
Comment #10
cartagena CreditAttribution: cartagena commentedCan you please tell me where I need to put this query to get a view that displays a list of groups showing number of members in each group? Thank you.
Comment #11
cartagena CreditAttribution: cartagena commentedJohn_B, I am posting of screen shot of my views settings that give me a member count by group. I still hope to learn how to make adjustments with code and queries as in #9 below but for now, this works. Hope it helps you!
Comment #12
rsanan-1 CreditAttribution: rsanan-1 commented@cartagena Can you explain how you achieved that ?
Comment #13
cartagena CreditAttribution: cartagena commented@rsanan, I set it just as the screenshot of my view shows. Can you be more specific in your question? I am not a programmer so I stay within the parameters of existing modules like views and og.
Comment #14
BeaPower CreditAttribution: BeaPower commentedI wasn't able to see the COUNT field in fields... and I have relationships set up as you have them in the pic.
Comment #15
cartagena CreditAttribution: cartagena commentedBeaPower, I am working on rebuilding this to give you an answer but had a family emergency. Hopefully later this week!
Comment #16
BeaPower CreditAttribution: BeaPower commentedok, hope all is well!
Comment #17
cartagena CreditAttribution: cartagena commentedI'm sorry but I can't recreate what I had. I decided not to use it months ago, but I kept the original so I went back to it so I could give you clearer instructions. I must have changed something along the way because I can't get the member count to work properly. I did try but to no avail. I was also using a very new version of OG for Drupal 7 when I got the count so something may have changed in later versions, too.
Comment #18
mototribe CreditAttribution: mototribe commentedhere are the steps to build the view:
http://drupal.stackexchange.com/questions/15189/how-to-show-the-count-of-members-that-belong-to-a-group/15241#15241
Comment #19
mototribe CreditAttribution: mototribe commentedI found a bug:
- when I try to order the above view by the member count I add field "og membership: entity id" and select "count distinct" and then get the error
"The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item."
Comment #20
drew29 CreditAttribution: drew29 commentedHello,
I've try to configure out my vie but I don't become any results only the labels will be output.
The first and second step I understand but the third step where can I put "user" I have only a textfield
can you explain me how can I solved it :-)
kind regards
drew
Comment #21
drew29 CreditAttribution: drew29 commentedHej,
I'am again. I have found a solution on http://drupal.org/sandbox/idiotprayer/1086720
and you need the module "Organic groups Views integration" and it works perfect for me :-)
hope it helps
kind regards
drew
Comment #22
qproThis another way to show a group list with member count field only with Views and Organic Groups modules.
I hope it helps someone , I were struggling my mind to find it.
1 - Create a view showing users ( adding user:active filter criteria )
2 - Add relationships: first "OG membership: OG membership from User" and then "(OG membership from user) OG membership: OG group gid"
3 - Add fields: first "(OG group) OG group" and "COUNT(User: Name)" for this you have to enable "Use aggregation"
Image attached
Comment #23
BeaPower CreditAttribution: BeaPower commented@22 - Hi do you mind exporting the view to us, because I was not able to replicate the fields, thanks.
Comment #24
qproFew days later I realize that a method like #18 is better. I did few changes:
Comment #25
BeaPower CreditAttribution: BeaPower commented@ #24 -Sorry, but I'm using the english version of drupal. So I don't see in relationships - OG group: OG group from Nodo or any of the other relationships you listed - node being the OG group) OG group: OG membership from OG group.
Comment #26
willkaxu CreditAttribution: willkaxu commentedHi, guy. #24 means OG group from Node. You can check it in your view.
Comment #27
qproHi
Nodo means Node , Usuario means User , almost everything else is in English.
Comment #28
BeaPower CreditAttribution: BeaPower commentedOk, I switched to the dev version and this worked, thanks!
Comment #29
willkaxu CreditAttribution: willkaxu commentedSome relationships in #24 can't be found in 7.x-2.x-dev, all the relationships are whole new in 7.x-2.x-dev.
Comment #30
tomogden CreditAttribution: tomogden commentedUpdating to the 2.x-dev version created major havoc on my site, similar to at least on other person. See #1423278-9: Column not found: 1054 Unknown column 'group_type'.
Comment #31
sunwukong CreditAttribution: sunwukong commentedsubscribe
Comment #32
qpro7.x-2.x-dev version deprecate "OG group entity" and now OG depends on EntityReference which simplifies the relationships and the way to build views.
See the discussion at http://drupal.org/node/1342632 and my efforts to understand the new panels integration with in http://drupal.org/node/1431246.
Comment #33
sal-h CreditAttribution: sal-h commentedAfter messing around with this problem for a day and a half, I finally came up with the solution for a group member count.
Attached is a screen shot of my view configurations. Enjoy!
Comment #34
nedjoSample query for fetching the number of members in a given group with specific roles:
Comment #35
allio_froggio CreditAttribution: allio_froggio commentedThese instructions worked like a charm. Thanks for taking the time to post them, #33!
Comment #36
Sinan Erdem CreditAttribution: Sinan Erdem commentedEasiest way if you are already using members view to show the group members in a block:
http://drupal.stackexchange.com/questions/25976/return-a-views-total-row...
Comment #37
seb.pisarski CreditAttribution: seb.pisarski commentedHi guys, the easiest way to display members and posts counter (without aggregation, contexts etc.) is to use views php with the following pieces of php code:
1. $posts = og_membership_load_multiple(FALSE, array('gid' => $row->gid, 'entity_type' => 'node'));
print count($posts);
2. $members = og_membership_load_multiple(FALSE, array('gid' => $row->gid, 'entity_type' => 'user'));
print count($members);
Your view needs to have group id column (gid).
Comment #38
modctek CreditAttribution: modctek commentedSubscribing - I could not get either #33 or #37 to work. Feeling like a failed web geek at the moment. :(
#33 gave me a SQL syntax error and #37 just returned "0" for every group.
Comment #39
seb.pisarski CreditAttribution: seb.pisarski commented#38 few details on my view setup:
1. in the relationships section I added "OG group: OG group from Node";
2. added "OG group: Og group ID" field via relationship (1.) and positioned it higher than (3.);
3. installed "Views PHP" and added "Global: PHP" field with the following code in Output code field:
I hope this helps.
Comment #40
drupalycious CreditAttribution: drupalycious commentedI tried the method #33 but now only "OG membership: OG membership from Node" is available. And the method doesn't work.
Did someone find out how to expose the number of members and posts per group in a view, with the latest dev of OG?
Thanks
Comment #41
Taxoman CreditAttribution: Taxoman commentedComment #42
PlayfulWolf CreditAttribution: PlayfulWolf commentedcan confirm, that none of those method work for me on OG 7.2
Comment #43
jacobpov CreditAttribution: jacobpov commentedBump I really need this , this is the most basic and needed thing for UI!
Comment #44
qproFinally my solution was:
1 - Include "Global : Result Summary" field in the header of some of my organic groups views to show the number of total items.
2 - Use filters to adjust the result , for example: only active users , only published content , etc...
Comment #45
PlayfulWolf CreditAttribution: PlayfulWolf commented@qpro: about which kind of view are you talking?
Did you made list with 7.2 like: http://drupal.org/files/results.jpg ?
Comment #46
qproThe changes described in #44 was made in the view "OG members" included in the module (version 7.2)
Comment #47
tmsss CreditAttribution: tmsss commentedI was trying to get the group member count and #39 did the work for me, just changed 'entity_type' => 'user'.
Thanks!
Comment #48
Yuri CreditAttribution: Yuri commented@qpro #46, can you elaborate on your method please, I don't understand how you filter the results of the summary field in the header. And I guess you were not able to use that method to show count in fields
Comment #49
Yuri CreditAttribution: Yuri commented@seb.pisarski #39 and @dissid3nt: #47 Am I right that you are NOT using OG 7.x-2.x (since that is what this thread is about) ?
Comment #50
amitaibuNote that we already have Post Count & Member Count as a views plugin for a few weeks now.
Comment #51
PlayfulWolf CreditAttribution: PlayfulWolf commented1) how to see it? I cant find.
2) How to make list with views:
Group A - 23 posts, 5 members
Group B - 523 posts, 93 members
Comment #52
amitaibuPlayfulWolf did you look at the screenshot in #50?
Comment #53
PlayfulWolf CreditAttribution: PlayfulWolf commentedI did, but maybe I am a bit slow :( Ok, I will play with this in a few days and will not waste your time.
If OG 7.2-dev has functionality to display node and member count in views list - this request is closed.
Comment #55
PlayfulWolf CreditAttribution: PlayfulWolf commentedI am going to reopen this issue, as there are no built in OG functionality to buid sortable group list with members and posts count, like in #45:
Group A - 10 members, 100 posts
Group B - 5 members, 50 posts
If it is supposed to be generated by views with aggregation settings - let that be.
Comment #56
drupalshrek CreditAttribution: drupalshrek commentedThe problem I have is pretty similar to the problem I read here.
In Drupal 6, when I edit my OG view, e.g. /admin/build/views/edit/og then when I do "Add fields" I have the option to select from a whole lot of fields grouped under "Organic Groups" such as:
Organic groups: Group: Members count
Organic groups: Group: Post count
Organic groups: Group: Join link
Attached is a screenshot which illustrates the Drupal 6 view.
In Drupal 7, I don't see where I find the ability to get the same items. What I want is a view which shows a list of all groups and the above 3 items for each group. I can get a list of groups with their title (since this is a just a list of node titles, where the node is of a given type), but I cannot figure out how to get the above 3 items.
Thanks for any help.
Comment #57
PlayfulWolf CreditAttribution: PlayfulWolf commentedIt is possible to include "Join link" in a list like this - the best way to get an example is to install OG extras module and take a look included views.
However I still cannot find a solution to show members/posts. It may be simple with rules incrementing some custom field, but this is above my knowledge and I cannot get help on rules and og groups
Comment #58
PlayfulWolf CreditAttribution: PlayfulWolf commented@ Amitaibu - please, explain for us, poor incompetent OG users, how to make a view with members & post count. I cannot get any of the list like (I guess like the other 31 of followers of this issue).
Group A - 10 members, 100 posts
Group B - 5 members, 50 posts
I have looked at 50#, but this is just group overview page, not a view of groups.
Please...
Comment #59
amitaibu> @ Amitaibu - please, explain for us, poor incompetent OG users, how to make a view with members & post count
Either you have fields on the group node, that accumulate the number of posts/ users every time there's a new one; or either you'll have to write some custom code to show the desired list. Not sure if Views would help you for the 2nd scenario.
Comment #60
nksahu CreditAttribution: nksahu commentedI did it in a different way
1) create a view of users
2) Change the format to Table ( Now you see all the users )
3) Added a Relationship ->
OG membership: OG membership from User
4) Add another relation ship ofcourse using the previos relationship -->
(OG membership from user) OG membership: Group Node from OG membership
5) Now Add Field -->Content :Title and use the relationship -->
(Group node from OG membership) Content: Title (Title)
This should give the name of the group
6) Now in OTHERS click
Use aggregation
7) Now use count of USERNAME
--Done--
Comment #61
asherry CreditAttribution: asherry commentedThe main thing I don't like about the aggregation solution is that you can't have different types of membership counts at the same type. For example if you have a view of group nodes, you could potentially have a user membership, and a node membership. There should be the ability to see both of those counts and not have to have conflicting left joins.
I've proposed something in the og_extras module, I'd like to get some feedback. We can create a new field in a view that you customize the target entity for, and the field would be able to attach to any entity view.
I have a patch I'm in the process of testing out.
http://drupal.org/node/1968372
Comment #62
IshaDakota CreditAttribution: IshaDakota commentedIn order for the aggregation solution of membership and post counts to work on a view of groups you'll need the following:
Assuming OG 7.x-2.x, create a view of the group content type with a table format
For members count:
1. Add the relationship "OG membership: OG membership from Content group."
2. Add the relationship "OG membership: User from OG membership" - in the configuration, set Relationship to "OG membership from node group" and make sure the Identifier is set to "user from OG membership."
3. You should now have 2 relationships listed: "OG membership: OG membership from Content group" AND "(OG membership from node group) OG membership: User from OG membership."
4. Add the field User: Uid and in the configuration, use the relationship "user from OG membership"
5. Turn aggregation on.
6. In the aggregation settings for the User: Uid field, set to COUNT.
For posts counts:
1. If you haven't already (when doing members count), add the relationship "OG membership: OG membership from Content group."
2. Add the relationship "OG membership: Content from OG membership" - in the configuration, set Relationship to "OG membership from node group" and make sure the Identifier is set to "node from OG membership."
3. You should now have another relationships listed: " (OG membership from node group) OG membership: Content from OG membership."
4. Add the field Content: Title and in the configuration, use the relationship "node from OG membership"
5. If you haven't already, turn aggregation on.
6. In the aggregation settings for the Content: Title field, set to COUNT.
This is probably not the most performant solution - if you have many groups, members, and posts there could be a performance hit.
@asherry - I tried your patch to OG Extras and it worked for me (for members counts, couldn't figure out how to get post counts). Can't yet really comment on the method as I haven't looked closely at the code.
Comment #63
fadgadget CreditAttribution: fadgadget commentedIve been trying to do this for months and have failed miserably every time. I was hoping that Isha's post above was going to save me but as before 'i have failed miserably'. My failings started at step 1.
OG membership: OG membership from Content group
I dont have this relationship. I am using the latest dev version. Relationships i do have that look similar are-
OG membership from Node
OG membership from Node group
I suspect its one of them. Lets try them both again then....
actually neither lets me have the relatiosnhip in step OG membership: Content from OG membership
OG membership: Node from OG membership seems about as close as i can get. Im going to have to give up. Ive a feeling its 'that easy' to do now that its slipped under my radar. Is there any reason why i might not have a OG membership: OG membership from Content group relationship? Is it possibly just called something else? thanks
Comment #64
jh81 CreditAttribution: jh81 commentedI'm having the exact same issues as fadgadget in #63, I don't see
OG membership: OG membership from Content group
I've attached what I do see. This should be simple to accomplish but I have spent hours on it and can't figure it out. Any help would be greatly appreciated.
Comment #65
PlayfulWolf CreditAttribution: PlayfulWolf commentedthis feature is standing so long, I can chip-in 5-20$ for solution: it does not matter in which module, og, og extras, og stats or another.
Comment #66
IshaDakota CreditAttribution: IshaDakota commented@fadgadget and @jh81, did you try following the instructions in #62, substituting the word "Node" for "Content." I don't know where that label is generated, but maybe in the dev version it was changed (I am using 7.x-2.2), as "Node" is actually more accurate than "Content"
If you do it, post a screenshot of the view configuration with the "Advanced" section expanded - maybe that will provide more troubleshooting info.
Comment #67
jh81 CreditAttribution: jh81 commented@IshaDakota, I'm using OG 7.x-2.2 and was finally able to get this working replacing "Content" for "Node". My relationships are for users:
OG membership: OG membership from Node group
(OG membership from node group) OG membership: User from OG membership
and for content:
OG membership: OG membership from Node group
(OG membership from node group) OG membership: Node from OG membership
Comment #68
fadgadget CreditAttribution: fadgadget commentedwowsers all working now Isha thanks (and jh81) Ive been trying to achieve this for months. excellent :)
Comment #69
AaronBauman#62 accurately answers OP.
Unfortunately this answer is neither obvious nor intuitive for those of us not intimately familiar with OG's database schema.
This is a pretty common thing to want to do.
How can we make this easier?
Comment #70
PlayfulWolf CreditAttribution: PlayfulWolf commentedhttps://drupal.org/node/1070324 - aaron, perhaps this thread can be as a continuation to your question
Comment #71
AaronBaumanYeah, I guess it makes sense for this to live in contrib.
Unless someone can provide a compelling reason otherwise, you'll need to check out a contrib module like "OG Statistics" if the tedious process in #62 does not suit you.
#1070324: Port Organic Groups Statistics to OG 7
Comment #72
fadgadget CreditAttribution: fadgadget commentedsorry if this is the wrong place to ask this but it seems related. Everything went well following #62 instructions. I have just noticed though that only User 1 can see the User Totals. It shows as 0 for normal members. the Node totals works fine for all though.
Can anyone think of a permission that i might have to change for members to see the aggregate User totals?
thanks
Comment #73
IshaDakota CreditAttribution: IshaDakota commented@fadgadget I am having the same problem and can't seem to find the right solution.
If you give users the Node permission: "Bypass content access control" (admin/people/permissions), they can see the user count. Obviously this is not a workable solution.
I can't seem to find the og permission that affects this.
Comment #74
AaronBaumanDid you try changing the views query settings to disable sql rewriting?
Comment #75
fadgadget CreditAttribution: fadgadget commentedI wont be able to aaron im afraid as i have private groups that i dont want people to see on the list. Maybe i could just get rid of the user count. i think folks will be more interested in the amount of content than other users on my site. thanks for the suggestion though.
Comment #76
fadgadget CreditAttribution: fadgadget commentedi suppose a workaround for me could be to add a select checkbox to my group content type and then have the list only show groups with the checkbox clicked. Ill just need to make private groups private via this checkbox. let me go see if it works..... yeah that seems to work fine aaron thanks for the tip.
Comment #77
IshaDakota CreditAttribution: IshaDakota commentedYes aaron, disabling SQL rewriting appears to be the correct approach. Thanks as well for that tip.
My only remaining question to someone more familiar with DB queries and performance is: Is this a scalable solution? Obviously it's not infinitely scalable, but at what point would performance suffer? 100s of groups? 1000s of posts?
The approach in #1070324: Port Organic Groups Statistics to OG 7 and #1968372: Membership counts and membership lists is to add fields that store counts of members and posts. This is clearly easier to handle from a query perspective, but it seems no one has come up with the completely developed solution.
Comment #78
seb_x CreditAttribution: seb_x commentedNow migrating to OG 7.x 2.x My code in #38 / #39 works fine, see the recipe below:
1. Instal OG 7.x 2.x + Views PHP 7.x 1.x
2. Create view for content:
- relationships: OG membership: OG membership from Node (not required)
- filter: content published of group type
- fields:
a) content: nid (hidden)
b) content: title
c) global: PHP (this one is for posts counter)
- output code:
$posts = og_membership_load_multiple(FALSE, array('gid' => $row->nid, 'entity_type' => 'node')); print count($posts);
d) global: PHP (this one is for members counter)
- output code:
$posts = og_membership_load_multiple(FALSE, array('gid' => $row->nid, 'entity_type' => 'user')); print count($posts);
Voila, I hope it helps somebody.
Comment #79
drummondf CreditAttribution: drummondf commentedThought I would make a note that #62 worked great for me, thanks! Using 7-x-2.3
Comment #80
rclemings CreditAttribution: rclemings commentedBoth #62 and #78 work for me as far as getting post counts. I went with the latter only because it involved less typing.
But does anyone have an idea on how to get counts of *unread* posts? That was another field that used to be available directly but isn't now.
I can use the "has new content" field, but that's just a flag, not a count.
Comment #81
drummondf CreditAttribution: drummondf commented@rclemings how are you identifying "unread" posts? Unread by who? Maybe defining that a little better will help us figure out which filter is most appropriate
Comment #82
rclemings CreditAttribution: rclemings commented"Number of new posts in a group for the current user" is how OG defined the now-missing field previously. I'm referring to OG v6.x-2.4. It's defined in og_views.views.inc.
Comment #83
Anonymous (not verified) CreditAttribution: Anonymous commentedI have seen many custom code posts around the web forget to properly query the database. When you query the og_membership table, you must not forget there might be attached nodes that allso have an og_membership. Hence, you must limit your queries to entity_type user, when you are counting users, and entity_type node when you are counting attached nodes. Here are some sample snippets that someone might find useful (I'm using Drupal 7)
Return count of all the users in group with gid 777
Return a count of all the groups of use with uid 888
If you want to do modify your queries to do something similar, just have a look at the og_membership table and see what you have to modify. You should be able to figure it out, by substituting the appropriate parts in the codes above.
Hope this is useful to someone.
Comment #84
Shabbir CreditAttribution: Shabbir commentedHi,
@PlayfulWolf, in your comment #57 you said, you can add join link by installing og_extras module. I did install og_extras module, can you please be a bit more clearer on what to do in order to get the join link visible..
Thanks,
shabs
Comment #85
mesnitu CreditAttribution: mesnitu commented@Shabbir, with og_extras you have a block with the join link. Or if you use pages, you have a view called Content create links
Comment #86
divined CreditAttribution: divined commentedAlways return 0.
$row->nid != gid.
How to recieve gid from node? Not in view, i.e. node.tpl ?
Comment #87
moin khan CreditAttribution: moin khan commentedfriends, 62 works perfectly but total users count field displaying (0) to other site members but when i login as a admin, user count field displaying properly with numbers.