Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
677 views
in Q2A Core by
It would be nice to add a few staple functions to the core, ones that I use a lot for different purposes... here's a list I'd like have available (their names are arbitrary), can anyone think of others?

        function qa_allow_check($opt) {
            if(qa_opt($opt) == QA_PERMIT_POINTS)
                return qa_get_logged_in_points() >= qa_opt($opt.'_points');
            return !qa_permit_value_error(qa_opt($opt), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags());
        }

        function qa_id_to_handle($uid) {
            require_once QA_INCLUDE_DIR.'qa-app-users.php';
            
            if (QA_FINAL_EXTERNAL_USERS) {
                $publictouserid=qa_get_public_from_userids(array($uid));
                $handle=@$publictouserid[$uid];
                
            }
            else {
                $handle = qa_db_read_one_value(
                    qa_db_query_sub(
                        'SELECT handle FROM ^users WHERE userid = #',
                        $uid
                    ),
                    true
                );
            }
            if (!isset($handle)) return;
            return $handle;
        }

        function qa_handle_to_id($handle) {
            require_once QA_INCLUDE_DIR.'qa-app-users.php';
            
            if (QA_FINAL_EXTERNAL_USERS) {
                $publictouserid=qa_get_userids_from_public(array($handle));
                $userid=@$publictouserid[$handle];
                
            }
            else {
                $userid = qa_db_read_one_value(
                    qa_db_query_sub(
                        'SELECT userid FROM ^users WHERE handle = $',
                        $handle
                    ),
                    true
                );
            }
            if (!isset($userid)) return;
            return $userid;
        }

    function qa_error_log($x) {
        ob_start();
        var_dump($x);
        $contents = ob_get_contents();
        ob_end_clean();
        error_log($contents);
    }
by
Good feedback, but why not use !qa_user_permit_error(...) in qa-app-user.php instead of qa_allow_check(...)?
by
hmmm - sorry about that, for some reason I looked at those functions and thought I needed a new one... looks like I was confused, sorry :)

1 Answer

+2 votes
by

Done! See qa_userids_to_handles(...) and qa_handles_to_userids(...) in qa-app-users.php in 1.5 beta 2. To reduce database queries, these work on multiple userids or handles at a time, but they can obviously be used for individual ones too.

by
thank you :)

while we're on the subject, can I bother you about putting userids in the post_meta "who" and "who_2" info?  I know that for "who", it's the same as the post, but there seems still no way to reliably get the userid for a "who_2" entry.
by
The 'who_2' should match $post['raw']['lastuserid'] - have you tried that?
by
ah, sorry, didn't see that :) thanks.
...