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.

Displaying FirstName and LastName on Posting

edited August 2008 in Vanilla 1.0 Help
I am wondering if there is an easy way to display someones real name instead of doing there user name where they post. I see AuthUsername, but I'm not totally sure how to add/change it to grab the FirstName and LastName.

Comments

  • edited December 2007
    That doesn't seem to help. I can't find that anywhere on your forum. Also that hack didn't seem to work. Don't mean the flame here, but it seems utterly idiotic that it only will return those specific methods. It should allow you to get any column from the comment author. I've only looked at the code for around 20 minutes, so maybe I'm missing something. EDIT: I dumped the $Comment class out on the page and it looks like FirstName and LastName are empty (string(0)). I had added these two lines around line 58 in Vanilla.Class.CommentManager.php: $s->AddSelect('FirstName', 'a', 'AuthFirstName'); $s->AddSelect('LastName', 'a', 'AuthLastName'); Then in comments.php I tried to do this: $CommentAuthName = $Comment->AuthFirstName; That just gave me an Notice: Undefined Property Error. EDIT2: If I change this line: $s->AddSelect('Name', 'a', 'AuthUsername'); to this: $s->AddSelect('FirstName', 'a', 'AuthUsername'); It does indeed spit out the first name. So I know I'm missing something somewhere.
  • I figured it out finally. I hate to put it into the dataset that was returned. I wish this was a bit easier though.
  • I am glad that you figured it out. However, I don't understand what you mean by "put into the dataset". Do you mean the data that's returned in the commentgrid? Could you explain?

    For others, the code change I made (that seems to work for me) to the CommentAuthorInfo add-on was:
    $posts = $rows['CountDiscussions'] + $rows['CountComments']; // begin jimw 20061113 //if ($Context->Session->UserID > 0) //un-comment if you only want to show for logged in users //{ if (!@$UserManager) $UserManager = $Context->ObjectFactory->NewContextObject($Context, "UserManager"); $AccountUserID = ForceIncomingInt("u", $Comment->AuthUserID); if (!@$AccountUser) { $AccountUser = $UserManager->GetUserById($AccountUserID); $DispFName = $AccountUser->FirstName; $DispLName = $AccountUser->LastName; $DispName = $DispFName . " " . $DispLName; } //} else { // $DispName = "xxx"; //} // end jimw 20061113 $RowNumber++; if ($Context->Configuration['DISPLAY_ONLY_COMMENT_COUNT']) { $CommentList .= ' '.$CommentGrid->Context->GetDefinition("Comments").': '.$posts.' '; //$CommentList = str_replace('<li id="Comment_'.$Comment->CommentID, $CommentGrid->Context->GetDefinition("Comments").': '.$rows['CountComments'].'<li id="Comment_'.$Comment->CommentID, $CommentList); } else { $CommentList .= ' '.$DispName.' '.$CommentGrid->Context->GetDefinition("Comments").': '.$posts.' '.$CommentGrid->Context->GetDefinition("AccountCreatedShort").': '.TimeDiff($CommentGrid->Context, UnixTimestamp($rows['DateFirstVisit'])).' ('.$Comment->CommentID.')'; } // $CommentList .= '<ul class="AuthorInformation"><li>'.$CommentGrid->Context->GetDefinition("Comments").': '.$posts.'</li><li>'.$CommentGrid->Context->GetDefinition("AccountCreatedShort").': '.TimeDiff($CommentGrid->Context, UnixTimestamp($rows['DateFirstVisit'])).'</li>';
  • Hey,

    You guyz are really messy and hard to understand. I had to figure it out by myself. Here's my way:
    I've created the following extension which will change the AuthUsername to "Firstname Lastname" on the Discussions Page.
    if (in_array($Context->SelfUrl, array("index.php"))) { //First Add Fields function addExtraDiscussionFields(&$DiscussionGrid){ $s = &$DiscussionGrid->DelegateParameters['SqlBuilder']; // Get author data $s->AddSelect('FirstName', 'u', 'AuthFN'); //Author FirstName $s->AddSelect('LastName', 'u', 'AuthLN'); //Author LastName // Get last poster data $s->AddSelect('FirstName', 'lu', 'LastFN'); //LastUser FirstName $s->AddSelect('LastName', 'lu', 'LastLN'); //LastUser LastName } $Context->AddToDelegate("DiscussionManager", "PostGetDiscussionBuilder", "addExtraDiscussionFields"); //Add that function to Delegate //Then Get Properties From DataSet function getPropertiesFromDataSet(&$Discussion){ $DataSet = &$Discussion->DelegateParameters['DataSet']; // Get author data MINE $Discussion->AuthUsername = @$DataSet['AuthFN'].' '.@$DataSet['AuthLN']; //Basically overwrite AuthUsername with what we pulled out in the previous function $Discussion->LastUsername = @$DataSet['LastFN'].' '.@$DataSet['LastLN']; //Basically overwrite AuthUsername with what we pulled out in the previous function } $Context->AddToDelegate("Discussion", "PostGetPropertiesFromDataSet", "getPropertiesFromDataSet"); }

    Developers at Vanilla should also add delegates to Vanilla.Class.Comment.php same as in the Vanilla.Class.Discussion.php which enable us to do what I just did above. Otherwise I'm forced to add them myself and breaking the rule of not touching application files.

    Thanks

    Karlito
    3magine.com
  • I'm no PHP ninja, but I think I managed to get the above working as an extension in Vanilla 1.1.5rc1. It displays the user's real name, instead of his username, on discussion list pages and comments pages. Can someone tell me if something is egregiously wrong with this? I'm not intimately familiar with Vanilla and delegation and all that; I basically just copied the previous poster's code and made modifications for comments pages. Light testing shows it so far to be functional.

    if (in_array($Context->SelfUrl, array("index.php"))) { //First Add Fields function addExtraDiscussionFields(&$DiscussionGrid){ $s = &$DiscussionGrid->DelegateParameters['SqlBuilder']; // Get author data $s->AddSelect('FirstName', 'u', 'AuthFN'); //Author FirstName $s->AddSelect('LastName', 'u', 'AuthLN'); //Author LastName // Get last poster data $s->AddSelect('FirstName', 'lu', 'LastFN'); //LastUser FirstName $s->AddSelect('LastName', 'lu', 'LastLN'); //LastUser LastName } $Context->AddToDelegate("DiscussionManager", "PostGetDiscussionBuilder", "addExtraDiscussionFields"); //Add that function to Delegate //Then Get Properties From DataSet function getPropertiesFromDataSet(&$Discussion){ $DataSet = &$Discussion->DelegateParameters['DataSet']; // Get author data MINE $Discussion->AuthUsername = @$DataSet['AuthFN'].' '.@$DataSet['AuthLN']; //Basically overwrite AuthUsername with what we pulled out in the previous function $Discussion->LastUsername = @$DataSet['LastFN'].' '.@$DataSet['LastLN']; //Basically overwrite AuthUsername with what we pulled out in the previous function } $Context->AddToDelegate("Discussion", "PostGetPropertiesFromDataSet", "getPropertiesFromDataSet"); } if (in_array($Context->SelfUrl, array("comments.php"))) { //First Add Fields function addExtraCommentFields(&$CommentGrid){ $s = &$CommentGrid->DelegateParameters['SqlBuilder']; // Get author data $s->AddSelect('FirstName', 'a', 'AuthFN'); //Author FirstName $s->AddSelect('LastName', 'a', 'AuthLN'); //Author LastName } $Context->AddToDelegate("CommentManager", "CommentBuilder_PreWhere", "addExtraCommentFields"); //Add that function to Delegate //Then Get Properties From DataSet function getPropertiesFromDataSet(&$Comment){ $DataSet = &$Comment->DelegateParameters['DataSet']; $Comment->AuthUsername = @$DataSet['AuthFN'].' '.@$DataSet['AuthLN']; //Basically overwrite AuthUsername with what we pulled out in the previous function } $Context->AddToDelegate("Comment", "PostGetPropertiesFromDataSet", "getPropertiesFromDataSet"); }
This discussion has been closed.