function get_user_object($userId)
{
    global $usersDB;
    $userCount = count($usersDB);
    if ($userCount > 0) {
        $user = false;
        for ($index = 0; $index < $userCount; $index++) {
            $usr = $usersDB[$index];
            if ($usr->email === $userId) {
                //convert $usr to map
                $user = convert_usr_stdclass_to_map($usr);
                break;
            }
        }
        return $user;
    }
    return false;
}
Example #2
0
/**
Private API
*/
function init_users_db()
{
    todolog("json_data_access.php | initializing usersDB");
    global $usersDB;
    global $users_db_file;
    if (!$usersDB) {
        $users_json_string = file_get_contents($users_db_file);
        $tmpDB = json_decode($users_json_string);
        $usersCount = count($tmpDB);
        if ($usersCount > 0) {
            todolog("json_data_access.php | found {$usersCount} users");
            $tmpUsers = array();
            for ($index = 0; $index < $usersCount; $index++) {
                $user = $tmpDB[$index];
                $userObj = convert_usr_stdclass_to_map($user);
                array_push($tmpUsers, $userObj);
            }
            $usersDB = $tmpUsers;
        } else {
            $usersDB = array();
        }
    }
}