Two way of one-way relationship

miscellanea - December 17, 2008 - 05:14
Project:User Relationships
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:alex.k
Status:closed
Description

I want to add a relationship teacher on my site.
Sometimes A is a teacher of B in some areas and B is a teacher of A in other areas.
I find no way to indicate this relationship when I use one-way relationship.
In one-way relationship, If A is a teacher of B, A can not add B as its teacher.
So I ask a feature if A can add B as its teacher even if A is a teacher of B.

#1

mtsanford - December 17, 2008 - 06:33

I agree.

Somebody recently posted a patch to do that I believe:

http://drupal.org/node/346305

But I haven't checked it out.

#2

icarus75 - December 17, 2008 - 17:57
Version:6.x-1.x-dev» 6.x-1.0-beta9
Component:User interface» Code
Category:feature request» bug report
Status:active» needs review

Here's a patch against UR 6.x-1.0-beta9 which should allow you to create two reciprocal one-way relationships. It's a D6 'port' of the patch in http://drupal.org/node/346305. I don't have a proper D6 setup for thoroughly testing the patch. So please perform some functional testing by creating/deleting 1- and 2-way relationships, including negative test cases.

Cheers,
Bart.

AttachmentSize
reciprocal-one-way-relationships-not-allowed.patch 1003 bytes

#3

a_c_m - February 27, 2009 - 14:44
Status:needs review» reviewed & tested by the community

Seems to work for me.

It might be nice however, to have the single one way relationship as an option somewhere.

#4

alex.k - April 3, 2009 - 12:05
Category:bug report» feature request
Status:reviewed & tested by the community» needs work

Agreed, it should be an option. A new column in user_relationship_types with values 0 or 1 for "singular" or "reciprocal" relationships. And the if statement in the patch would check for this flag being set in the relationship type, and doing the correct check whether to allow another relationship to be established.

#5

gunzip - April 18, 2009 - 20:06

subscribe

#6

rjbrown99 - May 13, 2009 - 07:23

This moved to line 173 in the latest dev code, but the patch is the same. Tested successfully, user A subscribes to user B. Later, user B can subscribe to user A (or not). This works out in views as well, which is cool. Exactly what I need and I am +1 for including this in the core module. Thanks!

#7

rjbrown99 - May 31, 2009 - 16:37
Status:needs work» needs review

Changing status to "Needs review". The attached patch does work and I have tested on multiple instances and in a production environment. It would be ideal for this to be committed to the tree. Thanks!

#8

alex.k - May 31, 2009 - 20:04
Status:needs review» needs work

Appreciate your vote, but really the patch still needs work.
1. It won't make request links appear, even if requesting is possible, because function _user_relationships_ui_actions_between() is checking for an existing relationship of this type. This function needs to be altered similarly to the posted patch
2. Default behavior of the module should not change. There needs to be an option to turn this feature on and off.
2a. The simple way is to add an admin option at /user/relationships/settings that will control this
2b. The flexible way is what I described in #4. A column in the relationship_types table, so that this setting can be set per-type. It will also make it available to Views.
So the best way to speed up this issue is to submit a patch that takes care of 1 and 2 (a or b). (yep I know it's a lot more code than the one-liner patch being discussed... but that's what the module would need). Thanks.

#9

walker2238 - June 12, 2009 - 02:37

subscribe

#10

bengtan - July 19, 2009 - 08:15
Status:needs work» needs review

Hi,

I'm working on a site which makes use of one-way relationships such that the relationship can be in either direction OR both directions (ie. reciprocal). I think it is the same issue as the original poster, hence I'm posting here.

I have a prospective patch for others to test, and hopefully it will be accepted (optionally with some modifications).

The patch adds a 'is reciprocal' checkbox to relationships. There is a new database column added to the relevant table. (Hence, if you try this patch, please make sure you have a backup first, and make sure you run update.php - there is no easy way to reverse the effects of this patch).

I have tried to follow the directions in comments #4 and #8, but if I have misunderstood anything, please let me know. Essentially, I have done 1, 2 and 2b of #8, but there isn't a views handler for the is_reciprocal field.

Finally, this functionality was developed using an old -dev version, but the patch is against the 6.x-1.x-dev version as of 20090713. The merging of the code changes from my old -dev version to the 6.x-1.x-dev (20090713) was straightforward with no conflicts so the signs are good. However, I haven't tested as much against the 6.x-1.x-dev (20090713) version.

AttachmentSize
reciprocal-one-way-relationships-348025.patch 10.59 KB

#11

amarnus - August 4, 2009 - 07:21

Just change value of is_oneway field of the relationship type to 2 (not 1 or 0). That should work in all cases.

#12

ajayg - August 19, 2009 - 13:58

@amarnus,
Do you mean there is no need for a patch (or needs a much simpler patch) where we can just change the type to 2 and it works?

#13

amarnus - August 21, 2009 - 02:55

Yes. I am guessing it should. Of course, the patch is the more stable solution but this is simpler. Try and see.

#14

ajayg - August 21, 2009 - 13:15

@amarnus,
It does not work at all. I just tested. Why you thought it should work? IS there any code that suggest it should work?

@everybody
this is not about the patch and just simple suggestion above from amarnus. I have not yet tested patch.

#15

rjbrown99 - August 21, 2009 - 05:46

Have you tried Beng's patch? It works for me and seems to meet the initial requirements that the module author set for this feature to be added.

#16

thekayra - September 30, 2009 - 20:33

I tired Beng's patch against the latest dev.

The admin pages looks good and I get to see the extra options. However I kept getting the "You may not create any more relationships to this user." error when I tried to "reciprocate" the one-way relationship (Trying to add BtoA when AtoB already exists).

Going to try it against the RC2 or maybe beta9 to see if the patch works with them.

Anybody can confirm this please?

#17

thekayra - September 30, 2009 - 21:20

Unfortunately could not make the patch work with beta9 and beta10. I failed at some point.

Patch is ok with RC2, however I still get the same "You may not create any more relationships to this user." error.

#18

bengtan - October 1, 2009 - 02:32
Version:6.x-1.0-beta9» 6.x-1.x-dev

The patch was rolled against a -dev version of July 19th, so it should best be tried against either -rc1 or rc2.

After you've done the patch, if you edit a relationship, do you see two checkboxes like so?

o This is a one-way relationship
Check this if this relationship should only go one way (ex Manager, Subscriber)

o This one-way relationship can be reciprocated
Check if this one-way relationship can go either way

You need to configure 'This one-way relationship can be reciprocated' to suit what you are trying to do.

Also, bumping the version number to -dev since it's more accurate.

#19

thekayra - October 1, 2009 - 14:37

Hi bengtan,

The options are available. And I checked both.

When I try to test it with two different users (A and B) trying to add eachother as fans, AtoB ise fine and he adds himself as a fan of B. However, BtoA gets the infamous "You may not create any more relationships to this user." error.

It is a little bit of a silly question but, did you try it with different users as well?

#20

alex.k - October 1, 2009 - 14:45

@thekayra Is the "allow multiple relationships" checkbox also enabled in UR settings?

#21

thekayra - October 1, 2009 - 17:01

@alex.k yes it is. This was the first thing I checked.

If nobody else is running into this issue maybe my installation and/or patching is problematic. Can anybody else confirm?

#22

trupal218 - October 29, 2009 - 03:01

Hello,
I was wondering if there are plans to commit this feature to the main module?
Thanks!

#23

wargo - October 30, 2009 - 14:14

Hello,

I have the same error that comment @alex.k

#24

robatsu - November 5, 2009 - 07:31

I'm wondering if there has been any movement on this, it is a real critical issue for us? I'm available to help out to get this into production.

#25

robatsu - November 5, 2009 - 09:10

Ok, I applied the patch. Didn't work - it would present me w/a relationship action, but it would then error out when I tried to make a reciprocal action.

Anyhow, I got into the code, this worked at around line 53 in user_relationships_ui.actions.inc. Unfortunately, I don't really have the time at the moment to make a proper patch out of it, but maybe someone here would be so kind. Or maybe I will when I get the time, but I'm in a big release crunch at the moment.

Pretty simple to finish the job that bengtan started:

$test_relationships=array();
foreach($current_relationships as $key=>$value){
foreach($value as $val_rel){
if(!$val_rel->is_oneway || !$val_rel->is_reciprocal){
$test_relationships[$key]=$value;
continue;
}
if($requester->uid == $val_rel->requester_id){
$test_relationships[$key]=$value;
}
}
}
if (!db_result(db_query(
'SELECT COUNT(*) FROM {user_relationship_types}' .
($test_relationships ? ' WHERE rtid NOT IN ('. db_placeholders($test_relationships) .')' : ''),
array_keys($test_relationships)
))) {
drupal_set_message(user_relationships_ui_get_message('too_many_relationships'), 'error');
drupal_goto();
}
else if ($test_relationships[$rtid]) {
$message_name = $test_relationships[$rtid]->approved ? 'existing_relationship' : 'existing_request';
form_set_error('rtid', user_relationships_ui_get_message($message_name, NULL, array(
'!requester' => $requester->name,
'!requestee' => $requestee->name,
'%relationship_name' => $current_relationships[$rtid][0]->name,
'%relationship_plural_name' => $current_relationships[$rtid][0]->plural_name
)));
}

#26

Summit - November 5, 2009 - 09:31

Subscribing, greetings, Martijn

#27

robatsu - November 5, 2009 - 21:09

Here is a diff/patch between 6.x-1.0-rc2 and:

1) Applying the patch file reciprocal-one-way-relationships-348025.patch provided by bengtan
2) Some further mods I made to user_relationships_ui.actions.inc that seemed to have finished the job and allow the reciprocal relationship to be actually created - user_relationships_ui_request_validate was not sorting out the reciprocal relationships before testing to see if they could be created.

It is working for me (I'm happy now...), interested to hear if it works for anyone else.

AttachmentSize
reciprocal_relationships.patch 14.29 KB

#28

bengtan - November 6, 2009 - 02:41

When I developed the patch in comment #10, I wasn't using relationship actions, so it may be possible I've broken something there.

While I would like to help with this functionality, the client that I did this for has changed priorities and so, the time I can spend on this particular issue has gone dormant. Sorry.

#29

wargo - November 6, 2009 - 18:30

Hi,

I applied the patch, but i have problems with the elaborations, the jquery windows where the user can write an observation becoming narrower.
Someone has the same error??

#30

wargo - November 7, 2009 - 14:51

it was my fault, now it's working correctly.

Thanks.

#31

ajayg - November 7, 2009 - 17:33

@alex.k
The patch seems to be working. Would you review and bless it, as fitting overall architecture? It is rather large so I would not call RTBC untill you review this.

#32

alex.k - November 7, 2009 - 20:19

@ajayg I think RTBC should be set by the community, not by the maintainer.

#33

alex.k - November 7, 2009 - 21:27
Assigned to:Anonymous» alex.k
Status:needs review» fixed

Committed with only a few non-essential tweaks, http://drupal.org/cvs?commit=285586. Added a small simpletest, some comments, and a reset of the flag if a relationship type is converted to a two-way. Great stuff, thanks!!

@bengtan sorry about the delay. I guess my plan to feature-freeze UR has not worked out...

#34

System Message - November 21, 2009 - 21:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.