Posted by nwe_44 on July 27, 2007 at 9:22pm
Jump to:
| Project: | Favorite Nodes |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
may I suggest adding this function
/**
* count number of times a node has been called a favorite
*/
function _favorite_nodes_count($nid) {
global $user;
$sql = "SELECT * FROM {favorite_nodes} WHERE nid = %d";
return db_num_rows(db_query($sql, $nid));
}and perhaps adding the result to a node's header.
Comments
#1
Why the "global $user" line?
#2
fair point – it has no business here.
That was legacy from me playing with the code.
#3
It's still a good idea.
#4
*** NOTE: FOR DRUPAL 6.x ONLY *** (unless someone feels brave enough to test it on 5.x)
I did something similar on my website.
In the node links area (at the bottom), to show the number of favorites, perform this manual patch:
Add this function to the module file:
<?php/**
* Function to count the number of favorites.
*/
function favorite_nodes_count($nid) {
return db_result(db_query("SELECT COUNT(*) FROM {favorite_nodes} WHERE nid = %d", $nid));
}
?>
Find this function:
function favorite_nodes_link($type, $node = NULL, $teaser = FALSE)Near the bottom of the function you'll see a lot of }'s. Replace those with this code:
<?php
);
}
}
}
}
if(!$teaser)
{
$links['favorite_count'] = array(
'title' => (intval(favorite_nodes_count($node->nid)) == 1) ? t('1 favorite') : favorite_nodes_count($node->nid) . ' ' . t('favorites')
);
}
else if($teaser && variable_get('favorite_nodes_teaser', 0) == 1)
{
$links['favorite_count'] = array(
'title' => (intval(favorite_nodes_count($node->nid)) == 1) ? t('1 favorite') : favorite_nodes_count($node->nid) . ' ' . t('favorites')
);
}
}
}
return $links;
}
?>
Don't forget the ");" at the top of that code (you don't want 2 of those in there).
Sorry I can't give a patch file, I've pretty heavily modified my favorite_nodes.module file and I'm not very good with patches anyway. :P Hope this helps! :)
Also, it would be cool if we could eventually have a page that would list all the users who favorited this node (and maybe even expose that to Views using a relationship).
#5