Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Option to display gender on Comment

sarowlwpsarowlwp New
edited May 2012 in Vanilla 2.0 - 2.8

i found one post about

Option to display gender on user profile page
http://vanillaforums.org/discussion/comment/143606/#Comment_143606

but i want display it on the comment ?

anyone can help ?

@x00 @423 @Todd

Best Answers

  • UnderDogUnderDog MVP
    Answer ✓

    422 said:
    Whos @423 ?

    A new version of @422 once he runs out of energy to post answers to silly questions :-|

    sarowlwp said:
    my question: i want display gender info on Comment Meta , i have done it in the profile page, but i can` get gender form discussion page , so any idea ?

    Show the exact code that you did on the profile page. Place it in < pre > tags or < code > tags or something else that makes the code readable.

    There was an error rendering this rich post.

  • x00x00 MVP
    Answer ✓

    nah

    that is very inefficient to query each person in a loop.

    $Author->Gender not work becuase in user model JoinUsers
    $Join = GetValue('Join', $Options, array('Name', 'Email', 'Photo'));

    is missing 'Gender'

    You could add it, though not the most transportable solution.

    grep is your friend.

  • x00x00 MVP
    Answer ✓

    The efficient solution is to cache the users, and join them pragmatically which is what JoinUsers does. Only it doesn't carry the gender across even though all the values are returned from the query.

    look in dashboard/models/class.usermodel.php -> JoinUser

    set the line to

    $Join = GetValue('Join', $Options, array('Name', 'Email', 'Photo', 'Gender'));

    This isn't the idea solution but it is simple for you, the plugin version would be more complex becuase there isn't a hook where you can add additional values in the mix, maybe somethign you can mention on github.

    grep is your friend.

  • x00x00 MVP
    edited May 2012 Answer ✓

    If the comment model Get added the the options, then you could use BeforeGet to to set $Options['Join'] retrieve what you want and go it by hooks, unfortunately the is not the case right now.

    grep is your friend.

«1

Answers

  • Can you not mention me on every post you make?!

    grep is your friend.

  • x00 said:
    Can you not mention me on every post you make?!

    ok,just , i konw you are an active dev for vanilla .

    sorry to trouble you

  • Saro, the way I see it is that lots of 'regulars' on this forum will 'read' all topics (with new posts in my case) so you do not have to mention the 'regulars', because they'll read it anyways.

    What you need to do a little more is first try the option (for example from the discussion you found) and then write down what didn't work.


    You can say : I want a red door, but all I found was a blue door. Or you can say : I want a red door, I have the red paint, but could not find the right brushes. All the stores are closed, what to do?

    Do you see my point?

    There was an error rendering this rich post.

  • UnderDog said:
    Saro, the way I see it is that lots of 'regulars' on this forum will 'read' all topics (with new posts in my case) so you do not have to mention the 'regulars', because they'll read it anyways.

    What you need to do a little more is first try the option (for example from the discussion you found) and then write down what didn't work.


    You can say : I want a red door, but all I found was a blue door. Or you can say : I want a red door, I have the red paint, but could not find the right brushes. All the stores are closed, what to do?

    Do you see my point?

    thx

    got it

  • thx for you two . i will take your advice .

    my question: i want display gender info on Comment Meta , i have done it in the profile page, but i can` get gender form discussion page , so any idea ?

  • Whos @423 ?

    There was an error rendering this rich post.

  • UnderDogUnderDog MVP
    Answer ✓

    422 said:
    Whos @423 ?

    A new version of @422 once he runs out of energy to post answers to silly questions :-|

    sarowlwp said:
    my question: i want display gender info on Comment Meta , i have done it in the profile page, but i can` get gender form discussion page , so any idea ?

    Show the exact code that you did on the profile page. Place it in < pre > tags or < code > tags or something else that makes the code readable.

    There was an error rendering this rich post.

  • Now i know how 006 felt about Roger Moore

    There was an error rendering this rich post.

  • I thought that was Dudley Moore.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • 422 said:
    Whos @423 ?

    he's one better.

    @sarowlwp post your code, and the results. I'm sure one of the 'guys' will be able to point you in the right direction. I think this is the sort of specificity that underdog was aiming for.. but he's a lot more subtle than i am.

    oh, and im both offended and grateful that you didn't @ me on this. (not an invitation, just trying for humor)

  • sarowlwpsarowlwp New
    edited May 2012

    hbf said:

    422 said:
    Whos @423 ?

    he's one better.

    @sarowlwp post your code, and the results. I'm sure one of the 'guys' will be able to point you in the right direction. I think this is the sort of specificity that underdog was aiming for.. but he's a lot more subtle than i am.

    oh, and im both offended and grateful that you didn't @ me on this. (not an invitation, just trying for humor)

    thx , i will change it , not @ anyone in the forum , you guys are nice ,sorry to trouble you all

    here my code

    file : views/discussion/helper_functions.php

        function WriteComment($Object, $Sender, $Session, $CurrentOffset) {
           $Alt = ($CurrentOffset % 2) != 0;
    
           $Author = UserBuilder($Object, 'Insert');
    

        <li class="<?php echo $CssClass; ?>" id="<?php echo $Id; ?>">
           <div class="Comment">
              <div class="Meta">
                 <?php $Sender->FireEvent('BeforeCommentMeta'); ?>
                 <span class="Author">
                    <?php
                    echo UserPhoto($Author);
                    echo UserAnchor($Author);
    

    i want inser gender info here and
    echo $Author->Gender;
    not work

  • doesnt echo ($this->User->Gender); work ?

    There was an error rendering this rich post.

  • 422 said:
    doesnt echo ($this->User->Gender); work ?

    Fatal error: Using $this when not in object context in /home/aiqingda/www/www/themes/aiqingda/views/discussion/helper_functions.php on line 52

  • 422422 MVP
    edited May 2012

    How have you got it working elsewhere?

    There was an error rendering this rich post.

  • 422 said:
    How have you got it working elsewhere?

     <li class="<?php echo $CssClass; ?>" id="<?php echo $Id; ?>">
           <div class="Comment">
              <div class="Meta">
                 <?php $Sender->FireEvent('BeforeCommentMeta'); ?>
                 <span class="Author">
                    <?php
                    echo UserPhoto($Author);
                    echo UserAnchor($Author);
                    echo ($this->User->Gender);
    
  • peregrineperegrine MVP
    edited May 2012

    There may be a better way but this works. - but it will do a database read on every comment.

    apparently it is Null in the $Sender, and $Object. I don't know if this is possibly a bug in the vanilla code or not.

    you have to pull it out of the database yourself like below:

    echo UserPhoto($Author);
    echo UserAnchor($Author);
    
     $AuthGender = Gdn::Database()->SQL()->Select('Gender')->From('User')->Where('UserID', $Author->UserID)->Get()->FirstRow();
    
    echo $AuthGender->Gender;
    

    let us know if it works for you :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • x00x00 MVP
    Answer ✓

    nah

    that is very inefficient to query each person in a loop.

    $Author->Gender not work becuase in user model JoinUsers
    $Join = GetValue('Join', $Options, array('Name', 'Email', 'Photo'));

    is missing 'Gender'

    You could add it, though not the most transportable solution.

    grep is your friend.

  • x00 said:
    nah

    that is very inefficient to query each person in a loop.

    $Author->Gender not work becuase in user model JoinUsers
    $Join = GetValue('Join', $Options, array('Name', 'Email', 'Photo'));

    is missing 'Gender'

    You could add it, though not the most transportable solution.

    thx you ! which source file it is ?

  • x00 said:
    nah

    that is very inefficient to query each person in a loop.

    $Author->Gender not work becuase in user model JoinUsers
    $Join = GetValue('Join', $Options, array('Name', 'Email', 'Photo'));

    is missing 'Gender'

    You could add it, though not the most transportable solution.

    thx you ! which source file it is ?> peregrine said:

    There may be a better way but this works. - but it will do a database read on every comment.

    apparently it is Null in the $Sender, and $Object. I don't know if this is possibly a bug in the vanilla code or not.

    you have to pull it out of the database yourself like below:

    echo UserPhoto($Author);
    echo UserAnchor($Author);
                  
     $AuthGender = Gdn::Database()->SQL()->Select('Gender')->From('User')->Where('UserID', $Author->UserID)->Get()->FirstRow();
        
    echo $AuthGender->Gender;
    

    let us know if it works for you :)

    thx, i have think about it , worried about mysql server, cost too much resource

    Addtion Question: any one konw about php HTML staticstic , i mean generate html file for most not change page , so speed up the forums ,and cost less resource ~

  • Best keep it to one question per thread

    There was an error rendering this rich post.

Sign In or Register to comment.