Views Support

monjohn - September 25, 2007 - 02:50
Project:Favorite Nodes
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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.

#1

mr.andrey - October 5, 2007 - 23:34

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

Andrey.

#2

cmillet1 - November 5, 2007 - 17:01

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

#3

kakoolcom - December 22, 2007 - 00:32

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

#4

yhager - December 26, 2007 - 09:06
Status:active» patch (code 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... :)

<?php
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']);
}
?>

#5

kbahey - December 29, 2007 - 20:42
Status:patch (code 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

#6

Anonymous - January 12, 2008 - 20:51
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.