Wednesday, October 19, 2011

How to override Jomsocial Controller

If you already override jomsocial template files then don't think that in same way you can override controller as well.
Before talking about how to override Jomsocial Controller, lets see why we need to override controller. If you hack the core files directly & made changes as you want. After some day when you upgrade jomsocial then those changes from the hacked files will be removed & then again you have to hack the core files. So this is very tedious task to check which file & what code you have hacked. Solution on hacking is obviously you have to override controller.

To override jomsocial controller you need a plugin which will override controller. In this plugin we just replace default controller object with our own custom class.
Before the system controller is created. Plugin may override the controller class name.
Plugin should contain following code.

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
require_once( JPATH_SITE .'/components/com_community/libraries/core.php');
require_once( JPATH_SITE .'/components/com_community/controllers/mybulletin.php');

class plgCommunityMybulletin extends CApplications
{

function plgCommunityMybulletin(& $subject, $config){
parent::__construct($subject, $config);
}

function onBeforeControllerCreate( &$controllerClassName )
{
$view = JRequest::getVar('view');
if($view == 'groups') {
$controllerClassName = 'MybulletinController'; // MybulletinController is class name which extends in your controller
return true;
}
return false;
}

}

Lets see the how to create controller.
If you wanna override groups controller then copy that file & paste it in the same folder(com_community/controller). Rename that file with what you have mentioned in plugin($controllerClassName value). In this case i rename that file with mybulletin.php & do changes as you want. Just make sure that you have added following line at the top of the file.
jimport ('joomla.application.component.controller');
require_once (COMMUNITY_COM_PATH.DS.'controllers'.DS.'controller.php');
To off email on bulletin creation i did override jomsocial group controller. You can find plugin & controller files here & make changes as you want.

Monday, October 3, 2011

Jomsocial Group Bulletin email off

Working on one of the sport site developed in Joomla, as usual Jomsocial is installed. Client requirement was that he didn't want to get email when users of the site created jomsocial group bulletin. Its jomsocial's default behavior that it sends mail to all member of the group when group bulletin created. I made the correct change in a correct file after spending couple of hours.
If you want to off the mail of group bulletin creation then you need to override Jomsocial group controller. Well you can't override the jomsocial controller file so easily as you override template file.
To know more about how to override jomsocial controller you need to wait for my new post.
Go to the components->com_community->controller->groups.php file & comment the lines from line no. 3014 to 3024. Make sure these line contains the following code.
/*
$model =& $this->getModel( 'groups' );
$memberCount = $model->getMembersCount($groupId);
$members = $model->getMembers($groupId, $memberCount , true , false , SHOW_GROUP_ADMIN );
$membersArray = array();
foreach($members as $row)
{
$membersArray[] = $row->id;
}
unset($members);
*/
After that Jomsocial won't send email to members of the group when member creates bulletin for the group. However this worked for me for Jomsocial 2.2.4 version. I am not sure whether it works for other versions for that you need to just make sure where the above code is & i guess it won't be a big deal.
Note :- Don't waste your time to search back-end option to make jomsocial group bulletin off.