XF 2.1 How to show all reactions inside post?

calopezes

Member
Istead
Reactions: user1, user2, user3 and 6 others
I would like
Reactions: user1, user2, user3 user4, user5, user6, user7, user8 and user9

Is this possible?
Any help?
 
You can simply edit /src/XF/Entity/Thread.php and add a function like the following one I created, which will return a list of usernames who reacted to the first post of the thread:


Code:
public function countReactList()
    {

               $firstPost = $this->db()->fetchRow("
                    SELECT post_id, thread_id
                    FROM xf_post
                    WHERE thread_id = ?
                    LIMIT 1
                ", $this->thread_id);

                $this->first_post_id = $firstPost['post_id'];

                $reactions = \XF::db()->fetchAll('SELECT user.username as username
                        FROM xf_reaction_content AS reacted
                        INNER JOIN xf_user AS user ON (reacted.reaction_user_id = user.user_id)
                        INNER JOIN xf_reaction AS reaction ON (reacted.reaction_id = reaction.reaction_id)
                        WHERE reacted.content_type = ? AND reacted.content_id = ? AND reaction.active = 1
                        ORDER BY reacted.reaction_date DESC', ['post', $this->first_post_id]);

                       $list = array();

                       foreach($reactions as $like){
                              $list[] = $like['username'];
                       }
              
                       $list = implode(', ', $list);
              
                       return $list;
}

And then, in thread_view you can add {{ $thread.countReactList() }} wherever you'd like to display this list, eventually restricting it to certain user groups etc..

I hope it helped.

Please note this is tested on XF2.1.x , I can't guarantee for newer versions, but the concept is quite simple to understand.
 
Top Bottom