Not signed in (Sign In)

Categories

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

Help keep Vanilla free:
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthordarkfate
    • CommentTimeDec 14th 2007 edited
     # 1
    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.
    •  
      CommentAuthorjimw
    • CommentTimeDec 15th 2007
     # 2
    • CommentAuthordarkfate
    • CommentTimeDec 15th 2007 edited
     # 3
    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.
    • CommentAuthordarkfate
    • CommentTimeDec 15th 2007
     # 4
    I figured it out finally. I hate to put it into the dataset that was returned. I wish this was a bit easier though.
    •  
      CommentAuthorjimw
    • CommentTimeDec 16th 2007
     # 5
    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>';
    • CommentAuthorplxkarl
    • CommentTimeDec 18th 2007
     # 6
    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
    • CommentAuthorcjohnson
    • CommentTime3 days ago
     # 7
    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");

    }
Add your comments
    Username Password
  • Format comments as