Hello,

Would it be possible to limit the number of relationships (Friends) a user can have by role type?

For example:
If user1 has role type A, then user1 can have a maximum of 5 Friends (approved and pending) at any one time.
user1 can remove a Friend or cancel a pending request in order to send a new request, but maximum of 5 at any given time.

I would greatly appreciate if someone can take a look at this scenario is see if it would be possible.

Thank you very much in advance.

Comments

alex.k’s picture

Hi, there's nothing in UR preventing this possibility, but it would have to be a custom addition to the module.

mrf’s picture

Status: Active » Needs work
StatusFileSize
new3.11 KB

I am working on a project where I needed this functionality as well. I've attached my progress so far.

I'm running into one problem that has me stuck. Using the user relationships API how can I stop the current initiated request and give the user an error message? I'm able to output an error message correctly (line 44 of the module), but the request still goes through the system as if nothing happened. I've tried out both 'presave' and 'request' but neither option seems to allow me to stop the request.

Any help would be much appreciated.

YK85’s picture

It would be awesome to be able to "limit the number of pending requests at any give time to x" as well.
I look forward to your work!

mrf’s picture

StatusFileSize
new3.2 KB

Hi yaz, I think that limiting the number of pending requests could definitely be useful. Right now I can't think of a good way to add that functionality in without confusing the user about what this module does. Would you expect the pending requests to be counted in the total number of requests (in the current version they are), or would this be a separate number that didn't affect the total number of allowed relationships?

I came up with a solution to my problem in #2, and new requests are now aborted if you have hit your limit.

Anyone that is interested, please try out the module and let me know if you come across any issues.

mrf’s picture

Status: Needs work » Needs review
YK85’s picture

hi mrf,

I will definitely test out your module this weekend and will report back with any issues if I come across any. I think the name of your custom module "user_relationship_limits" is great and covers all aspects.

Below are some features that I think would be great:
1) limit for total number of approved relationships a user can have (by role) <= i believe you already have this
2) limit for total number of pending requests sent
3) limit for total number of pending requests received
4) limit for total number of pending requests sent and received (sent and received requests combined at any given time, choosing this should disable 2 and 3 above)

For the above, allowing admin to choose a # or unlimited for each setting would be great!
I hope you will be further developing your custom module and look forward to following your work.

Thank you

introfini’s picture

subscribing

artscoop’s picture

Hi,
Saving the settings form does not work with the module provided in #4, because of the db_rewrite_sql scattered in the code.
Removing them is ok, but it won't prevent anything from happening (I use the JS popup).

Well, I found some other errors in the code, I'm just going to give the correct code with the lines :
Circa line 31 :
if ($max_limit == 0) {
At this line the inner code block was never executed.

Circa line 42 :
if($rel_number >= $max_limit) {
At this line the code said that if you want 11 relations max you will have 12 available.

artscoop’s picture

StatusFileSize
new2.39 KB

Well folks, here is the gz file.

mrf’s picture

StatusFileSize
new5.56 KB

Thanks for taking a look artscoop.

I made one more change. On line 31 the check was meant to skip the sorting if we had already set $max_limit to unlimited value of 0 in line 27. I feel like the logic with unlimited relationships is convoluted and welcome any suggestions to make handling the unlimited possibility more clear.

Here's the module with that change made to line 31.

alex.k’s picture

StatusFileSize
new5.75 KB

That's a nice implementation of this feature. I took the liberty of simplifying the check for unlimited per your comment above, pls have a look at the attached. The change is all in user_relationship_limits_user_relationships.

I would suggest you host it as a stand-alone module rather than include in UR proper. It will make things easier as far as managing the issue queue and also the UR package won't grow too big with so many additional modules that not all sites need.

mrf’s picture

Status: Needs review » Closed (fixed)

I followed alex's suggestion and created a new project for this module. I'll be putting up the first dev release soon. Feel free to submit any additional patches or related feature requests over there.

http://drupal.org/project/user_relationship_limits

alex.k’s picture

Great, let me know when you are ready and i will add a link to your module.