.
*/
declare(strict_types=1);
namespace Fisharebest\Webtrees\Statistics\Repository;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Contracts\UserInterface;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Services\UserService;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\UserRepositoryInterface;
use Fisharebest\Webtrees\Tree;
/**
* A repository providing methods for user related statistics.
*/
class UserRepository implements UserRepositoryInterface
{
/**
* @var Tree
*/
private $tree;
/**
* @var UserService
*/
private $user_service;
/**
* Constructor.
*
* @param Tree $tree
* @param UserService $user_service
*/
public function __construct(Tree $tree, UserService $user_service)
{
$this->tree = $tree;
$this->user_service = $user_service;
}
/**
* Who is currently logged in?
*
* @TODO - this is duplicated from the LoggedInUsersModule class.
*
* @param string $type
*
* @return string
*/
private function usersLoggedInQuery($type = 'nolist'): string
{
$content = '';
// List active users
$NumAnonymous = 0;
$loggedusers = [];
foreach ($this->user_service->allLoggedIn() as $user) {
if (Auth::isAdmin() || $user->getPreference('visibleonline')) {
$loggedusers[] = $user;
} else {
$NumAnonymous++;
}
}
$LoginUsers = \count($loggedusers);
if ($LoginUsers === 0 && $NumAnonymous === 0) {
return I18N::translate('No signed-in and no anonymous users');
}
if ($NumAnonymous > 0) {
$content .= '' . I18N::plural('%s anonymous signed-in user', '%s anonymous signed-in users', $NumAnonymous, I18N::number($NumAnonymous)) . '';
}
if ($LoginUsers > 0) {
if ($NumAnonymous) {
if ($type === 'list') {
$content .= '
';
} else {
$content .= ' ' . I18N::translate('and') . ' ';
}
}
$content .= '' . I18N::plural('%s signed-in user', '%s signed-in users', $LoginUsers, I18N::number($LoginUsers)) . '';
if ($type === 'list') {
$content .= '