repod/lib/Service/UserService.php

39 lines
733 B
PHP
Raw Normal View History

2023-07-28 01:00:38 +00:00
<?php
declare(strict_types=1);
namespace OCA\RePod\Service;
use OCP\IUserSession;
use OCP\L10N\IFactory;
class UserService
{
public function __construct(
2024-11-12 09:11:21 +00:00
private readonly IFactory $l10n,
private readonly IUserSession $userSession
2023-12-23 16:25:20 +00:00
) {}
2023-07-28 01:00:38 +00:00
2023-12-23 16:25:20 +00:00
public function getUserUID(): string {
2023-08-22 17:41:17 +00:00
$user = $this->userSession->getUser();
return $user ? $user->getUID() : '';
}
2023-12-23 16:25:20 +00:00
public function getIsoCode(): string {
2023-07-28 01:00:38 +00:00
return $this->l10n->getUserLanguage($this->userSession->getUser());
}
2023-12-23 16:25:20 +00:00
public function getCountryCode(): string {
2023-07-28 01:00:38 +00:00
$isoCodes = explode('_', $this->getIsoCode());
2024-11-10 12:18:53 +00:00
return $isoCodes[1] ?? 'us';
2023-07-28 01:00:38 +00:00
}
2023-12-23 16:25:20 +00:00
public function getLangCode(): string {
2023-07-28 01:00:38 +00:00
$isoCodes = explode('_', $this->getIsoCode());
return $isoCodes[0];
}
}