RePod-Nextcloud-App/lib/Service/UserService.php

39 lines
736 B
PHP
Raw Normal View History

2023-07-28 03:00:38 +02: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 17:25:20 +01:00
) {}
2023-07-28 03:00:38 +02:00
2023-12-23 17:25:20 +01:00
public function getUserUID(): string {
2023-08-22 19:41:17 +02:00
$user = $this->userSession->getUser();
return $user ? $user->getUID() : '';
}
2023-12-23 17:25:20 +01:00
public function getIsoCode(): string {
2023-07-28 03:00:38 +02:00
return $this->l10n->getUserLanguage($this->userSession->getUser());
}
2023-12-23 17:25:20 +01:00
public function getCountryCode(): string {
2023-07-28 03:00:38 +02:00
$isoCodes = explode('_', $this->getIsoCode());
return isset($isoCodes[1]) ? $isoCodes[1] : 'us';
}
2023-12-23 17:25:20 +01:00
public function getLangCode(): string {
2023-07-28 03:00:38 +02:00
$isoCodes = explode('_', $this->getIsoCode());
return $isoCodes[0];
}
}