Drupal 6, Views 2: Is it possible to have a filter

2019-06-27 09:40发布

Is it possible to create a filter in a Drupal 6 View that 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!

1条回答
小情绪 Triste *
2楼-- · 2019-06-27 10:03

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.

查看更多
登录 后发表回答