Hi, thanks a lot for such a valuable module! But I still miss one small thing to become totally happy :)

Here's what I'd like to do. Using Panels I'd like to override the normal node's page and add there a block with users who have added this node to their favorites.

Basically, I just need to have an argument "Favorite Nodes: Node ID" that would restrict the list of users generated by Views (with the help of Usernode module) only to those users who have added this node to favorites.

I've tried to dig into the code myself but being quite new to Drupal I got really frustrated with the views argument handling. So, I will appreciate any help!

CommentFileSizeAuthor
#1 favorite_nodes.zip5.04 KBcostinius

Comments

costinius’s picture

Status: Active » Fixed
StatusFileSize
new5.04 KB

Finally I managed to get it done myself. Here's what I did:

1. Added a new table to the hook_views_tables:


  $tables['usernode_favorite_nodes'] = array(
    'name' => 'favorite_nodes',
    'join' => array(
      'left' => array(
        'table' => 'usernode',
        'field' => 'uid',
      ),
      'right' => array(
        'field' => 'uid',
      ),
    ),
  );

2. Added a new arg to the hook_views_arguments:


  $args['node_id'] = array(
    'name'    => t("Favorite Nodes: Node ID"),
    'handler' => 'favorite_nodes_handler_argument_nid',
    'help'    => t('Node ID for Favorite node.'),
  );

3. Added a new handler for the NodeID argument:


function favorite_nodes_handler_argument_nid($op, &$query, $argtype, $arg = '') {
  switch ($op) {
    case 'filter':
      $nid = intval($arg);
      $table_data = _views_get_tables();
      $joininfo = $table_data['usernode_favorite_nodes']['join'];
      $joininfo['type'] = 'inner';
      $joininfo['extra'] = array('nid' => $nid);
      $query->add_table("usernode_favorite_nodes", true, 1, $joininfo);
      break;
  }
}

I'm not sure if the code is perfect, but it works for me. Hope it will help others too (please mind dependency on the Usernode module).

Attached is the changed version of the 'favorite_nodes.module'.

kbahey’s picture

I committed it to 5.x-1.x-dev.

I added in the description that this requires the node profile module.

Wait till tomorrow and download the -dev tarball and test it.

costinius’s picture

Khalid, thanks!

Just some clarification - the Nodeprofile module is not needed (I didn't install that); the patch depends on the Usernode module instead (the one responsible for Views integration).

Some more clue where this can be really applicable (and why I needed it) - this functionality allows users to create Fan Clubs around artists, actors etc. In this case you should have an artist-node which Fans can add to their "favorites". And vica-versa, with the help of Panels and Views you can easily show the list of Fans on the artist's page.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.