Download & Extend

List of nodes matching users subscriptions - Views

Project:Notifications
Version:6.x-4.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hi there,

For a community site I'm building, I'd like to give users the ability to subscribe to authors, taxonomies, or groups. There are different modules for each of these, but to prevent module bloat, a single solution is highly desirable. Notifications already supports all the requirements, except one:

Can subscriptions be exposed as a Views 2 filter?

That is to say, rather than (or in addition to) a user receiving an e-mail which informs them of the new content in the areas to which they've subscribed, a single Views-powered page featuring all the new nodes from the authors, groups, taxonomy terms (etc.) to which they've subscribed.

Is that possible?

Comments

#1

This appears to already be possible in the Subscriptions module:

http://drupal.org/node/269472#comment-952645

#2

Status:active» closed (duplicate)

#260435: Views integration

#3

re-opening this and hi-jacking since i don't think the Notifications Views integration is finished.

Original poster's questions is valid and extremely useful - but not supported by n_views.module as far as i can see.

My need is simple and i think the intent of something like views support for notifications - i would like to have a block that shows a user his most recent nodes of interest. By his interest i mean "Subscribe to N terms and see latest nodes that are tagged with any of these terms".

original poster, i believe is asking for the same thing:

rather than (or in addition to) a user receiving an e-mail which informs them of the new content in the areas to which they've subscribed, a single Views-powered page featuring all the new nodes from the authors, groups, taxonomy terms (etc.) to which they've subscribed.

i think the argument handler in n_views for Subscriber UID is close; but it only filters the nodes which the user subscribed to directly - and doesn't take in to account the "rules" concepts of notifcations like taxonomy, authors, etc. There needs to be a join somewhere with the term_data table for the taxonomy part of this to work.

I am trying to figure out Dr6 views handlers to see if this is possible; but if anyone has a better grasp of views handlers - please let me know; i can pay for a solution to this!!

#4

Title:Views integration - 'notification as filter'» List a users subscriptions - Views Integration
Version:6.x-1.x-dev» 6.x-2.1
Status:closed (duplicate)» active

#6

Title:List a users subscriptions - Views Integration» List of nodes matching users subscriptions - Views

title still too obscure.. lol

#7

ok, haven't been able to figure out the views handler code to do this properly; but here is a pretty cool hack in case anyone is trying to do this same thing (i.e. list nodes user is interested in).

basic idea is:

- i know the sql to get the nids i need to match BOTH the specific nodes i am subscribed to as well as the nodes matching the taxonomy rules i am subscribed to
- just can't figure out complex views handler to do this properly.

so:

- simply make a function that returns the full list of these nids
- ad a view arg for Node: NID and convert the arg(1) real passed in arg (which will be the user's UID when we add this view page as a tab off My Account) to a comma separated list of nids

pretty bad/cool hack.. :).. works like a charm

// build block of recent posts that match users subscriptions
//  - include individual subscribed nodes AND nodes matching taxonomy rules
//  - will need this as a block, tab page, etc
function _chec_notifications_subscribed_block($uid = null) {
  if (!$uid) $uid = arg(1);
  $nids = array();
 
  // Nodes
  $sql = "SELECT DISTINCT(node.nid) AS nid, node.changed FROM node node
    LEFT JOIN notifications_fields notifications_fields ON node.nid = notifications_fields.value AND notifications_fields.field = 'nid'
    LEFT JOIN notifications notifications ON notifications_fields.sid = notifications.sid
    WHERE notifications.uid = %d";
 
  $results = db_query($sql, $uid);
  while ($result = db_fetch_object($results)) $nids[] = $result->nid;
 
  // Taxonomy Rules
  $sql = "SELECT DISTINCT(node.nid) AS nid, node.changed FROM node node
    Inner Join term_node ON node.vid = term_node.vid
    Inner Join notifications_fields nf ON nf.value = term_node.tid
    join notifications n on n.sid = nf.sid and n.uid = %d
    WHERE nf.field = 'tid'";
   
  $results = db_query($sql, $uid);
  while ($result = db_fetch_object($results)) $nids[] = $result->nid; 
 
  return $nids;
}

function _chec_test(){
  $nids = _chec_notifications_subscribed_block($handler->argument);
  return join(",", $nids);
}

and the arg handler code:

$handler->argument = _chec_test();
return true;

#8

of course, now that we have full list in arg, all the std views features can work on this; like sort as required, paging, make tabbed pages, blocks, etc..

can't believe i didn't think of this sooner.

#9

Can you post your view that makes this work?

#10

$view = new view;
$view->name = 'subscribed_nodes';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
  ),
));
$handler->override_option('sorts', array(
  'last_updated' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'last_updated',
    'table' => 'node_comment_statistics',
    'field' => 'last_updated',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'nid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'current_user',
    'default_argument' => '',
    'validate_type' => 'php',
    'validate_fail' => 'not found',
    'break_phrase' => 1,
    'not' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'faq' => 0,
      'forum' => 0,
      'blog' => 0,
      'bookmark' => 0,
      'bookmark_global' => 0,
      'category' => 0,
      'community' => 0,
      'event' => 0,
      'group_blog' => 0,
      'page' => 0,
      'resource' => 0,
      'site_text' => 0,
      'subcategories' => 0,
      'wiki' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '45' => 0,
      '42' => 0,
      '43' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_is_member' => 0,
    'validate_argument_signup_status' => 'any',
    'validate_argument_signup_node_access' => 0,
    'validate_argument_php' => 'if (!$handler->argument) $handler->argument = arg(1);
$handler->argument = _chec_test($handler->argument);
return true;',
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'perm',
  'perm' => 'access content',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'My Subscribed Content');
$handler->override_option('empty', 'You have no subscribed content.');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', '1');
$handler->override_option('use_more', 1);
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
  'relationship' => 'none',
  'build_mode' => 'teaser',
  'links' => 1,
  'comments' => 0,
));
$handler = $view->new_display('page', 'Subscribed - Full', 'page_1');
$handler->override_option('arguments', array(
  'nid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'current_user',
    'default_argument' => '',
    'validate_type' => 'php',
    'validate_fail' => 'not found',
    'break_phrase' => 1,
    'not' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'faq' => 0,
      'forum' => 0,
      'blog' => 0,
      'bookmark' => 0,
      'bookmark_global' => 0,
      'category' => 0,
      'community' => 0,
      'event' => 0,
      'group_blog' => 0,
      'page' => 0,
      'resource' => 0,
      'site_text' => 0,
      'subcategories' => 0,
      'wiki' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '45' => 0,
      '42' => 0,
      '43' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_is_member' => 0,
    'validate_argument_signup_status' => 'any',
    'validate_argument_signup_node_access' => 0,
    'validate_argument_php' => 'if (!$handler->argument) $handler->argument = arg(1);
$handler->argument = _chec_test($handler->argument);
return true;',
  ),
));
$handler->override_option('access', array(
  'type' => 'perm',
  'perm' => 'views disable',
));
$handler->override_option('path', 'chec/%/subs');
$handler->override_option('menu', array(
  'type' => 'tab',
  'title' => 'Interesting',
  'description' => '',
  'weight' => '3',
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));
$handler = $view->new_display('block', 'Your Latest', 'block_1');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('title', 'Your Latest');
$handler->override_option('items_per_page', 5);
$handler->override_option('use_pager', '0');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
  'grouping' => '',
  'type' => 'ul',
));
$handler->override_option('row_plugin', 'fields');
$handler->override_option('row_options', array(
  'inline' => array(),
  'separator' => '',
));
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
$handler = $view->new_display('page', 'Subscribed - Nodes Only', 'page_2');
$handler->override_option('arguments', array(
  'uid' => array(
    'default_action' => 'empty',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid',
    'table' => 'notifications',
    'field' => 'uid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'faq' => 0,
      'forum' => 0,
      'blog' => 0,
      'bookmark' => 0,
      'bookmark_global' => 0,
      'category' => 0,
      'community' => 0,
      'event' => 0,
      'group_blog' => 0,
      'page' => 0,
      'resource' => 0,
      'site_text' => 0,
      'subcategories' => 0,
      'wiki' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '45' => 0,
      '42' => 0,
      '43' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_is_member' => 0,
    'validate_argument_signup_status' => 'any',
    'validate_argument_signup_node_access' => 0,
    'validate_argument_php' => '',
  ),
));
$handler->override_option('path', 'chec/%/subscribed');
$handler->override_option('menu', array(
  'type' => 'tab',
  'title' => 'My Subscribed',
  'description' => '',
  'weight' => '3',
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));

#11

Here is the module that I've built for this purpose.

I am not sure about the performance implications of module and interoperability with other views elements. And I am not sure if it would function on PGSQL. It works directly on node table by implementing sub-queries that use multiple table joins.

Install as any other drupal module. On Modules page you will find Advanced Notifications Views under Notifications section.

After enabling the module, in your view you will notice three additional filters and three additional arguments under 'Notifications' group.

The filters/arguments are 'Subscribed Tags', 'Subscribed Content Types' and 'Subscribed Types in OG'. Support for Thread subscriptions is already built in the notifications views module, but I am not sure about the 'Author' and 'Content type and Author' subscriptions.

I have added two more options for each filter/argument, 'Filter Operator' and 'Group Operator'. With these options you can control how the content is filtered.

Case study:

Let's assume that we have enabled og subscriptions and tag subscriptions on our web site.

We want to allow users who are subscribed to Content types in OGs only to see the nodes tagged by the terms that they are subscribed to. On top of that we want to include our site News Letters in their streams.

Solution:

We would create a view with following filters:

'Notifications: Subscribed Types in OG' with following options set:

- Is the logged in user: True,
- Filter Operator: AND,
- Group Operator: OR.

'Notifications: Subscribed Tags' with following options set:

- Is the logged in user: True,
- Filter Operator: AND,
- Group Operator: OR.

'Node: Type' with following options set:

- Operator: Is one of,
- Node type: Site News Letter.

Hope that it explains a little bit. :)

Please do not use this on your production site, before you throughly test it.

Perhaps the 'Notifications' maintainers would like to consider this module merging into the 'Notifications Views'?

Cheers!!

AttachmentSize
advanced_notifications_views.tar_.gz 2.59 KB

#12

Subscribing...

#13

Version:6.x-2.1» 6.x-4.x-dev

To be considered for 4.x

#14

Subscribing.

#15

Subscribing. And just think, if this worked and was implemented on d.o, I wouldn't have to do this (:

#16

subscribed

#17

Will this work with cck also? There is a cck notifications add-on for the Notifications module.

Also on May 27, 2010 it states "to be considered for 4.x". has this been put in there yet?

#18

I'm also very interested with this feature. But isn't it what notifications_views is supposed to offer ?

#19

subscribing