duanbipu1720 2014-12-15 17:58
浏览 16

如何获取JomSocial用户组计数

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.

  • 写回答

1条回答 默认 最新

  • duanji1026 2014-12-16 20:51
    关注

    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();
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制