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

39 lines
733 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(
2024-11-12 10:11:21 +01:00
private readonly IFactory $l10n,
private readonly 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());
2024-11-10 13:18:53 +01:00
return $isoCodes[1] ?? 'us';
2023-07-28 03:00:38 +02:00
}
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];
}
}