3

I'm running a D7 site and need some help with a view.

I've a 'Follow' Flag on every user profile which users can use to follow each other.

I'm trying to build a view where I want to see the list of users who have followed less than 5 other users.

Is this possible?

  • Is this website in development? or is this a live site? – No Sssweat Dec 9 '16 at 9:30
  • @NoSssweat it's a live site but I do have a UAT and DEV – ozyy Dec 9 '16 at 9:31
  • I was gonna suggest a solution I had in mind, but since the site is live and people have already flagged other people, it's too late to implement it. – No Sssweat Dec 9 '16 at 9:33
  • @NoSssweat I've looked at doing it through views but can't seem to find a way :( – ozyy Dec 9 '16 at 9:34
1

Well, actually it's not too late to implement if you do the following:

1) Add a following count (integer) field as a user field.

2) Go to /user/1/edit and put any number other than 1, inside of this field. (this is just a temporary place holder).

3) With PHPMyAdmin or a DB viewer program, export the following count field as a CSV file.

4) The 1 is where the USER ID goes, and the other random number is the actual following count.

So with views, create a view that shows the user ID and the following flag count number.

Then you open the exported .csv file on Excel and paste these data in the proper columns.

5) Import back into your Drupal DB and clear flush cache.

*Note: Instead of doing steps 3, 4 and 5, you could just do this with Views Bulk Operations + Rules.

6) Using the Rules module, create a rule that +1's the user following count field, when a user flags the follow flag and -1's it when they unfollow.

7) In views, in your List of Users View, for Filter, simply add the following count field and put less than 5.

8) Use the Field Permissions module to hide the following count field, that way when they edit their profile, the user cannot insert/modify the number.

  • 1
    To avoid messing with the database, you can just create a rule that loops through each users flags and increments in the field on the profile. I tested it and it works fine. Maybe the event could be "user is updated" and then use VBO to mass update every user and then delete the rule and replace it with what you've said from 7-9. – Niall Murphy Dec 9 '16 at 10:23
1

You need to create a view of users (base table: user) with the following settings:

  • Relationships:

    • Flags: User flag

      • Identifier: a meaningful name
      • Include only flagged content: checked
      • Flag: Your existing flag
      • By: Any user
    • Flags: User flag counter

      • Identifier: a meaningful name
      • Include only flagged content: checked
      • Flag: Your existing flag
  • Filter:

    • Flags: Flag counter
      • Relationship: the created flag relationship from above
      • Operator: Is less or equal to
      • Value: 5
  • Sort criteria:

    • Flags: Flag counter
      • Relationship: the created flag relationship from above
      • Sort descending: selected
  • Field:

    • Flags: Flag counter
      • Relationship: the created flag relationship from above

You can select from the "Flags: User flag" relationship between "Any user" or "Current user" to view flagged content for any user or the logged in user respectively. Basic theory on flags and views.

  • thank you very much for your input. I'll give it a try and let you know. – ozyy Dec 16 '16 at 14:00
  • @ozyy did you even try my answer? – No Sssweat Dec 22 '16 at 13:36
  • @NoSssweat I've tried your solution and it works but in reverse. So I'm getting the number of users following a user but not the number of users followed by the user. Thank you for your help though – ozyy Jan 11 '17 at 11:49
  • Then u just need to +1 the flagged user in their followers count field. – No Sssweat Jan 11 '17 at 12:27

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.