Download & Extend

View users who have a node as favorite

Project:Favorite Nodes
Version:6.x-1.x-dev
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hi,

I really like the 'favorite_nodes' module.
There is one quetion that I have.
I would like to show all users who have a node put to their favorites.
Means I'm on a node-page which can be put as favorite node. Now I want to see the users who put it at their favorite node (instead of just showing the counter).
I hope you understand what I mean ;o)
Is there a view like this?

Thank you for your hints,
Doris

Comments

#1

Subscribing

#2

I think, this should be done via views. We can create a user views type, and perhaps use arguments to filter for all users who faved that node

#3

Can you explain how you do that ?

Thx

PS : Subscribing too

#4

Subscribing. This is a heavily requested feature by my users. Please add functionality to be able to view who favorited a particular node.

#5

Well... since noone developing this module has responded with a solution, I'll post mine. But here's the disclaimer:

This is NOT efficient code. This is by far NOT the best way to go about this. But it does work. And if you want a quick and dirty solution, here it is.

<?php
function who_favorited_this($nid) {
   
$output = '<fieldset class=" collapsible collapsed"><legend><a href="#">Who favorited this?</a></legend><div class="top"><div class="bottom"><div class="bottom-ornament"><div><br />';
   
   
$count = 0;
   
   
$result = db_query('SELECT uid FROM favorite_nodes WHERE nid = ' . $nid);
    while(
$fav = db_fetch_object($result))
    {
       
$thisu = user_load($fav->uid);
       
$output .=  theme('username', $thisu);
       
$output .= '<br />';
       
$count++;
    }
   
$output .= '</div></div></div></div></fieldset>';
   
    if(
$count > 0)
    {
        return
$output;   
    }
    else
    {
        return
'';   
    }
}
?>

Put this inside your template.php file, and then insert this code somewhere in your node.tpl.php file:

<?php
if(function_exists("who_favorited_this"))
{
    print
who_favorited_this($node->nid);
}
?>

Like I said... it's quick and dirty, but it works.

#6

Subscribing

#7

Thanks for this! I'm considering using it on my site, as there's just obviously so much value displaying who favorited a particular node.

If you can, would you mind explaining any drawbacks of utilizing your down-and-dirty code? I understand how it works, but I'd just like to know, say, if the query is too basic that it puts undue load on querying the database. I don't know enough about optimizing queries to know whether this might be the case or not.

#8

@7: You're only performing a single query, so it shouldn't be that bad. I don't know what kind of performance this gets, though, as I've only ever seen this function work with less than 50 users at a time (that are returned from the query), so I can't really answer your question. You could always test it on your site as an administrator before deploying it to everyone else.

#9

Ahhhh I could see returning a large result set being problematic if it goes into the hundreds or possibly thousands, without incorporating a paging ability to retrieve only a subset of the whole.

I've already begun implementing it and it works great. I'll have to add on more hacked code for the paging. Will hold out hope that we'll get a proper update for this module, but many many thanks for your quick fix contribution here!

nobody click here