JomSocial – Like and Dislike buttons for Discussion in groups

My company decided to have “like” and “dislike” buttons in our JomSocial for Joomla component in… discussions inside of groups. Why? We renamed “discussions” to “reviews” to allow other users to make reviews of other people stuff they put in groups (pics/videos/music). Now we need “Likes” in it. I will show you how to do that.

First of all – grab a good code editor and a FTP/SFTP client. I do prefer Komodo Edit and Cyberduck (that one’s for Mac; for Windows you may use WinSCP).

When you’re ready open those files from your Joomla directory tree (COM_DIR is the directory of your JomSocial frontend component directory – probably /path/to/joomla/components/com_community):

  • COM_DIR/views/groups/view.html.php
  • COM_DIR/templates/name_of_your_template/groups.viewdiscussion.php
In view.html.php scroll to
public function viewdiscussion( )

You should find erase debt this line few lines below:

$isBanned = $group->isBanned( 																																																																																																																																																																																																																																																																																																												housing loans india

$my->id );

Add this:

$isMember   = $group->isMember( $my->id );
CFactory::load( 'libraries' , 'like' );
$likes	    = new CLike();
$likesHTML  = ($isMember && !$isBanned) ?
   $likes->getHTML( 'groups.viewdiscussion', $topicId, $my->id ) :
   $likes->getHtmlPublic( 'groups.viewdiscussion', $topicId );

This code will load the CLike JomSocial library (class) and create the proper HTML we will put later in the template. To pass $likesHTML to the template add this at the bottom of this class (you should get the idea loans quick cash where to put it as there are plenty of similar lines in that area):

$tmpl->set( 'likesHTML' , $likesHTML );

Now, go to groups.viewdiscussion.php (mind the lack of “s” on the end of the file; it’s NOT viewdiscussions). Right after:

<!--Discussion : Detail-->
<div style="clear: both;"></div>

put:

<div class="vidSubmenu clrfix">
    <div id="like-container"><?php 																																																																																																																																																																																																																																																																																																												financing a computer

echo $likesHTML; ?></div>
</div>

Remember the $likesHTML from the first file? That’s it – the core should do the rest and render those buttons with JavaScript attached to them. Here’s the expected effect:

Enjoy!