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

For the avatar I think I have to use the function qa_get_user_avatar_html (see qa-app-users.php) but it is said: Pass the user's fields $flags, $email, $handle, and avatar $blobid, $width and $height

I also found: qa_get_avatar_blob_html($blobid, $width, $height, $size, $padding=false)

From my current situation (developping another plugin) I have only the userid that I can pass, and I need to get username and user-avatar.

Can anybody help?

 

by
NoahY uses the following code (from history plugin):

function getHandleFromId($userid) {
    require_once QA_INCLUDE_DIR.'qa-app-users.php';
   
    if (QA_FINAL_EXTERNAL_USERS) {
        $publictohandle=qa_get_public_from_userids(array($userid));
        $handle=@$publictohandle[$userid];
    }
    else {
        $user = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
        $handle = @$user['handle'];
    }
    return $handle;
}

1 Answer

+1 vote
by
edited by

Alright, found 1st part of answer:

function qa_userids_to_handles (in qa-app-users.php)

 

EDIT:

and this is how you do it:

        // get handles in array usernames ($userids MUST be an array)
        $usernames = qa_userids_to_handles($userids);

       // and then I iterate over an array like that:
         foreach ($scores as $userId => $val) {
           $currentUser = $usernames[$userId];
            $user = qa_db_select_with_pending( qa_db_user_account_selectspec($currentUser, false) );
            $bestusers .= "<li>" . qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true) . " "
                                    . qa_get_one_user_html($usernames[$userId], false).' ('.$val.')</li>';
        }


---

Edit 2012-11-01:

This is the code I am using now in my plugins to get the username by passing the userid!

// get user details (display avatar and name)
$username = qa_db_read_all_assoc(qa_db_query_sub('SELECT handle FROM ^users WHERE userid = #',$row['userid']), 'handle');
$user = qa_db_select_with_pending( qa_db_user_account_selectspec($username, false) );
$revLink = isset($row['title']) ? $row['title'] : "Answer was edited";
$htmloutput .= '<tr> <td>'.date("Y-m-d H:m", strtotime($row['updated'])).'</td>
                     <td><a href="'.$activity_url.'">'.$revLink.'</a> <br />'.$display_post_url.'</td>
                     <td>'. qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), false) . " " . qa_get_one_user_html($user['handle'], false).'</td></tr>';

 

If you only want to query 1 username use:

$username = qa_db_read_one_assoc(qa_db_query_sub('SELECT handle FROM ^users WHERE userid = #',$row['userid']), 'handle');

by
edited by
Just as follow up, with v1.6.3 you can use function qa_handle_to_userid($handle) to retrieve the userid from the username. See https://github.com/q2a/question2answer/blob/master/qa-include/qa-app-users.php

Plus, the other solution for the question above: qa_post_userid_to_handle($userid) see https://github.com/q2a/question2answer/blob/master/qa-include/qa-app-posts.php

*** From 1.7 ***
qa_userid_to_handle($userid)
https://github.com/q2a/question2answer/blob/master/qa-include/app/users.php
...