1
rlankford
Get userid from user's name (nickname)
  • 2010/10/26 21:02

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


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.

2
zyspec
Re: Get userid from user's name (nickname)
  • 2010/10/27 4:13

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


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' ?

3
culex
Re: Get userid from user's name (nickname)
  • 2010/10/27 10:15

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


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.

4
ghia
Re: Get userid from user's name (nickname)
  • 2010/10/27 10:55

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


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

5
culex
Re: Get userid from user's name (nickname)
  • 2010/10/27 12:53

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


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.

6
rlankford
Re: Get userid from user's name (nickname)
  • 2010/10/27 13:49

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


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.

Login

Who's Online

177 user(s) are online (109 user(s) are browsing Support Forums)


Members: 0


Guests: 177


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits