• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Adding Like Ratio in Messages

#1
Hi,

This is my first time developing for Xenforo so bear with me if I say something stupid haha. I wanted to create an add-on to show the ratio between likes received and likes given for each user's post.

This is how I'm approaching it:

1.
Created a template_hook for "extra_user_info" to run 'Like_Ratio_Listener' class and function 'template_hook'

2.
My code in Like_Ratio_Listener (I already created a model to run an sql query to grab the liked given and liked received then dividing them to get the ratio. Right now, I need to find a way to grab the userid from the message for $USERIDHERE to output the ratio :

PHP:
    public static function template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template){
        if($hookName == 'message_user_info_extra')
        {
            $model = new LikeRatio_Model_LikeRatioModel();
            $input = array('ratio'=> $model -> getAllLikesGiven($USERIDHERE));
            $ourTemplate = $template->create('like_ratio_post', $input);
            $rendered = $ourTemplate->render();
            $contents .= $rendered;
        }
    }
3. So my main question is, how would I grab the user_id of the message to put it into my model.

Thank you so much for the help!
 

Jeremy

Well-known member
#2
Template Hooks inject code that is later rendered. You cannot get the current post user id when you are using template hooks.