开发者

Get a view with users who flagged me?

开发者 https://www.devze.com 2023-02-08 14:28 出处:网络
i\'m using views and flags modules. Users can flag开发者_StackOverflow社区 users. I could easily create a list of users i\'ve flagged. But I cannot create a view with users, who flagged me.I tried thi

i'm using views and flags modules. Users can flag开发者_StackOverflow社区 users. I could easily create a list of users i've flagged. But I cannot create a view with users, who flagged me.


I tried this out with a very simply Drupal install... just Core, Views 2 and Flags.

You can in fact do this. I created a Flag called flag_user_test and 3 test accounts plus admin. I flagged the admin account using the other test accounts and was able to get this list of users to display using the user id as an argument, defaulting to currently logged in user.

First, create the view to be of type User (not Node).

Next, you need to create a relationship with "Flags: User's flagged content" and select the user flag on the settings for the relationship. I did not select "Include only users who have flagged content".

Then, create an Argument using the "Flags: Content ID" type. Set this argument to use the "user flagged content" relationship you defined in the last step. I also provided the default argument to be the User ID of the currently logged in user.

Now just add the fields you want from the user profile and your done!

Get a view with users who flagged me?

And here's an export of the view if you want to try it out. It looks really awful right there I know. But I don't know how to include it as an attachment, so that's the best I can do. If anyone knows how to make that code block look better, be my guest.

$view = new view; $view->name = 'flag_me_view'; $view->description = 'User\'s who flagged me'; $view->tag = ''; $view->view_php = ''; $view->base_table = 'users'; $view->is_cacheable = FALSE; $view->api_version = 2; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ $handler = $view->new_display('default', 'Defaults', 'default'); $handler->override_option('relationships', array( 'flag_user_content_rel' => array( 'label' => 'user flagged content', 'required' => 0, 'flag' => 'flag_user_test', 'id' => 'flag_user_content_rel', 'table' => 'users', 'field' => 'flag_user_content_rel', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), )); $handler->override_option('fields', array( 'name' => array( 'label' => 'Name', 'alter' => array( 'alter_text' => 0, 'text' => '', 'make_link' => 0, 'path' => '', 'link_class' => '', 'alt' => '', 'prefix' => '', 'suffix' => '', 'target' => '', 'help' => '', 'trim' => 0, 'max_length' => '', 'word_boundary' => 1, 'ellipsis' => 1, 'html' => 0, 'strip_tags' => 0, ), 'empty' => '', 'hide_empty' => 0, 'empty_zero' => 0, 'link_to_user' => 1, 'overwrite_anonymous' => 0, 'anonymous_text' => '', 'exclude' => 0, 'id' => 'name', 'table' => 'users', 'field' => 'name', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), 'picture' => array( 'label' => 'Picture', 'alter' => array( 'alter_text' => 0, 'text' => '', 'make_link' => 0, 'path' => '', 'link_class' => '', 'alt' => '', 'prefix' => '', 'suffix' => '', 'target' => '', 'help' => '', 'trim' => 0, 'max_length' => '', 'word_boundary' => 1, 'ellipsis' => 1, 'html' => 0, 'strip_tags' => 0, ), 'empty' => '', 'hide_empty' => 0, 'empty_zero' => 0, 'exclude' => 0, 'id' => 'picture', 'table' => 'users', 'field' => 'picture', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), )); $handler->override_option('arguments', array( 'content_id' => array( 'default_action' => 'default', 'style_plugin' => 'default_summary', 'style_options' => array(), 'wildcard' => 'all', 'wildcard_substitution' => 'All', 'title' => '', 'breadcrumb' => '', 'default_argument_type' => 'current_user', 'default_argument' => '', 'validate_type' => 'none', 'validate_fail' => 'not found', 'break_phrase' => 0, 'not' => 0, 'id' => 'content_id', 'table' => 'flag_content', 'field' => 'content_id', 'relationship' => 'flag_user_content_rel', 'validate_user_argument_type' => 'uid', 'validate_user_roles' => array( '2' => 0, ), 'override' => array( 'button' => 'Override', ), 'default_options_div_prefix' => '', 'default_argument_fixed' => '', 'default_argument_user' => 0, 'default_argument_php' => '', 'validate_argument_node_type' => array( 'page' => 0, 'story' => 0, ), 'validate_argument_node_access' => 0, 'validate_argument_nid_type' => 'nid', 'validate_argument_vocabulary' => array(), 'validate_argument_type' => 'tid', 'validate_argument_transform' => 0, 'validate_user_restrict_roles' => 0, 'validate_argument_node_flag_name' => 'relationship', 'validate_argument_node_flag_test' => 'flaggable', 'validate_argument_node_flag_id_type' => 'id', 'validate_argument_user_flag_name' => 'relationship', 'validate_argument_user_flag_test' => 'flaggable', 'validate_argument_user_flag_id_type' => 'id', 'validate_argument_php' => '', ), )); $handler->override_option('filters', array( 'flagged' => array( 'operator' => '=', 'value' => '1', 'group' => '0', 'exposed' => FALSE, 'expose' => array( 'operator' => FALSE, 'label' => '', ), 'id' => 'flagged', 'table' => 'flag_content', 'field' => 'flagged', 'relationship' => 'flag_user_content_rel', 'override' => array( 'button' => 'Override', ), ), )); $handler->override_option('access', array( 'type' => 'none', )); $handler->override_option('cache', array( 'type' => 'none', )); $handler = $view->new_display('page', 'Page', 'page_1'); $handler->override_option('path', 'flagged'); $handler->override_option('menu', array( 'type' => 'none', 'title' => '', 'description' => '', 'weight' => 0, 'name' => 'navigation', )); $handler->override_option('tab_options', array( 'type' => 'none', 'title' => '', 'description' => '', 'weight' => 0, 'name' => 'navigation', ));

0

精彩评论

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