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.
This module is great! I'm using it on my site http://www.preik.no/ and it's really good!
But I really need a Views filter and sort criteria for Favorite Nodes.
* Filter to only show nodes when lets say 2 or more users has added the node as a favorite.
* Sort criteria to sort by number of users having added the node as a favorite.
I'll gladly pay/donate $25 if anyone can help me with this pretty fast!
Comment | File | Size | Author |
---|---|---|---|
#6 | favorite_nodes.zip | 5.83 KB | costinius |
#4 | favorite_nodes.zip | 5.89 KB | costinius |
Comments
Comment #1
CoolDreamZ CreditAttribution: CoolDreamZ commentedSubscribing as I would also like this functionality, especially the second bullet point (sort criteria in a View)
Comment #2
asund CreditAttribution: asund commentedI managed to make a list of the most favorited nodes.
I'm sure the code can be improved a lot by someone who actually knows php. :P
It is VERY slow as it is now (at least on my site with loads of content)
Comment #3
costinius CreditAttribution: costinius commentedSubscribing. I've tried to fix it myself (the 2d point) but failed so far.
Comment #4
costinius CreditAttribution: costinius commentedHi, I've fixed the 2d problem "Sort criteria to sort by number of users having added the node as a favorite." It works fine for me.
The updated files are attached. You'll have to reinstall the module to make it work (remember to backup {favorite_nodes} table and restore it after the reinstallation of the module).
Shortly, my code creates a new table {favorite_nodes_count} which stores the data with the number of users who added the node as a favorite. Then making it work in views becomes a piece of cake. If anyone wants to add a filter (1st problem), you can easily add necessary code.
Disclaimer: It took me 15 minutes to update the module, so I can't guarantee that it's perfect. Please test it first.
Comment #5
kbahey CreditAttribution: kbahey commentedThanks for this.
However, including a patch will make the review much easier than the full module.
Please read about how to create a patch at http://drupal.org/patch
Comment #6
costinius CreditAttribution: costinius commentedOoops, found one bug already. Attached is the corrected version.
Khalid, I know I need to read that and post patches instead of full modules, sorry. I'm not that advanced at Drupal yet. Will do my best next time :)
Comment #7
kbahey CreditAttribution: kbahey commentedI am divided about this patch. One one hand, it solves the issue of "Count". But from an architecture point of view, it introduces extra (summary) table, which is denormalization. It solves the problem now, but becomes a management and maintenance burden, and introduces the possibility of inconsistencies later.
So, I like to get some feedback on this from an architecture/design point of view.
Hence, I created a cleaned up patch from costinius' .zip file for those who want to review it.
Comment #8
costinius CreditAttribution: costinius commentedKhalid, thanks for creating the patch. Just 2 comments:
1. I didn't find a better way how to solve the problem. If anyone has other ideas, please suggest.
2. The patch updates the summary table only when someone adds/removes a node to/from the favorites. Afterwards the views module retrieves the data directly from this table, which makes this operation much faster than calculating the # of users each time a view is loaded in the browser window. It becomes even more relevant when the view is used often by a big number of users.
Comment #9
SpikeX CreditAttribution: SpikeX commentedSubscribing.
I need a way to sort by favorite count. I tried to add a Sort views handler to the view API code, but it didn't work right.