Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
443 views
in Q2A Core by
edited by

Just a Q2A Core question. Is there any particular reason to have so similar different methods in these classes?

qa-app-posts.php (line 329)

// Return the handle corresponding to $userid, unless it is null in which case return null
function qa_post_userid_to_handle($userid) {
    if (isset($userid)) {
        if (QA_FINAL_EXTERNAL_USERS) {
            require_once QA_INCLUDE_DIR.'qa-app-users.php';
            $handles=qa_get_public_from_userids(array($userid));
            return @$handles[$userid];
        } else {
            $user=qa_db_single_select(qa_db_user_account_selectspec($userid, true));
            if (!is_array($user))
                qa_fatal_error('User ID could not be found: '.$userid);
            return $user['handle'];
        }
    }
    return null;
}

qa-app-users.php (line 616)

// Return an array mapping each userid in $userids to that user's handle (public username), or to null if not found

function qa_userids_to_handles($userids) {

    if (QA_FINAL_EXTERNAL_USERS)
        $rawuseridhandles=qa_get_public_from_userids($userids);
    else {
        require_once QA_INCLUDE_DIR.'qa-db-users.php';
        $rawuseridhandles=qa_db_user_get_userid_handles($userids);
    }
    $gotuseridhandles=array();
    foreach ($userids as $userid)
        $gotuseridhandles[$userid]=@$rawuseridhandles[$userid];
    return $gotuseridhandles;
}

If the intention was to overload a method that received an array into one that could also receive an int, the best approach I can think of to enforce code reuse, would be to check the paramter type (eg: is_array()). Or maybe I'm missing something :)

Q2A version: 1.6.2
by
Agree .. +1          .

1 Answer

+1 vote
by
 
Best answer
The function was indeed duplicated and deprecated in 1.7.0.
by
I can not fully understand it. What you're worried about? And, did you what changes to Q2A?
by
In 1.6.2 there were 2 functions that fulfilled the same purpose. I was asking if they were actually duplicated. They were. During 1.7.0-alpha (if I remember correctly) I suggested removing one of them and so it was. A year later I stumbled with my own question and answered it :)
by
edited by
I understood your changes by checking source code of V1.7. But, many users may not be able to understand it. qa_userid_to_handle() which is added in users.php is good. it should be added in Q2A functions lists.
http://www.question2answer.org/functions.php
In addtion, configuration of the source files has been changed largely in V1.7. But, document is unspoiled. I'm worried about document is not updated.
...