A block to show nodes that are added to users' favorites in last 24 hours, would be great.

Comments

JordanD’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev

If I could get a daily/weekly (Or even configurable time frame?) most favorited nodes block---I'd be happier than a pig in mud. Any chances?

asund’s picture

I really want this feature!
Pretty please? =)

asund’s picture

I wrote a similar snippet here. Might be able to use it for this with a few tweeks
http://drupal.org/node/215210#comment-830015

asund’s picture

Okay, I rewrote it to be a list of the most favorited for the last days.
This can just be pasted in a block with PHP filter.

<?php
//You may make som changes to these variables:
$days = 7; //Number of days to include
$list_length = 10; //Number of nodes to list
$min_faves = 1; //Minimum amount of favorites to be listed

//---------------
$result = db_query("SELECT * FROM {node} WHERE created > %d-86400*%d",time(),$days); //Gets all nodes from the specified days

while ($anode = db_fetch_object($result)) {
  $sql = "SELECT nid FROM {favorite_nodes} WHERE nid = $anode->nid"; //Counts number of favorites for each node
  $count = db_num_rows(db_query($sql, $nid));
  if($count>=$min_faves){
    $favnodes[$anode->nid]=array("count" => db_num_rows(db_query($sql, $nid)), "nid" => $anode->nid); //Stores data in an    Array
  }
}

rsort($favnodes); //Sorts nodes by number of favorites
$output = "<ul>";
$prcnt = 0;
while($prcnt<$list_length){
  $node = node_load($favnodes[$prcnt]["nid"]); //Loads node from nid
  if($node){
    $output .= "<li><a href='".url(drupal_get_path_alias("node/".$node->nid))."'>".$node->title."</a></li>";
  }
  $prcnt++;
}
$output .= "</ul>";
print $output;
?>