There are several requests for the results of favorites to be displayed in a block. Given that there could be a huge variation in the exact block that different users could want, it seems that adding view support would allow each user to create their own block.

Comments

mr.andrey’s picture

Yes, views support would be wonderful. I would like to implement daily/weekly/monthly blocks to throw up on the front page.

Andrey.

cmillet1’s picture

I would also like to see Views support. I'd like to include users' favorite nodes in either pages or blocks, along with some more advanced filtering such as by role or content type. I think Views support is the best approach to making this possible.

Thanks -

Chris

kakoolcom’s picture

we're working on this... but can't get field & filter to work (view shows no results).. does anyone see anything wrong with our code?

-------------------------------------

<?php
// $Id: views_favoritestest.inc,v 1.6.4.4 2007/03/04 06:30:22 merlinofchaos Exp $
/**
* This include file implements views functionality on behalf of recommendedlink.module
*/
function favoritestest_views_tables() {
$tables['favorite_nodes'] = array(
'name' => 'favorite_nodes',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'users',
'field' => 'uid'
),
'right' => array(
'field' => 'uid'
),
),
'fields' => array(
'nid' => array(
'name' => t('Favorite_nodes: nid'),
'sortable' => true,
'handler' => 'views_handler_favorite_nid',
'help' => t('This will display the nid'),
),
),
"filters" => array(
'uid' => array(
'field' => 'uid',
'name' => t('Favorite_nodes: uid'),
'operator' => 'views_handler_operator_eqneq',
'list' => array('***CURRENT_USER***' => t('Currently Logged In User')),
'list-type' => 'select',
'handler' => 'views_handler_filter_favenid',
'help' => t('This allows you to filter nodes based on favorites.'),
)
),
);
return $tables;
}
function views_handler_favorite_nid($fieldinfo, $fielddata, $value, $data) {
return l($value, 'node/'.$value->nid);
//drupal_set_message("node/$value->nid");
}

function views_handler_filter_favenid($op, $filter) {
global $user;
return l($value, $user->uid);
//$table = $fieldinfo['favorite_nodes'];
//$query->add_where("$table.uid = ***CURRENT_USER***");
// if ($filter['value'] != '***ANY_USER***') {
// $joininfo['extra']['uid'] = $filter['value'];
//}
//global $user;
//$favenodes = array();
//$result = db_query("SELECT DISTINCT nid FROM {favorite_nodes} f where uid=%d",$user->id);
//while ($obj = db_fetch_object($result)) {
// $favenodes[$obj->nid] = "$obj->nid";
//}
//return $favenodes;
}

yhager’s picture

Status: Active » Needs review

I am using the code below, which gives me 'Node is favorite of the current user' filter. I just found this in my sandbox, not sure if it's mine or if I picked it up somewhere... :)


function favorite_nodes_views_tables(){
  $tables['favorite_nodes'] = array(
    "name" => "favorite_nodes",
    "join" => array(
      "left" => array(
        "table" => "node",
        "field" => "nid"
      ),
      "right" => array(
        "field" => "nid"
      ),
    ),
    "filters" => array(
      "uid" => array(
        'name' => "Favorite Nodes: Node is a Favorite for Current User",
        'operator' => "views_handler_operator_eqneq",
        'list' => "views_handler_filter_usercurrent",
        'handler' => "favorite_nodes_views_handler_filter_uid_is_favorite",
        'cacheable' => 'no'
      )
    )
  );
 
  return $tables;
}

function favorite_nodes_views_handler_filter_uid_is_favorite($op, $filter, $filterinfo, &$query) {
  $tn = $query->add_table($filterinfo['table']);
  $tname = $query->get_table_name($filterinfo['table'], $tn);
  $query->add_where("$tname.uid $filter[operator] '%s'", $filter['value']);
}
kbahey’s picture

Status: Needs review » Fixed

I finally created a comprehensive solution for this feature.

Features are:

- Filter for current users (my favorite nodes)
- Filter for all nodes that have been added to favorites by any user.
- A field that shows how many users have added the node to favorites, useful as an indication for popularity.
- An argument that allows filtering of Favorites nodes for a specific user. This is useful to show "editor's picks" and such type of lists.

This work has been done

Anonymous’s picture

Status: Fixed » Closed (fixed)

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