We 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 favorite_nodes 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;
}
Comments
...
(Please wrap your code in
<code>next time.)You're building a bookmark service. Then you probably want to connect your table to the 'node' table, not to the 'users' one. Think of it in this way: "Views by default shows all the nodes on your site. What you want to do is to filter them by the booker." ('booker' is the person who bookmarked this node; it's the 'uid' in the table you created.)
--
Help save BLOCKQUOTE
Resolved: views added to favorite_nodes.module
This has been fixed in new version of favorite_nodes..
...
Oh? I didn't realize we were talking about the 'favorite_nodes' module :-)
BTW, have a look at the 'views_bookmark' module, which is very similar to favorite_nodes. (and of course it has Views support.)
Voting and faving
Sadly, after using favorite nodes I've realized that using the voting API and just making the user interaction simple, you can leverage the information better. Recommended content, user points, etc. only happen when you have a more full handle on the data... unless you want to go custom.