Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

FirstName and LastName in session

edited March 2007 in Vanilla 1.0 Help
Mark, I'm using the People framework outside of Vanilla for several projects, and I have certain pages where I greet / refer to the user by their full name or first name (if set). UserManager->GetSessionDataById() doesn't populate the FirstName/LastName fields of the user object that's stored in the session, so I have to patch it whenever I upgrade Vanilla (no big deal, it's just a 1-line change). Would you consider populating these two fields in a future version of People / Vanilla? It's on line 518 of People.Class.UserManager.php. Btw, if you're curious about how I'm using Vanilla / People, http://dcsquares.c99.org/ uses People for authentication, and uses the Vanilla user IDs for the high score tables. My newer project, http://dev.c99.org/DreamZZT/ uses a leaderboard as well as a game download system written as a Vanilla extension. Thanks, Sam Steele

Comments

  • MarkMark Vanilla Staff
    Right on - I'm glad to see that the libraries are getting some use out there! I know exactly the line you are talking about, and I purposefully removed those from the query just to keep things quick. That query is called on every page load, so every little bit of data that I can prevent from loading helps to speed things up. Since the firstname and lastname values from that query aren't used anywhere in vanilla, I don't really want to add them in. Sorry :(
  • Sam, Would you mind posting the one-liner you made so that those of us wanting to get First and Last names but are dense can achieve it? Thanks
  • OK after about another 20 minutes of fooling around i've figured it out for myself, so nevermind. :)
  • Could you perhaps post it then? In case anyone else might be interested. :)
  • edited March 2007
    GetSessionDataByID is intended for getting the session of the currently logged in user. UserManager->GetUserByID() is probably more appropriate for this use, and it also includes the first name and last name in the user object.

    Only downside I can see is its a very similar query that would wind up being run twice for those pages that greet the user by name. No biggie IMHO.
  • edited March 2007
    I ended up changing three files altogether. They could probably be put into an add-on relatively easily but i haven't gotten that far yet.

    in People.Class.UserManager.php changed line 518 from this:
    $s->AddSelect(array('Name', 'UserID', 'RoleID', 'StyleID', 'CustomStyle', 'UserBlocksCategories', 'DefaultFormatType', 'Preferences', 'SendNewApplicantNotifications'), 'u');
    to this:
    $s->AddSelect(array('Name', 'FirstName', 'LastName', 'UserID', 'RoleID', 'StyleID', 'CustomStyle', 'UserBlocksCategories', 'DefaultFormatType', 'Preferences', 'SendNewApplicantNotifications'), 'u');

    Then I changed Vanilla.Class.CommentManager.php, line 46:
    $s->AddSelect('Name', 'a', 'AuthUsername');
    to
    $s->AddSelect('FirstName', 'a', 'AuthUsername');

    and changed Vanilla.Class.DiscussionManager.php, line 47:
    $s->AddSelect('Name', 'u', 'AuthUsername');
    to
    $s->AddSelect('FirstName', 'u', 'AuthUsername');

    and line 51:
    $s->AddSelect('Name', 'lu', 'LastUsername');
    to
    $s->AddSelect('FirstName', 'lu', 'LastUsername');

    Obviously changing code like this is not the most efficient way to do this, but I am a lazy man who is only interested in results. Probably there are WAY more areas where these updates have to be made, I've only posted the ones that made the pages look the way i wanted them.

    edit: Also I should note that for users who do not have the First Name field filled in, the query returns nothing and thus there is no text displayed either on Comments or on the Discussions page. However it does not appear to break anything, you'll just have nameless icons.
  • MarkMark Vanilla Staff
    Another option would have been to change the language file so that instead of "username" it says "full name" everywhere in the application - so that people enter their real name instead of their username. Then all of the requirements of the username are applied to the real name and you won't get any blank names anywhere - and you won't need to change any queries.
This discussion has been closed.