Drupal 7 - 具有关系和过滤器问题的视图
Posted
技术标签:
【中文标题】Drupal 7 - 具有关系和过滤器问题的视图【英文标题】:Drupal 7 - Views with Relationship and Filters issue 【发布时间】:2015-09-08 19:35:38 【问题描述】:我想创建一个视图,显示组中的所有用户(在本例中为角色)以及他们在设定日期的帖子计数。我还需要它来显示尚未发布的用户。只要没有设置过滤器,我就可以让它工作。一旦我在节点上添加日期过滤器或分类术语过滤器之一,它就会停止显示未在该日期内发布或使用这些术语的用户。
当前视图是一个用户类型的视图,并且关系设置为用户:内容创作并且要求这个关系没有被选中。
当前视图导出:
$view = new view();
$view->name = 'posts_by_group';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Posts by Group';
$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'] = 'Posts by Group';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$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'] = '20';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'name' => 'name',
'nid' => 'nid',
);
$handler->display->display_options['style_options']['default'] = 'nid';
$handler->display->display_options['style_options']['info'] = array(
'name' => array(
'sortable' => 1,
'default_sort_order' => 'desc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'nid' => array(
'sortable' => 1,
'default_sort_order' => 'desc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
);
$handler->display->display_options['style_options']['empty_table'] = TRUE;
/* Relationship: User: Content authored */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'users';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
/* 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']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['name']['empty'] = '0';
$handler->display->display_options['fields']['name']['empty_zero'] = TRUE;
$handler->display->display_options['fields']['name']['hide_alter_empty'] = FALSE;
/* Field: COUNT(DISTINCT Content: Nid) */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['relationship'] = 'uid';
$handler->display->display_options['fields']['nid']['group_type'] = 'count_distinct';
$handler->display->display_options['fields']['nid']['label'] = '# of Posts';
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nid']['empty'] = '0';
$handler->display->display_options['fields']['nid']['hide_alter_empty'] = FALSE;
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: User: Roles */
$handler->display->display_options['filters']['rid']['id'] = 'rid';
$handler->display->display_options['filters']['rid']['table'] = 'users_roles';
$handler->display->display_options['filters']['rid']['field'] = 'rid';
$handler->display->display_options['filters']['rid']['value'] = array(
15 => '15',
);
/* Filter criterion: Date: Date (node) */
$handler->display->display_options['filters']['date_filter']['id'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['table'] = 'node';
$handler->display->display_options['filters']['date_filter']['field'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['relationship'] = 'uid';
$handler->display->display_options['filters']['date_filter']['operator'] = '>=';
$handler->display->display_options['filters']['date_filter']['exposed'] = TRUE;
$handler->display->display_options['filters']['date_filter']['expose']['operator_id'] = 'date_filter_op';
$handler->display->display_options['filters']['date_filter']['expose']['label'] = 'Start Date';
$handler->display->display_options['filters']['date_filter']['expose']['operator'] = 'date_filter_op';
$handler->display->display_options['filters']['date_filter']['expose']['identifier'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['expose']['required'] = TRUE;
$handler->display->display_options['filters']['date_filter']['expose']['remember'] = TRUE;
$handler->display->display_options['filters']['date_filter']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
10 => 0,
11 => 0,
12 => 0,
13 => 0,
14 => 0,
15 => 0,
22 => 0,
16 => 0,
20 => 0,
17 => 0,
18 => 0,
19 => 0,
23 => 0,
21 => 0,
24 => 0,
25 => 0,
);
$handler->display->display_options['filters']['date_filter']['form_type'] = 'date_popup';
$handler->display->display_options['filters']['date_filter']['default_date'] = 'now -30 days';
$handler->display->display_options['filters']['date_filter']['date_fields'] = array(
'node.created' => 'node.created',
);
/* Filter criterion: Date: Date (node) */
$handler->display->display_options['filters']['date_filter_1']['id'] = 'date_filter_1';
$handler->display->display_options['filters']['date_filter_1']['table'] = 'node';
$handler->display->display_options['filters']['date_filter_1']['field'] = 'date_filter';
$handler->display->display_options['filters']['date_filter_1']['relationship'] = 'uid';
$handler->display->display_options['filters']['date_filter_1']['operator'] = '<=';
$handler->display->display_options['filters']['date_filter_1']['exposed'] = TRUE;
$handler->display->display_options['filters']['date_filter_1']['expose']['operator_id'] = 'date_filter_1_op';
$handler->display->display_options['filters']['date_filter_1']['expose']['label'] = 'End Date';
$handler->display->display_options['filters']['date_filter_1']['expose']['operator'] = 'date_filter_1_op';
$handler->display->display_options['filters']['date_filter_1']['expose']['identifier'] = 'date_filter_1';
$handler->display->display_options['filters']['date_filter_1']['expose']['required'] = TRUE;
$handler->display->display_options['filters']['date_filter_1']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
10 => 0,
11 => 0,
12 => 0,
13 => 0,
14 => 0,
15 => 0,
22 => 0,
16 => 0,
20 => 0,
17 => 0,
18 => 0,
19 => 0,
23 => 0,
21 => 0,
24 => 0,
25 => 0,
);
$handler->display->display_options['filters']['date_filter_1']['form_type'] = 'date_popup';
$handler->display->display_options['filters']['date_filter_1']['default_date'] = 'now';
$handler->display->display_options['filters']['date_filter_1']['date_fields'] = array(
'node.created' => 'node.created',
);
/* Filter criterion: Content: Sponsor (field_sponsor) */
$handler->display->display_options['filters']['field_sponsor_tid']['id'] = 'field_sponsor_tid';
$handler->display->display_options['filters']['field_sponsor_tid']['table'] = 'field_data_field_sponsor';
$handler->display->display_options['filters']['field_sponsor_tid']['field'] = 'field_sponsor_tid';
$handler->display->display_options['filters']['field_sponsor_tid']['relationship'] = 'uid';
$handler->display->display_options['filters']['field_sponsor_tid']['value'] = array(
0 => '54',
);
$handler->display->display_options['filters']['field_sponsor_tid']['reduce_duplicates'] = TRUE;
$handler->display->display_options['filters']['field_sponsor_tid']['vocabulary'] = 'sponsor';
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'posts-by-group';
【问题讨论】:
【参考方案1】:您尝试过滤的字段将需要该关系。
【讨论】:
对,但是有没有办法显示这些字段,即使帖子计数为 0?日期似乎是杀死它的原因。我得到组中的用户列表和帖子计数,然后添加日期后,它会删除所有未在该范围内发布的人。我希望他们留下来。 这是因为视图构建了它的查询。我建议打开Show SQL query
,这样您就可以更好地了解正在发生的事情。一些很好的解释,以及如何更改查询here。他们谈论hook_views_pre_execute
,但也有hook_views_post_execute
和hook_views_alter
。
感谢您的信息!我会看看并报告。以上是关于Drupal 7 - 具有关系和过滤器问题的视图的主要内容,如果未能解决你的问题,请参考以下文章
具有默认值上下文过滤器的 Drupal 7 视图块不会在页面上过滤(Mongo)
如果未定义第二个过滤器,则具有 2 个上下文过滤器的 Drupal 7 视图不起作用
Drupal:如何在具有来自外部数据库选项卡的数据的视图中添加公开过滤器