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
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.
0
This discussion has been closed.
Comments
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>';
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
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"); }