I’m currently building a multilingual health focused community site, FitTogether (note: at time of writing still under construction!). We’re using Joomla 1.5 along with a variety of third party components, including Community Builder, GroupJive and Kunena forum components. GroupJive allows you to create private and public groups that site members can create and join. It has the ability to send “bulletins” to group members, but no inbuilt discussion forum ability. That has been solved by integrating it with the Kunena forum component. But there’s a problem – neither Joomla 1.5 nor Kunena currently allow you to restrict access to forums to particular site members or groups of site members.

This functionality is planned with Joomla 1.6, but as is often the case, I needed a solution now. Fortunately I managed to come up with one and I thought I’d share it.

The solution uses Stephen Brandon’s powerful MetaMod module. MetaMod allows you to enable various “rules” on a Joomla page for turning modules on and off, writing particular messages, redirecting – whatever you can come up with. Using MetaMod I created a rule that checks to see if the logged on user is a member of the GroupJive group connected to the forum he/she is trying to view. If they are not then it redirects them to another page. It does the same if anyone attempts to view the parent category. This step isn’t necessary if the parent category is unpublished in Kunena.

To enable this solution, download and install MetaMod and publish it on the Kunena forum component page. In my template I publish it with no title, in the footer, and with class -nobox so that it’s effectively invisible to users. In the module itself I set the following PHP code –

//
// Block access to GroupJive Forums
//
$group_catid=21;
$redirect_url='/';
$catid = JRequest::getVar("catid");
//Redirect if in main group category
if ($catid==$group_catid)
{
      $app->redirect($redirect_url);
}
// check if forum is in group category
$query="select parent from jos_fb_categories where id=".$catid;
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$parent_id= $row->parent;
if ($parent_id==$group_catid)
{
$username = $user->username;
$gj_query = "SELECT username FROM jos_gj_users
INNER JOIN jos_gj_jb ON jos_gj_users.id_group=jos_gj_jb.group_id 
where category_id=".$catid." and username='".$username."'";
$db->setQuery( $gj_query, 0, 1 );
$gj_row = $db->loadObject();
$gj_username = $gj_row->username;
if (is_null($gj_username))
{
      $app->redirect($redirect_url);
}
}

There are two things you need to change in the first few lines of code. $group_catid should be set to the Kunena category ID where your having GroupJive create forums. $redirect_url should be set to wherever you want the user to end up instead of the private forum. You may want to setup an error message page. In the future I think I’ll set mine to redirect to the main groupjive page with an error message stating the forums are private and they need to join. Alternatively I might simply redirect back to the page they came from. That’s it!