I'd like to show 'friend' avatars on my user profiles. UR comes with a block that shows the names, but not user pictures. UR is also integrated with Views, but I can't figure out how to configure a view/block that will show the friend pics of the user profile I'm currently viewing. Does anyone know how to do this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mtsanford’s picture

FileSize
41.96 KB

I was wondering myself. Being a complete newbie to views module (using views2), it took me a while just to figure out what the hell was going on. (The learning curve here is a bit steep, but I see the possibilities...)

Start with a "User Relationship" type view, not "User" unless you want to bang your head against a wall for an hour or so :)

I made a page view that shows the current users 'friends'. The settings are shown in the following PNG attachment. 'friend' is a a 2-way relationship as I defined it, so requester/requestee can be flipped and it should not matter.

(oh, probably should have an extra filter to make sure relationship is approved too...)

Not exactly what you're looking for I guess, but hope this helps. You may have to muck with the Arguments? (But like I said, I'm a newbie with views so that's just a guess.)

lillywolf’s picture

Hey, thanks -- I wound up re-configuring one of the blocks that comes with the module, but I'll try out the 'user relationship' type view to see what I can get from that.

yang_yi_cn’s picture

Great! Now I can display pictures without hacking.

Kane’s picture

Hi, any progress with Views 2? I've figured out how to make "My Friends" block, but stuck with "User Relationships". Tried to figure out by myself, but don't have enought experience with Views.

I thought that this block should take user id and use it to find this user's friends. Anyway, no idea how to do it.

Kane’s picture

I believe i found way to make this view. Check screens for View details.

I hope this will work for you. And i hope this is right settings.

Thoor’s picture

Hallo Kane,

THX a lot for your Instructions - guess without it, i would never ever done ist. With your Help I could do it!

For example: At the Bottom on: http://www.steeldart.org/users/tom

I am also using the module Imagecache_profile. As you see, the view uses the "Profile picture preset" to show the relations.
Anyone an Idea for me to change the shown picures of the view to "Default picture preset"? For example the picturesize shown on my Startpage http://www.steeldart.org

Kane’s picture

Hey THOOR, i actually stuck with the same problem. This problem accurs, at least as i understand, because on profile page you use imagecache preset with different actions then in your default "Default picture preset".
Here what i decided to do. BTW, i have ImageCache profiles too, so our situation is similar.

English is not my first language, so i'm sorry for any stupid mistakes.

There are two ways (maybe more) and only one which i've tried (i don't even know if other will work).

Here what i think about way which supposedly won't work and it needs hacks to imagecache_profiles too.
There are some global variables (or whatever): "uid" - user id, "nid" - node id, "cid" - comment id and some others.
In imagecache profiles you need to add some strings whic will create dropdown menu which will assgn choosen imagecache preset to "bid"/"vid" or what ever which represent "block id".
It means that when any user picture will be placed by views in block it will automatically use choosen imagecache profiles preset for blocks. Damn, i do really hope you understand what i mean, cause i'm not a programmer and don't know Drupal Api.

Anyway here's second solution to this problem (which most likely i will use and i'm sure it will work):
As you know, you have "Picture in profile" (or something like that) which goes with default Drupal module "Profile".
And also there's module which called Content Profiles. With this module you can create Content type, for example "Profile". When user register on your site he have to create this content (there is link in profile page) whic will be his/her profile (it also displays in profile page).
Now you need cck, filefield and imagefield. Just create image field call it like "Your image" assign imagecache profiles to it. Then choose display (imagecache preset) on fields settings.
Btw, i think you need to edit profiles template to delete default user picture call. maye there's other way to do it, like in theme settings or user settings, don't know.

If you need instructions with images i think i can make it later.

Good luck.

rjbrown99’s picture

I'm working on much the same problem, and based on #5 above I am able to create a view and display it properly with the core user fields.

One thing I am struggling with, and I'm not sure why, but if you take the same view from #5 and add a View Relationship to "Node: Content Profile" tied to the Requestee relationship, it breaks the rest of the view and it no longer renders. This is true for me even if you don't add any new fields or change anything else.

What I am trying to do is exactly what is in #5, just output fields from the requestee's content profile instead of fields from their core account/user profile. Kane in #7 - were you successful in building this same view with a content profile? If so would you mind sharing a screenshot of your view? Thanks in advance.

rjbrown99’s picture

Well, I had it right from the get-go. There is a bug in the views 2.4 and 2.5 releases that prevented this from working properly. After adding a second relationship (content profile -> requestee), the SQL query breaks. Here's the fix that worked for me.
http://drupal.org/node/437960#comment-1513360

If you have Views 2.4 or 2.5 and this is not working, check that link and fix.

Kane’s picture

FileSize
37.28 KB

Thanks to rjbrown99 and his link to fix i made view with content profile (check attach).
I want to notice that avatar will be linked (if you choose to link) to content profile page, not to default user profile. I guess there's a way to fix it, but i'm not sure.

Also, choose required or "default image" or both for avatar image field. Or users without avatars won't be shown in userpics block.

Good luck.

Michelle’s picture

Just an FYI - Advanced Profile Kit comes with a "friends" view that includes avatars. I don't recommend using APK itself at the moment since it's going through a rough transition to Panels 3, but you can always grab the view export.

Michelle

Kane’s picture

Thanks for advice Michelle, i tried APK but i decided to make profile page by myself (themekey module and node theme module allows to change theme of specific node type). Also, i'm not a fan of panels, prefer to manually create theme than installing module which weights about 1 MB and i bet adds even more queries to db than i already have.

But that's only my situation and both Panels and APK great modules which was created by great developers. I bet a lot of people are grateful for this modules.

Kane’s picture

Double post

Michelle’s picture

@Kane: I think you missed the part where I said "I don't recommend using APK itself at the moment since it's going through a rough transition to Panels 3, but you can always grab the view export." :)

Michelle

Kane’s picture

Check this issue: http://drupal.org/node/349331

It allows to choose in what size user pictures will be displayed via Views.
After applying patch and stuff you need to assign imagecache presets in user settings again.

alex.k’s picture

Status: Active » Fixed

Seems to be ok to mark fixed.

rjbrown99’s picture

Just a follow-up from my post #9. This was not a views issue - it was a content profile issue that was fixed in a later commit. Don't bother hacking on views; just update your content profile module to current.

Here is the CP issue: http://drupal.org/node/471708

kvvnn’s picture

I used Michelle's suggestion and imported the "Friends View" from the Advanced Profile Kit, and it worked wonderfully. I customized it to fit my needs and I am sailing smooth.

I've attached the view and included the code.

Here is the views code that you can import to create a view that will display all of a user's friends, with that user ID as an argument :

$view = new view;
$view->name = 'apk_ur_friends_gallery';
$view->description = 'Shows a gallery of friends\' avatars';
$view->tag = 'APK';
$view->view_php = '';
$view->base_table = 'user_relationships';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'requestee_id' => array(
'label' => 'requestee',
'required' => 0,
'id' => 'requestee_id',
'table' => 'user_relationships',
'field' => 'requestee_id',
'relationship' => 'none',
),
'requester_id' => array(
'label' => 'requester',
'required' => 0,
'id' => 'requester_id',
'table' => 'user_relationships',
'field' => 'requester_id',
'relationship' => 'none',
),
'rtid' => array(
'label' => 'rtid',
'required' => 0,
'id' => 'rtid',
'table' => 'user_relationships',
'field' => 'rtid',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'name' => array(
'label' => '',
'link_to_user' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'requestee_id',
'override' => array(
'button' => 'Override',
),
),
'picture' => array(
'label' => '',
'exclude' => 0,
'id' => 'picture',
'table' => 'users',
'field' => 'picture',
'relationship' => 'requestee_id',
),
));
$handler->override_option('sorts', array(
'plural_name' => array(
'order' => 'ASC',
'id' => 'plural_name',
'table' => 'user_relationship_types',
'field' => 'plural_name',
'relationship' => 'rtid',
),
));
$handler->override_option('arguments', array(
'requester_id' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'user',
'default_argument' => '',
'validate_type' => 'numeric',
'validate_fail' => 'not found',
'break_phrase' => 0,
'not' => 0,
'id' => 'requester_id',
'table' => 'user_relationships',
'field' => 'requester_id',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'blog' => 0,
'page' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(),
'validate_argument_type' => 'tid',
'validate_argument_php' => '',
),
));
$handler->override_option('filters', array(
'approved' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'approved',
'table' => 'user_relationships',
'field' => 'approved',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Friends gallery');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 0);
$handler->override_option('items_per_page', 30);
$handler->override_option('use_pager', 'mini');
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
'grouping' => '',
'columns' => '4',
'alignment' => 'horizontal',
));
$handler->override_option('row_options', array(
'inline' => array(
'name_1' => 'name_1',
),
'separator' => ', ',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'users/%/friends_gallery');
$handler->override_option('menu', array(
'type' => 'normal',
'title' => 'All Relationships',
'description' => '',
'weight' => '0',
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler = $view->new_display('panel_pane', 'Panel pane', 'panel_pane_1');
$handler->override_option('pane_title', 'Friends Gallery (UR)');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
'name' => 'Advanced Profile Kit',
'weight' => '0',
));
$handler->override_option('allow', array(
'use_pager' => 0,
'items_per_page' => 'items_per_page',
'offset' => 0,
'link_to_view' => 'link_to_view',
'more_link' => 'more_link',
'path_override' => 'path_override',
'title_override' => 'title_override',
'exposed_form' => FALSE,
));
$handler->override_option('argument_input', array(
'requester_id' => array(
'type' => 'context',
'context' => 'user.uid',
'panel' => '0',
'fixed' => '',
'label' => 'User relationships: Requester user',
),
));
$handler->override_option('link_to_view', 0);
$handler->override_option('inherit_panels_path', 0);

Bilmar’s picture

kvnBushi-

I was able to import the view but getting:
"Query No query was run"
And for the location of the page:
Page not found
The requested page could not be found.

I have a friend already approved and listed.
What may I be doing wrong?

Thank you.

Status: Fixed » Closed (fixed)

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

kvvnn’s picture

I'm really not sure based on the errors you are giving. If you want, PM me and give me access to your View and I will help you. Cheers

sadist’s picture

FileSize
5.83 KB

the Views code at #18 won't work for me as it depends on the UID arguments in URL. So I'd made an amendment to it and removed all handlers for Panels.

What you need to do is just to change the user picture field and set it to your own imagecache preset.

So here's my Views.

j3frea’s picture

I'm trying to do this as well;
I'm importing a block in my user-profile.tpl.php using

<?php
$right .= '<h2>Friends</h2>';
$block = module_invoke('views', 'block', 'view', 'user_relationships-block_1');
$right .= $block["content"];
?>

the block is generated by a view which is supposed to display all the images of the friends of the user whose profile is being viewed.

The problem is that my imagecache preset, which seems to apply to the view's block when in preview mode, reverts to the user profile preset when actually displayed in the user profile.

I hope that made sense, any help will be appreciated. (By the way, I used sadist's import to get the view)

j3frea’s picture

A workaround that I figured out is to use the imagecache preset that you want in your user-profile.tpl.php and then to set a different preset (i.e. the one you want to use for the avatars) in User Settings as the profile preset.

gitin’s picture

hi everyone, sorry this is my first comment on drupal site so plz forgive me if m doing something wrong...
i read all comments and i think everybody is using views to make a relationship block with pictures or avatars in it, i tried to use views so many times but it always goes over my head, just a request if someone could reply, is there any other way we can make a ur block with user pictures in it with 'default names'..?
thanx
you might wanna visit my site and have a idea what i m talking about, just visit any profile page thanx
http://orkutx.com

broncomania’s picture

#22 should be a standart view in my opinion.