Drupal 6,视图2:是否有可能只适用于注册用户的过滤器? [英] Drupal 6, Views 2: Is it possible to have a filter that only applies to registered users?

查看:222
本文介绍了Drupal 6,视图2:是否有可能只适用于注册用户的过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在仅适用于注册用户的Drupal 6视图中创建过滤器?

Is it possible to create a filter in a Drupal 6 View that is only applied for registered users?

对于一个过滤器,我需要使用用户投票(使用fivestar和votingapi)来知道用户是否已经投票了该节点,而当用户是匿名,正在从所有的匿名用户的所有投票一样工作。这就是为什么我需要添加此过滤器,但是如果用户是匿名的,则忽略它。

For one filter I need I'm using the user vote (With fivestar and votingapi) to know if they user already voted this node or not, and when the user is annonymous, is working as if all the votes from all the annonymous users where from the same. This is why I need to add this filter, but ignore it in case the user is annonymous.

非常感谢您的帮助!

推荐答案

如果您对php感到满意,请下载Views PHP Filter模块( http://drupal.org/project/viewsphpfilter )。此模块允许您轻松地为任何视图编写自己的自定义过滤器。

If you're comfortable with php, download the Views PHP Filter module (http://drupal.org/project/viewsphpfilter). This module allows you to easily write your own custom filters for any view.

下载并启用该模块后,创建一个新视图并添加Node:Node ID PHP处理器过滤器。现在您可以为所需的任何过滤器添加自定义PHP代码。也许是这样的:

After downloading and enabling the module, create a new view and add a "Node: Node ID PHP handler" filter. Now you can add custom php code for any filter you want. Perhaps something like:

global $user;
$allowed = array('authenticated user');
foreach ($user->role as $role) {
  if (in_array($role, $allowed)) {
    $nids = //Run custom filter query for allowed users
  }
  else {
    $nids = //Run alternate filter query for anonymous users 
  }
}
return $nids;

代码应该返回要显示的节点ID列表。

The code should return a list of node ids to display.

这篇关于Drupal 6,视图2:是否有可能只适用于注册用户的过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆