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

kitt’s picture

Why the "global $user" line?

nwe_44’s picture

fair point – it has no business here.

That was legacy from me playing with the code.

Dabitch’s picture

It's still a good idea.

SpikeX’s picture

*** 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:

/**
 * 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:

              );
            }
          }
        }
      }
	  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).

kbahey’s picture

Title: n people call this a favorite » Number of times a node was added as a favorite
Version: master » 6.x-1.x-dev