Hi,
UR seems to rock! :)
As I'm a designer, I have maybe two stupid questions:
1. I'm theming the profile and content profile templates, so I need a "add to contacts" link if users are not yet in relationship; otherwise a "remove from contacts" link.
I've found this snippet:
$mybuddy = !!($relationships = user_relationships_load(array('between' => array($user->uid, $GLOBALS['user']->uid)))) ? 1 : 0;
print($mybuddy);
Am I right that '1' should appear if users are in relationship, otherwise '0'?
When I use this snippet I always get '0', whether in relationship or not. I'm a designer, so my php skills are poor.
FYI: I use Drupal 6.10, the core profile in conjunction with content profile (6.x-1.0-beta3).
2. Sorry, if my thoughts are too poorly conceived... I have to hide some personal profile fields from users who are not in relationship.
If the snippet above works, is it possible to replace the field information with the '1' and the 'else show nothing' text with the '0'?
Or how would you realize this? If important to know: There are only cck fields to hide.
It would be so great if somebody could help me.
Thanks a lot in advance guys.
Stefan
Comments
Comment #1
MisterSpeed CreditAttribution: MisterSpeed commentedBoth the user you have compared above have same uid (as $user->uid and $GLOBALS['user']->uid returns same result) thats why it is always returning 0. Add current user id from $user as u have done and other user id for which you r checking for.
Comment #2
design.er CreditAttribution: design.er commentedHey, thanks for your reply.
I ended up with this snippets and it works fine for me. I want to post my solutions for other designers without enough php skills. Please, feel free to correct me if you think there are better ways to handle this.
Note: I use the content profile.module, so I use $node->uid instead of $account->uid. It works fine for me. And I only use 1 kind of relationship, so I use a static number (1) in all my links. Maybe somebody could provide a more elegant way to create dynamic links.
To create an "add to contacts"/"remove from contacts" link:
If you'd like to hide individual profile fields from "foreign" users, you can use this example for phone numbers:
And this snippet for content taxonomy fields - in my example for "City". You have to change the figure "4" with the id of your vocabulary:
I hope that will help other non-programmers.
Regards,
Stefan
Comment #3
MisterSpeed CreditAttribution: MisterSpeed commentedComment #4
Liliplanet CreditAttribution: Liliplanet commentedThank you for the snippet Stefan, I'm also using content profile with the following:
To 'Add to my Network' works great, but when I try 'Remove from my Network', the popup shows, but does not load anything, just stays stuck.
Any help would be most appreciated. (Actually would even prefer if it was not a popup, but a 'normal link' as with the http://www.drupal.org/project/flags module) in other words, by clicking on the link just reloads the page with a confirmation message.)
But just to make it work, would be fabulous.
Look forward to hearing from you.
Lilian
Comment #5
kvvnn CreditAttribution: kvvnn commentedHow to do this in Views : http://drupal.org/node/409432#comment-1826238
Comment #6
MisterSpeed CreditAttribution: MisterSpeed commentedComment #7
drupalina CreditAttribution: drupalina commentedHi,
I used the first code in comment #2 in views and custom field. It almost works, but I need a little push to make it work with 1-way twitter-style following/followers relationships.
So far I've got:
The "+ Follow" links work beautifully and open up in an Ajax popup.
But because these are 1 way relationships, the direction of the relationship should also be checked. "I'm following Mike" is not the same as "Mike is following me" - checking for the existence of the relationship is not enough. It should also check the direction of the relationship.
So, if the logged in user is viewing a user whom he is following, it should say "Following - (un-follow)"
Otherwise, it should just give a link "+ Follow".
So even if the logged in user is viewing another user who is already following him, it should still say "+ Follow"
Can anyone help with the above code? Please! (it would be a great use to anybody who is working with twitter-style user relationships)
Comment #8
mrf CreditAttribution: mrf commentedYou'll need to check if the is_oneway and is_reciprocal values are true then present the link to follow the user.
Something along the lines of (I haven't tested this...)
Comment #9
mrf CreditAttribution: mrf commentedComment #10
mrf CreditAttribution: mrf commentedWould be great to create a documentation page that describes how to do this, some sort of combination of the information in this issue, and over at #902908: How to add (print) custom button: "Add to friends" into custom user-profile.tpl.php