Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
333 views
in Plugins by

@gidgreen + pros: Alright, I want to make sure that there is no better way (performance).

For my new plugin I need to ignore blocked users, this is what I did: 

            // get blocked users that we don't want in our listing
            $blockedusers = array();
            $blockedusersData =qa_db_select_with_pending(qa_db_users_with_flag_selectspec(QA_USER_FLAGS_USER_BLOCKED));
            foreach ($blockedusersData as $user) {
                array_push($blockedusers,$user['userid']);
            }

 

Then I list all users:

            foreach ($scores as $userId => $val) {
                // no users with 0 points, and no blocked users!
                if($val>0 && !in_array($userId, $blockedusers) ) {
                    $currentUser = $usernames[$userId];
                    $user = qa_db_select_with_pending( qa_db_user_account_selectspec($currentUser, false) );

                  ...
 

As you see I implemented qa_db_users_with_flag_selectspec(QA_USER_FLAGS_USER_BLOCKED) at first, then I query the database again with qa_db_user_account_selectspec($currentUser, false).

Is that fine? Or could I somehow get blocked users using only qa_db_user_account_selectspec($currentUser, false) ?

1 Answer

0 votes
by
edited by

answering myself with "yes, you can do better. you do not need to collect the blocked users separately using qa_db_users_with_flag_selectspec, but":

                if($val>0) {
                    $currentUser = $usernames[$userId];

                    $user = qa_db_select_with_pending( qa_db_user_account_selectspec($currentUser, false) );
                    // check if user is blocked
                    if (! (QA_USER_FLAGS_USER_BLOCKED & $user['flags'])) {
                        // ...

 

and it works wink

see also my tutorial q2a-post How to find flag of user blocked from flag number?

cheers,
Kai

PS: developing for q2a is really fun!

...