Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
In the past there seemed to be a patch to add user relationship count to views options: http://drupal.org/node/216473
That was for version 5 and it seemed to have never been committed.
Is there already a way to get the relationship count in views? I'd like to be able to sort by relationship count (how many friends you have) and also post that number in a field. I can do the second if I make a custom views template and manually put in the count; but that's more complicated when it comes to sorting which is why it's needed in views.
Comments
Comment #1
ChrisRut CreditAttribution: ChrisRut commented:subscribing:
Comment #2
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #3
grzegorz.bartman CreditAttribution: grzegorz.bartman commentedsubscribing
Comment #4
manoz_79 CreditAttribution: manoz_79 commentedsubscribing
Comment #5
ajayg CreditAttribution: ajayg commentedThese is an easy way (in any view) to get count of all records returned. So once you get your view working, and you should try the default relationship browser view as a model, just add following in the header or footer
I typically keep the Title of views display blank and replace "Relationship count" text above with whatever title I want for display and add above to header.
Comment #6
YK85 CreditAttribution: YK85 commentedThanks for the help ajayg. That trick does indeed work for showing the relationship count for a view of one specific user.
Just to note - this does not work if you want a view with many users' username and the relationship count per user.
I believe this would require work to create a views field for this information.
-------------------------------
username | relationship count
username | relationship count
username | relationship count
username | relationship count
-------------------------------
Thanks!
Comment #7
ajayg CreditAttribution: ajayg commentedI have not tried myself. But have you looked at View group by module?
Comment #8
Offlein CreditAttribution: Offlein commentedThis is useful functionality - and should be worked into a views handler because I'd eventually like to use it as an Exposed Filter. That is, users on our site can have a maximum of 3 buddies, and our search is basically an exposed view. It'd be great to give them the ability to see only users who had no buddy, had the maximum number of buddies, or otherwise.
And when I say "because I'd like it" I, of course, really mean "because since I'd like it, probably someone else would too". If there was a field handler for this already, presumably I (or someone) would be able to make a filter handler relatively quickly as well.
Comment #9
cerup CreditAttribution: cerup commentedI agree with Offlein. This should really be made into a view handler. Searching/sorting/filtering people based on how many relationships they have is very common today and would probably be used by the majority of people using this module in some capacity I could imagine.
If I get a chance i'll see if I can create a working patch. I actually think the patch in my first post may still apply #216473: PATCH: Addition to views section -- User Relationship Count but needs to be reworked to add to the current dev version.
Comment #10
YK85 CreditAttribution: YK85 commentedI will definitely do my best to help with testing if someone could work on a patch for views handlers. Thank you!
Comment #11
pedrofaria CreditAttribution: pedrofaria commentedThis feature is not so easy to do...
The best way is do it by SQL but i guess that it must be very hard to do it with views schema... maybe i can get the count value when views render the field to output...
i will put the patch at #866400: Views filter patch for current user
cya
Comment #12
YK85 CreditAttribution: YK85 commentedThanks pedrofaria!
I look forward to testing it =)
Comment #13
pedrofaria CreditAttribution: pedrofaria commentedField added to patch...
Please, review it... ;)
pedrofaria
Comment #14
robby.smith CreditAttribution: robby.smith commentedIt be very cool to have two fields.
User Relationships: Pending relationship counter
User Relationships: Approved relationship counter
Comment #15
YK85 CreditAttribution: YK85 commentedThere is some code for pending count at http://drupal.org/node/562138#comment-2008640
Comment #16
mmachina CreditAttribution: mmachina commentedis there way to adjust the code to read differently if user has only 1 friend... or more than 1 friend?
1 friend or
10 friends
Comment #17
YK85 CreditAttribution: YK85 commentedI was wondering if anyone had any progress with this views relationship count?
Thanks!
Comment #18
diego.pasc CreditAttribution: diego.pasc commentedsubscribing
Comment #19
mrf CreditAttribution: mrf commentedThis would need #468442: Provide API function to return relationship counts completed before tackling views integraiton.