Imagecache (user picture in inbox view) using user_load()
| Project: | Privatemsg |
| Version: | 6.x-1.x-dev |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Don't worry this isn't another support request... yet. I basically set up the inbox page kinda like facebook has it's inbox. Now I managed to add this just fine. But my worries are that I might be writing a bunch of code for nothing. Here's how I did it.
First I used hook_privatemsg_sql_list_alter to add the origional author... $fragments['select'][] = "pm.author". After that I used the theme functions, most specific being mytheme_privatemsg_list_field__participants. In that theme I added two things.
1. Variable to add the user who started the message....
<?php
$sender = _privatemsg_generate_user_array($thread['author']);
?>2. I made another variable which seemed to be the only way I could print the authors picture.
<?php
$user_avatar = user_load($thread['author']);
?>Then using the $user_avatar variable I of coarse added my authors picture using imagecache..
Anyways the question is, is this the proper way to do things? Will there be any performance issues by using user_load? Or maybe theres a simpler solution?
Thanks again,
Steve

#1
$sender should contain an array of user objects (in case of author, only one) and the same information as $user_avatar. Try $sender[0].
user_load() can issue several queries, if you have modules that load stuff when a user is loaded. The function http://blog.worldempire.ch/de/api/function/_privatemsg_generate_user_arr... contains a static cache, and only loads each user object once per request.
#2
Update:
$sender[0] does not work, because the index is the uid, so you have to use something like:
<?php$sender = reset($sender);
?>
#3
I'm confused. See if I follow you correctly... I'm currently using...
<?php(user_load($thread['author']);
?>
I'm not very familiar with it. But since im using $thread['author'] with it, would that not make it only issue that one query? My problem isn't to get it working. It works fine. My concern is performance, and doing it the best possible way.
Or are you saying that I should use the $sender variable in user_load() instead of $thread['author']?
So after re-reading your posts I'm gonna take a guess...
I'd be better off not using user_load and instead just rest the $sender variable and use $sender->picture within the theme for imagecache pictures? And if so then don't I have to redeclare the $sender variable in order to get the origional authors name?
Sorry for the million questions just trying to get a better understanding.
#4
Seems I misundestood the question in the first place. Performance is an issue and user_load() is slow, but there might be no other way.
anyway, setting this to fixed since the issue has not seen any responses in months.
#5
Automatically closed -- issue fixed for 2 weeks with no activity.