I am trying to use condition Check if two users are related and action User account page is viewed on rules. I need to redirect users to another page if users don't have 'Friends' relationships. And have two troubles
1 - If user go to another user profile - drupal throw Notices
Notice: Trying to get property of non-object in user_relationships_rules_condition_users_are_related() (line 211 of /home/sharednu/public_html/sites/all/modules/user_relationships/user_relationships_rules/user_relationships_rules.rules.inc).
Notice: Undefined property: RulesCondition::$uid in user_relationships_rules_condition_users_are_related() (line 211 of /home/sharednu/public_html/sites/all/modules/user_relationships/user_relationships_rules/user_relationships_rules.rules.inc).
Also in $relationship_types variable stored 'execute' string, but as I saw in code, there must be rid of allowable relationships
2 - I need to select, what types of relationships must between users to views profile, but don't know how to set it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ohthehugemanatee’s picture

Seconding this. I'm trying to set up to kinds of relationships.

* "Fan" - one way, no confirmation
* "Buddies" - two way, no confirmation

Trying to set up a rule that fires on relationship request. It should check to see if Requestee is a "fan" of Requestor, and then create a "buddy" relationship between them.

But when I "fan" someone, I get

Notice: Trying to get property of non-object in user_relationships_rules_condition_users_are_related() (line 211 of /mnt/srv/www/sites/all/modules/user_relationships/user_relationships_rules/user_relationships_rules.rules.inc). Backtrace:
user_relationships_rules_condition_users_are_related(Array, Object, 'execute') 
call_user_func_array('user_relationships_rules_condition_users_are_related', Array) faces.inc:123
FacesExtendable->__call('execute', Array) rules.core.inc:293
RulesExtendable->__call('execute', Array) rules.plugins.inc:96
RulesCondition->executeCallback(Array, Object) rules.core.inc:1483
RulesAbstractPlugin->evaluate(Object) rules.plugins.inc:466
RulesAnd->evaluate(Object) rules.plugins.inc:466
RulesAnd->evaluate(Object) rules.plugins.inc:214
Rule->evaluate(Object) rules.plugins.inc:387
RulesReactionRule->evaluate(Object) rules.core.inc:2113
RulesActionContainer->evaluate(Object) rules.plugins.inc:684
RulesEventSet->executeByArgs(Array) rules.module:777
rules_invoke_event('user_relationships_request', Object, Object, Object) user_relationships_rules.module:10
user_relationships_rules_user_relationships_save(Object, 'request') 
call_user_func_array('user_relationships_rules_user_relationships_save', Array) module.inc:818
module_invoke_all('user_relationships_save', Object, 'request') user_relationships.module:628
user_relationships_save_relationship(Object) user_relationships.module:559
user_relationships_request_relationship(Object) user_relationships_ui.actions.inc:109
user_relationships_ui_request_submit(Array, Array) form.inc:1430
form_execute_handlers('submit', Array, Array) form.inc:844
drupal_process_form('user_relationships_ui_request', Array, Array) form.inc:364
drupal_build_form('user_relationships_ui_request', Array) form.inc:123
drupal_get_form('user_relationships_ui_request', Object) user_relationships_ui.forms.inc:67
user_relationships_ui_request_ajax(Object, '1') 
call_user_func_array('user_relationships_ui_request_ajax', Array) menu.inc:503
menu_execute_active_handler() index.php:21

Notice: Undefined property: RulesCondition::$uid in user_relationships_rules_condition_users_are_related() (line 211 of /mnt/srv/www/sites/all/modules/user_relationships/user_relationships_rules/user_relationships_rules.rules.inc). Backtrace:
user_relationships_rules_condition_users_are_related(Array, Object, 'execute') 
call_user_func_array('user_relationships_rules_condition_users_are_related', Array) faces.inc:123
FacesExtendable->__call('execute', Array) rules.core.inc:293
RulesExtendable->__call('execute', Array) rules.plugins.inc:96
RulesCondition->executeCallback(Array, Object) rules.core.inc:1483
RulesAbstractPlugin->evaluate(Object) rules.plugins.inc:466
RulesAnd->evaluate(Object) rules.plugins.inc:466
RulesAnd->evaluate(Object) rules.plugins.inc:214
Rule->evaluate(Object) rules.plugins.inc:387
RulesReactionRule->evaluate(Object) rules.core.inc:2113
RulesActionContainer->evaluate(Object) rules.plugins.inc:684
RulesEventSet->executeByArgs(Array) rules.module:777
rules_invoke_event('user_relationships_request', Object, Object, Object) user_relationships_rules.module:10
user_relationships_rules_user_relationships_save(Object, 'request') 
call_user_func_array('user_relationships_rules_user_relationships_save', Array) module.inc:818
module_invoke_all('user_relationships_save', Object, 'request') user_relationships.module:628
user_relationships_save_relationship(Object) user_relationships.module:559
user_relationships_request_relationship(Object) user_relationships_ui.actions.inc:109
user_relationships_ui_request_submit(Array, Array) form.inc:1430
form_execute_handlers('submit', Array, Array) form.inc:844
drupal_process_form('user_relationships_ui_request', Array, Array) form.inc:364
drupal_build_form('user_relationships_ui_request', Array) form.inc:123
drupal_get_form('user_relationships_ui_request', Object) user_relationships_ui.forms.inc:67
user_relationships_ui_request_ajax(Object, '1') 
call_user_func_array('user_relationships_ui_request_ajax', Array) menu.inc:503
menu_execute_active_handler() index.php:21

This says to me that the Requestor and Requestee variables which seem to be automatically set in the Rule are not working properly.

ohthehugemanatee’s picture

Note: if I remove the Users are related test, the rule works perfectly.

fehin’s picture

I'm getting this error message too whenever i use the condition.

DrupalDesigner-1’s picture

+ 1

DevJoshLopez’s picture

+ 1

Tritof’s picture

+ 1

de_chris’s picture

subscribe
There are also several other issues out there related to profile privacy based on user relationships, e.g. http://drupal.org/node/1774902. Unfortunaltely there is no official solution for this request.
My prefered solution would be to let the user account act as some kind of private database since there are modules (e.g. fboauth) out there which allow to import user data from social media. Furthermore I would like to use profile2 to generate one profile for each kind of user relationship. And for the ease of use I would like to give the user the chance to enable an exchange relation for data between the different profiles. He may also leave field on single profiles blank or enter different information.

Example:
user x can import name and age from facebook to his account
he can then set the relation for the name and age field of his account and the name and age field of his family profile, this profile is only visible to user with family relation
this makes it also necessary to set hierarchic relations between the profiles
advantage: detailed access on how my profile is displayed for each user
disadvantage: complicated and all the stuff related to duplicated content

so for a first version I would be very convenient if I could set restrictions to account fields or profile fields

afranioce’s picture

Version: 7.x-1.0-alpha3 » 7.x-1.0-alpha5
FileSize
1.41 KB

I also had the same problem, so I could solve by changing the function user_relationships_rules_condition_users_are_related.

kansaj’s picture

Hi,

Actually I'm not sure if my contribution will suitable, but I found that this rule is a bit of mess or not actually what I was imagining. I though that if two users are related by specific relation/s it should work, but not for me. I modified a bit the code to

'user_relationships_rules_condition_users_are_related' => array(
      'label' => t('Check if two users are related'),
      'named parameter' => TRUE,
      'parameter' => array(
        'user1' => array('type' => 'user', 'label' => t('User A')),
        'user2' => array('type' => 'user', 'label' => t('User B')),
        'relationship_type' => array(
          'type' => 'list<integer>',
          'label' => t('Relationship type'),
          'options list' => 'user_relationships_rules_types_list',
        ),
      ),
      'group' => t('Relationships'),
    ),
-----
function user_relationships_rules_condition_users_are_related($settings) {
  // Get the approved relationships between the two users and the specified
  // relationship types.
$args = array(
    'user_a' => $settings['user1'] instanceof EntityDrupalWrapper ? $settings['user1']->getIdentifier() : $settings['user1']->uid,
    'user_b' => $settings['user2'] instanceof EntityDrupalWrapper ? $settings['user2']->getIdentifier() : $settings['user2']->uid,
    'rtid' => $settings['relationship_type'],
  );
 
$relationships = user_relationships_load(array('approved' => 1, 'rtid' => $args['rtid'], 'between' => array($args['user_a'],$args['user_b'])));

if(!empty($relationships)) { return TRUE;}

}
scottsawyer’s picture

Issue summary: View changes

@kansaj, your mod seems to work so far as adding the relationship type on the rule, but I have two questions:

  1. There seems to be another condition available "Relationship has type"
  2. This may require another issue, but I can not get this rule to pass for event "After saving new user account".

I am using UR Invite and have a role I wish to give to a new user based on the relationship type from the inviter. My rule looks like this:

Event:
"After saving new user account"
Condition:
"Check if two users are related"
Action:
"Add user role"

The inviter sends the invite selecting the relationship type. The new user clicks the invite link and registers. In user/uid/relationships, the relationship exists. However, whenever the rule fires, it always fails at the condition.

This is probably more of a Rules question, but I wonder if the relationship does not exist until after the saving of a new user account event fires.

I have also tried to use the Event "A user relationship has been approved", but then the rule never fires. ( this relationship does not need to be approved. ).

Any thoughts or experience is appreciated.

fraweg’s picture

Hi scottsawyer,

did you solve the issue? and if... how?

Best regards
Frank

@ kansaj is this an export of the rule ?

Patch #8 seems to work for me... thanks a lot!