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

夙愿已清 提交于 2019-12-14 03:47:44

问题


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:


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.



来源:https://stackoverflow.com/questions/2598986/drupal-6-views-2-is-it-possible-to-have-a-filter-that-only-applies-to-register

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!