xoops forums

rlankford

Not too shy to talk
Posted on: 2010/10/26 21:02
rlankford
rlankford (Show more)
Not too shy to talk
Posts: 158
Since: 2004/8/27
#1

Get userid from user's name (nickname)

I'm rusty on module development in Xoops. I have a nickname and I need to look up the user id and return it as part of making my /modulename/include/search.php file. For the life of me, I cannot remember an easy way to look up the user id!


$ret[$i]['uid'] = 0;

Need something better than zero here.

Thanks everyone.

zyspec

Module Developer
Posted on: 2010/10/27 4:13
zyspec
zyspec (Show more)
Module Developer
Posts: 1056
Since: 2004/9/21
#2

Re: Get userid from user's name (nickname)

You could try something like...

$result $xoopsDB->query("SELECT uid FROM " $xoopsDB->prefix'users' ) . " WHERE `uname`={$name} LIMIT 0,1");
list(
$uid) = $xoopsDB->fetchRow($result);
$ret[$i]['uid'] = ($uid) ? $uid 0;


Although I'm curious - how did you end up knowing the nickname without knowing the 'uid' ?

culex

Module Developer
Posted on: 2010/10/27 10:15
culex
culex (Show more)
Module Developer
Posts: 705
Since: 2004/9/23
#3

Re: Get userid from user's name (nickname)

Or you can use the class xoopsUser

global $xoopsUser;
$name "rlankford";
$user = new XoopsUser($name);
$userid $user->getVar('uid');
Programming is like sex:
One mistake and you have to support it for the rest of your life.

ghia

Community Support Member
Posted on: 2010/10/27 10:55
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#4

Re: Get userid from user's name (nickname)

Quote:
Or you can use the class xoopsUser
Is that working correct for non-existing usernames?

culex

Module Developer
Posted on: 2010/10/27 12:53
culex
culex (Show more)
Module Developer
Posts: 705
Since: 2004/9/23
#5

Re: Get userid from user's name (nickname)

Ups...your right ghia - was way off on this one.. Just tested and didnt work.

This one does work but almost makes things more complicated than the sql look-up :-S

$name "culex";
$user = new XoopsMemberHandler();
$users $user->getUserList();
    while (list(
$key$value) = each($users)) {
        if (
$value == $name) {
            echo 
"ID = ".$key.", Username = ".$value;
            break;
        }    else {
                echo 
"none found";
                break;
            }
    }
Programming is like sex:
One mistake and you have to support it for the rest of your life.

rlankford

Not too shy to talk
Posted on: 2010/10/27 13:49
rlankford
rlankford (Show more)
Not too shy to talk
Posts: 158
Since: 2004/8/27
#6

Re: Get userid from user's name (nickname)

Thanks so much everyone.

I suspected that I'd have to bring in the list of users and check each one for the appropriate account (or just do a direct query myself), but I was hoping that there was a neat little method somewhere already in the api that I was just overlooking.

Quote:

Although I'm curious - how did you end up knowing the nickname without knowing the 'uid' ?


Well, it's a long story, but maybe someone will find it interesting?? Anyway, this server also hosts lots of SVN Repositories (close to a thousand and growing). We have a neat little web-top going that allows folks to browse through the repositories and check-out, or simply download, whatever they'd like to work on.

We've been adding new features to this. For instance, Illustrators can now use SVN meta-data to mark a directory for automated uploading into our CMS database (not Xoops, something else) whenever they check-in changes via SVN. We also automatically generate thumbnails of graphics and show them while browsing around the web-top interface.

The final thing we were gonna do was add a sort of search. We don't need a complete indexing of all the content in SVN, since most of the 'stuff' that we'd want to search for is already hosted in that other CMS that I mentioned. But it would be nice if you were an Illustrator and could search/find the location of "really-cool-graphic.eps" across all our repositories.

So, I thought that it might be nice to perform an indexing operation after every repository commit action that would gather and store the path, author, revision #, revision date, and log information for each repository item. This information is getting stored directly into xoops tables for a module that I'm also writing. This module is very simple in that it really only implements the search feature of modules. There is no admin interface, main menu presence, or even general-purpose module pages for a user to view. They will, however, be able to search across filenames and log data. The search results will take them to the associated pages in our web-top. And, finally, the stylesheets for all this stuff is set up so that users of our site can't really tell that they're bouncing around amongst various websites on the same server. It'll all looks like they're in Xoops the whole time.

Now, to answer your question. SVN stores what we call the shortnames of folks who commit changes to the repositories. We've hooked Xoops to LDAP for authentication, so these very same shortnames are the Xoops nicknames on their accounts. So, during this search action, I need to go from nickname to userid so that I can pass that back. The Xoops search engine will then convert that into a clickable author link on the search results page. It's a small detail, but one I'd like to go ahead and implement.

Thanks again everyone for your help on this. Greatly appreciated!!!

---

Oh, and now that I'm thinking about it, I'll probably want to do this action during the indexing operation itself by just directly looking up the information with a MySQL query. That way, the work will be done during the batch indexing operation that nobody is waiting for rather than the search results algorithm that someone *is* waiting for.