XF 2.1 HIde usergropu from online

gaga

Member
Hello,
I want to do something, but I need your help.
So in /online/ I want to hide (not shown) the users from specific user group (e.x moderators) I used this
Code:
XF\Option\UserGroup::renderSelectMultiple
to select user groups to show in online, all exclude will be hide for all (visitors and members)

Thanks.
 
.you should extend the class XF\Finder\SessionActivity with this code
PHP:
<?php

namespace BS\WhereIsMyGroups\XF\Finder;

class SessionActivity extends XFCP_SessionActivity
{
    public function applyMemberVisibilityRestriction()
    {
        parent::applyMemberVisibilityRestriction();

        $excludeGroups = $this->app()->options()->whereIsMyGroupsExclude;
        if ($excludeGroups)
        {
            $notUserGroupWhere = [
                ['User.user_group_id', '<>', $excludeGroups]
            ];

            foreach ($excludeGroups as $groupId)
            {
                $notUserGroupWhere[] = $this->expression(
                    'NOT FIND_IN_SET(' . $this->quote($groupId) . ', %s)',
                    'User.secondary_group_ids'
                );
            }

            $this->where($notUserGroupWhere);
        }

        return $this;
    }
}
 
.you should extend the class XF\Finder\SessionActivity with this code
PHP:
<?php

namespace BS\WhereIsMyGroups\XF\Finder;

class SessionActivity extends XFCP_SessionActivity
{
    public function applyMemberVisibilityRestriction()
    {
        parent::applyMemberVisibilityRestriction();

        $excludeGroups = $this->app()->options()->whereIsMyGroupsExclude;
        if ($excludeGroups)
        {
            $notUserGroupWhere = [
                ['User.user_group_id', '<>', $excludeGroups]
            ];

            foreach ($excludeGroups as $groupId)
            {
                $notUserGroupWhere[] = $this->expression(
                    'NOT FIND_IN_SET(' . $this->quote($groupId) . ', %s)',
                    'User.secondary_group_ids'
                );
            }

            $this->where($notUserGroupWhere);
        }

        return $this;
    }
}
Thanks, work.
Just one question the same, but in conversation (does not show in Conversation participants sidebar).
 
.you can make a modification

Template: conversation_view
Search type: Regular expression
Find: /(<xf:foreach loop="\$recipients" value="\$recipient">)(.*?)(<\/xf:foreach>)/s
Replace:
Code:
$1
<xf:if is="$recipient.user_id != $xf.visitor.user_id && !$recipient.User.isMemberOf($xf.options.ourOptionGroups)">
    $2
</xf:if>
$3
 
I try using the code above to hide from conversation_list, but get error:
Code:
Template public:conversation_list_macros: Cannot call method isMemberOf on a non-object (NULL) (src\XF\Template\Templater.php:984)

The code is:
Code:
conversation_list_macros
FInd:
Code:
/(<xf:foreach loop="\$userConv.Master.recipients" value="\$recipient" if="{\$recipient.user_id} != \{\$userConv.Master.user_id}">)(.*?)(<\/xf:foreach>)/s

Replace:
Code:
$1
<xf:if is="!$recipient.User.isMemberOf($xf.options.myAddonExcludeUserGroups)">
    $2
</xf:if>
$3

Where is the problem?
Thanks.
 
try this

HTML:
$1
<xf:if is="!in_array($recipient.user_group_id,$xf.options.myAddonExcludeUserGroups)">
    $2
</xf:if>
$3
 
Top Bottom