repod/lib/Service/UserService.php

39 lines
736 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(
private IFactory $l10n,
private 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());
return isset($isoCodes[1]) ? $isoCodes[1] : 'us';
}
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];
}
}