3

Background

I want to add a tab to the user profile that shows the logged in user which other users have viewed his/her profile. I want to control this list in Views.

Until recently, I have been using the User Visits module. However, this module does not integrate with Views and is no longer actively maintained.

I started building this using Views, Rules, and Flag. Specifically, I created a flag Viewed profile, and then made a Rule to automatically flag a profile when a user visits another user's profile.

I then created a view of users with two displays.

My View

The first display, Profiles I visited, has a relationship to the Viewed profile flag and simply lists all profiles flagged (visited) by the current user. Easy.

Now I want to create a second display, Users who have visited me. In this case, I want to display all the users who have flagged the current user. However, I can't figure out how to do this.

I can add a relationship, Flags (by any user), but there could quickly be 10,000+ such flags on my site, so I am worried about the performance implications of loading all the flags like that. Also, even if I load all the flags, I don't see how to easily filter them to users who have flagged the current user.

Instead, it seems like it would be easier to create a second flag, User who viewed me, and attach both flags (Viewed profile and User who viewed me) with a rule at the same time when a user visits a profile. However, this seems like unnecessary duplication of information to me, since both flags link the same two users at the same time. Is there a more elegant way to display this data in Views that will not lead to performance issues down the line?

0
  1. Add a relationship, Flags: User's flaggings for your flag. Uncheck Include only users who have flagged content.
  2. Add a contextual filter, Flags: Content ID and set Provide default value to User ID from logged in user.

This was not intuitive, but it appears to do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.