开发者

Drupal 6, Views 2: Is it possible to have a filter that only applies to registered users?

Is it possible to create a filter in a Drupal 6 View tha开发者_如何学Ct is only applied for registered users?

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.

Thanks a lot in advance for the help!


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.

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;

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜