Count all active and non-invisible members for guests on space directory (#6162)

This commit is contained in:
Yuriy Bakhtin 2023-03-13 21:12:31 +04:00 committed by GitHub
parent 569992aba5
commit 448f4ee2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ namespace humhub\modules\space\widgets;
use humhub\components\Widget;
use humhub\modules\space\models\Membership;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use Yii;
/**
@ -36,11 +37,16 @@ class SpaceDirectoryIcons extends Widget
}
$membership = $this->space->getMembership();
$membersCount = Membership::getSpaceMembersQuery($this->space)->active()->visible()->count();
$membersCountQuery = Membership::getSpaceMembersQuery($this->space)->active();
if (Yii::$app->user->isGuest) {
$membersCountQuery->andWhere(['!=', 'user.visibility', User::VISIBILITY_HIDDEN]);
} else {
$membersCountQuery->visible();
}
return $this->render('spaceDirectoryIcons', [
'space' => $this->space,
'membersCount' => Yii::$app->formatter->asShortInteger($membersCount),
'membersCount' => Yii::$app->formatter->asShortInteger($membersCountQuery->count()),
'canViewMembers' => $membership && $membership->isPrivileged(),
]);
}