0

I am using Joomla and JomSocial to develop a social platform.

JomSocial comes with some codes in the documentation, that allows me to retrieve certain information about the JomSocial user.

For example:

If i want to retrieve the JomSocial User Name, i can use this code here >

<?php
include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
// Get CUser object
$user  = CFactory::getUser( $userid );
$name = $user->getDisplayName();
echo ' '.$name ;
?>

The above code will display the JomSocial User Name for the currently logged in user.

Another example:

If i want to retrieve the JomSocial User Friend Count, i can use this code here >

<?php
include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
// Get CUser object Friend Count
$cuser = CFactory::getUser();
$data = $cuser->getFriendCount();
echo $data;
?>

The above code, will display the number of friends for the currently logged in viewing user.

I use these codes, and add them into my custom Joomla template, to build a user dashboard area for my users, so my users can monitor their various activities on my website.

I would like also, to be able to display to my users their JomSocial Group Count.

For example:

If Joe Blogs has joined 4 JomSocial Groups. I need the code that would display the data count of: 4

How to get the JomSocial User Group Count ?

I have looked through the JomSocial Documentation, and it does not provide an answer to this particular question. It does explain:

There are several ways you can retrieve the user object which is going to be manipulated. The basic way to retrieve the currently logged in user is shown below. If no one is logged in, it will return "guest" object.

$cuser = CFactory::getUser();

Thank you for your help and support.

CyborgTeq
  • 1
  • 3

1 Answers1

1

JomSocial does not have a variable for this, but you can get the count easily:

<?php
$cuser = CFactory::getUser();
$db = JFactory::getDBO();
$db->setQuery( "SELECT COUNT(DISTINCT `groupid`) FROM #__community_groups_members WHERE `memberid`='{$cuser->id}' AND `approved`='1'" );
$groupCount = $db->loadResult();
?>
Mike Feng
  • 803
  • 2
  • 9
  • 19
  • Hi Mike Feng. Thank you very much for your reply. I have tested the code you have provided, and it does not appear to work. The code displays no results for the logged in user. I have added the code into my Joomla template index.php file, and it displays nothing. Please help! Your reply is really appreciated. Please could you check the code, could it be possible, there is something incorrect ? – CyborgTeq Dec 17 '14 at 11:32
  • Hi Mike Feng. If it helps to know. I am using Joomla Version 3.3.6, and also, latest version of JomSocial, Version 3.2.1.5 – CyborgTeq Dec 17 '14 at 11:38