Hi,
I'm trying to fill up a gap in Users subscriptions management with Views, but cannot find a way:

My website have several newsletters and I would like to list in a table all registered users with their different newsletter subscriptions, as below.

John Doe Newsletter 3
Newsletter 5

Mark Zuck Newsletter 2
...

I thought this would not be difficult to achieve with Views, however, I could not find yet any way to get the proper relationships. If I start with a Users view, I'm getting only 'Simplenews subscriber: User' relationship. And if I start with a Simplenews subscriber view then the best that I can get is a list with Users and the Simplenews subscription: Term ID they are linked with (see attached copy screen and view export below).

Maybe I'm missing something. Does someone have a better way to list registered users subscriptions ? Thanks for any hint.

$view = new view();
$view->name = 'users_subscriptions';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'simplenews_subscriber';
$view->human_name = 'Users Subscriptions';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Users Subscriptions';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'name' => 'name',
  'tid' => 'tid',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'tid' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: Simplenews subscriber: User */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'simplenews_subscriber';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
/* Relationship: Simplenews subscription: Subscriber ID */
$handler->display->display_options['relationships']['snid']['id'] = 'snid';
$handler->display->display_options['relationships']['snid']['table'] = 'simplenews_subscription';
$handler->display->display_options['relationships']['snid']['field'] = 'snid';
/* Relationship: Simplenews subscription: Term ID */
$handler->display->display_options['relationships']['tid']['id'] = 'tid';
$handler->display->display_options['relationships']['tid']['table'] = 'simplenews_subscription';
$handler->display->display_options['relationships']['tid']['field'] = 'tid';
/* Relationship: User: Profile */
$handler->display->display_options['relationships']['profile']['id'] = 'profile';
$handler->display->display_options['relationships']['profile']['table'] = 'users';
$handler->display->display_options['relationships']['profile']['field'] = 'profile';
$handler->display->display_options['relationships']['profile']['relationship'] = 'uid';
/* Relationship: Simplenews category: Term ID */
$handler->display->display_options['relationships']['tid_1']['id'] = 'tid_1';
$handler->display->display_options['relationships']['tid_1']['table'] = 'simplenews_category';
$handler->display->display_options['relationships']['tid_1']['field'] = 'tid';
$handler->display->display_options['relationships']['tid_1']['relationship'] = 'tid';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'uid';
/* Field: Simplenews subscription: Term ID */
$handler->display->display_options['fields']['tid']['id'] = 'tid';
$handler->display->display_options['fields']['tid']['table'] = 'simplenews_subscription';
$handler->display->display_options['fields']['tid']['field'] = 'tid';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['relationship'] = 'uid';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'admin/people/simplenews/subscriptions';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Users Subscriptions';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;

Comments

jippie1948’s picture

Thanks for this suggestion. You provided me with a view that I could use to make 'membership' lists of subscribers to a particular newsletter.

portulaca’s picture

I did it with Subscriber views, so basically simply continue editing the views you mention above.

Add the Relationship "Simplenews subscription: Term ID" (it will probably be labeled "Term (newsletter series)"). Then under Fields or Filters add "Taxonomy Term: Name" and it will probably already come with the Relationship "Term (newsletter series)" selected, because it won't work without it.

You will now see the category name appear in your views results, or the filter field (I exposed it) above the results.

The only thing that is bothering me is I can't get the exposed filter to display as a list, it only shows the textfield.

EDIT:
I was able to get the Exposed filter to display as a drop-down list instead of an autocomplete field by using the "Taxonomy term: Term" field that has this text in the description: "Taxonomy term chosen from autocomplete or select widget." and then choosing the "Dropdown" instead of "Autocomplete" in the filter settings.

ressa’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev

In a related task, I needed to find users without a subscription, and ended up using Aggregation to count the number of subscriptions, and listed them at the top:

uuid: 12851ec7-1fe0-477e-87d7-9e2c62c5d752
langcode: en
status: true
dependencies:
  module:
    - simplenews
id: simplenews_status
label: 'Subscription status'
module: views
description: ''
tag: ''
base_table: simplenews_subscriber
base_field: id
display:
  default:
    id: default
    display_title: Default
    display_plugin: default
    position: 0
    display_options:
      title: 'Subscription status'
      fields:
        user_name:
          id: user_name
          table: simplenews_subscriber
          field: user_name
          relationship: none
          group_type: group
          admin_label: ''
          entity_type: simplenews_subscriber
          plugin_id: simplenews_user_name
          label: User name
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: true
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
        edit_simplenews_subscriber:
          id: edit_simplenews_subscriber
          table: simplenews_subscriber
          field: edit_simplenews_subscriber
          relationship: none
          group_type: group
          admin_label: ''
          entity_type: simplenews_subscriber
          plugin_id: entity_link_edit
          label: Edit
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: true
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          text: edit
          output_url_as_text: false
          absolute: false
        subscriptions_target_id:
          id: subscriptions_target_id
          table: simplenews_subscriber__subscriptions
          field: subscriptions_target_id
          relationship: none
          group_type: count
          admin_label: ''
          entity_type: simplenews_subscriber
          entity_field: subscriptions
          plugin_id: field
          label: Antal
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: target_id
          type: entity_reference_label
          settings:
            link: true
          group_column: target_id
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          set_precision: false
          precision: 0
          decimal: .
          format_plural: 0
          format_plural_string: !!binary MQNAY291bnQ=
          prefix: ''
          suffix: ''
        subscriptions_target_id_1:
          id: subscriptions_target_id_1
          table: simplenews_subscriber__subscriptions
          field: subscriptions_target_id
          relationship: none
          group_type: group
          admin_label: ''
          entity_type: simplenews_subscriber
          entity_field: subscriptions
          plugin_id: field
          label: Subscriptions
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: true
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: target_id
          type: entity_reference_label
          settings:
            link: true
          group_column: entity_id
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
        mail:
          id: mail
          table: simplenews_subscriber
          field: mail
          relationship: none
          group_type: group
          admin_label: ''
          entity_type: null
          entity_field: mail
          plugin_id: field
          label: E-mail
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: true
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: basic_string
          settings: {  }
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
      pager:
        type: mini
        options:
          offset: 0
          pagination_heading_level: h4
          items_per_page: 10
          total_pages: null
          id: 0
          tags:
            next: ››
            previous: ‹‹
          expose:
            items_per_page: false
            items_per_page_label: 'Number of elements'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
      exposed_form:
        type: basic
        options:
          submit_button: Execute
          reset_button: false
          reset_button_label: Restore
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      access:
        type: none
        options: {  }
      cache:
        type: tag
        options: {  }
      empty: {  }
      sorts:
        subscriptions_target_id:
          id: subscriptions_target_id
          table: simplenews_subscriber__subscriptions
          field: subscriptions_target_id
          relationship: none
          group_type: count
          admin_label: ''
          entity_type: simplenews_subscriber
          entity_field: subscriptions
          plugin_id: standard
          order: ASC
          expose:
            label: Subscriptions
            field_identifier: count
          exposed: false
      arguments: {  }
      filters: {  }
      style:
        type: table
        options:
          grouping: {  }
          row_class: ''
          default_row_class: true
          columns:
            user_name: user_name
            subscriptions_target_id: subscriptions_target_id
            mail: mail
          default: '-1'
          info:
            user_name:
              sortable: false
              default_sort_order: asc
              align: ''
              separator: ''
              empty_column: false
              responsive: ''
            subscriptions_target_id:
              sortable: true
              default_sort_order: asc
              align: ''
              separator: ''
              empty_column: false
              responsive: ''
            mail:
              sortable: true
              default_sort_order: asc
              align: ''
              separator: ''
              empty_column: false
              responsive: ''
          override: true
          sticky: false
          summary: ''
          empty_table: false
          caption: ''
          description: ''
      row:
        type: fields
      query:
        type: views_query
        options:
          query_comment: ''
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_tags: {  }
      relationships: {  }
      group_by: true
      header: {  }
      footer: {  }
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url.query_args
      tags: {  }
  page_1:
    id: page_1
    display_title: Page
    display_plugin: page
    position: 1
    display_options:
      display_extenders:
        metatag_display_extender:
          metatags: {  }
          tokenize: false
      path: admin/simplenews-status
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url.query_args
      tags: {  }