Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
1.5k views
in Plugins by
edited by

Currently I am developing the widget to show most active users per time interval (release soon).

For this I would like to show not only numbers (1., 2., 3. place) but also the avatar images of the users.

What code do I need to get the image links of the user avatars?
In other words: How to use qa_get_user_avatar_html properly?

 

The function is:
function qa_get_user_avatar_html($flags, $email, $handle, $blobid, $width, $height, $size, $padding=false)

So can I call the function with:
$handle = "theusername";
$avatarImage = qa_get_user_avatar_html(NULL, NULL, $handle);

?

1 Answer

+1 vote
by
edited by

This is what works (I have an associative array of usernames and go over them):

foreach ($users as $username => $val) {
            $user = qa_db_select_with_pending( qa_db_user_account_selectspec($username, false) );
            $avatarImages[$username] = qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true);
}

And I output the username besides each image using (in another foreach):

$topusers .= "<li>".$avatarImages[$key]." ".qa_get_one_user_html($key, false) ."</li>";

I guess this is the correct way to do it.

by
This will work, but it would be more efficient to do a single database query. So you could just retrieve the necessary columns for all of the users in one go, by using an IN(...) clause. See qa_db_user_get_handle_userids(...) in qa-db-users.php for a start.
by
But qa_db_user_get_handle_userids() only returns handle and userid. For qa_get_user_avatar_html() I need more parameters: $flags, $email, $handle, $blobid, $width, $height, $size, $padding

What should qa_db_user_get_handle_userids() replace?
by
I just meant you could build on the code  in qa_db_user_get_handle_userids(...) to get the information you need from a single database query.
by
alright got it, thanks
...