major update
This commit is contained in:
@@ -11,7 +11,12 @@ use MintyPHP\Service\User\UserScopeGateway;
|
||||
|
||||
class UserCustomFieldValueService
|
||||
{
|
||||
public static function validateForTenants(array $tenantIds, array $post, bool $canEdit): array
|
||||
public function __construct(
|
||||
private readonly UserScopeGateway $userScopeGateway
|
||||
) {
|
||||
}
|
||||
|
||||
public function validateForTenants(array $tenantIds, array $post, bool $canEdit): array
|
||||
{
|
||||
if (!$canEdit) {
|
||||
return ['ok' => true, 'errors' => []];
|
||||
@@ -20,14 +25,14 @@ class UserCustomFieldValueService
|
||||
if (!$tenantIds) {
|
||||
return ['ok' => true, 'errors' => []];
|
||||
}
|
||||
$prepared = self::prepareForSync($tenantIds, $post);
|
||||
$prepared = $this->prepareForSync($tenantIds, $post);
|
||||
if ($prepared['errors']) {
|
||||
return ['ok' => false, 'errors' => $prepared['errors']];
|
||||
}
|
||||
return ['ok' => true, 'errors' => []];
|
||||
}
|
||||
|
||||
public static function buildDefinitionsByTenant(array $tenantIds, bool $includeInactive = false): array
|
||||
public function buildDefinitionsByTenant(array $tenantIds, bool $includeInactive = false): array
|
||||
{
|
||||
$tenantIds = self::normalizeTenantIds($tenantIds);
|
||||
if (!$tenantIds) {
|
||||
@@ -69,7 +74,7 @@ class UserCustomFieldValueService
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
public static function buildUserValueMap(int $userId, array $definitionIds): array
|
||||
public function buildUserValueMap(int $userId, array $definitionIds): array
|
||||
{
|
||||
if ($userId <= 0) {
|
||||
return [];
|
||||
@@ -122,7 +127,7 @@ class UserCustomFieldValueService
|
||||
* from user assignment context, each with at least id/uuid/description/status.
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public static function buildPublicValuesByTenant(int $userId, array $tenantSummaries, ?int $tenantScopeId = null): array
|
||||
public function buildPublicValuesByTenant(int $userId, array $tenantSummaries, ?int $tenantScopeId = null): array
|
||||
{
|
||||
if ($userId <= 0) {
|
||||
return [];
|
||||
@@ -154,7 +159,7 @@ class UserCustomFieldValueService
|
||||
}
|
||||
|
||||
$tenantIds = array_keys($orderedTenants);
|
||||
$definitionsByTenant = self::buildDefinitionsByTenant($tenantIds, false);
|
||||
$definitionsByTenant = $this->buildDefinitionsByTenant($tenantIds, false);
|
||||
if (!$definitionsByTenant) {
|
||||
return [];
|
||||
}
|
||||
@@ -169,7 +174,7 @@ class UserCustomFieldValueService
|
||||
}
|
||||
}
|
||||
$definitionIds = array_values(array_unique($definitionIds));
|
||||
$valueMap = self::buildUserValueMap($userId, $definitionIds);
|
||||
$valueMap = $this->buildUserValueMap($userId, $definitionIds);
|
||||
|
||||
$result = [];
|
||||
foreach ($tenantIds as $tenantId) {
|
||||
@@ -239,7 +244,7 @@ class UserCustomFieldValueService
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function syncForUser(int $userId, array $tenantIds, array $post, bool $canEdit): array
|
||||
public function syncForUser(int $userId, array $tenantIds, array $post, bool $canEdit): array
|
||||
{
|
||||
if ($userId <= 0) {
|
||||
return ['ok' => false, 'errors' => [t('User not found')]];
|
||||
@@ -258,7 +263,7 @@ class UserCustomFieldValueService
|
||||
return ['ok' => true, 'errors' => []];
|
||||
}
|
||||
|
||||
$prepared = self::prepareForSync($tenantIds, $post);
|
||||
$prepared = $this->prepareForSync($tenantIds, $post);
|
||||
if ($prepared['errors']) {
|
||||
return ['ok' => false, 'errors' => $prepared['errors']];
|
||||
}
|
||||
@@ -306,9 +311,9 @@ class UserCustomFieldValueService
|
||||
return ['ok' => true, 'errors' => []];
|
||||
}
|
||||
|
||||
private static function prepareForSync(array $tenantIds, array $post): array
|
||||
private function prepareForSync(array $tenantIds, array $post): array
|
||||
{
|
||||
$definitionsByTenant = self::buildDefinitionsByTenant($tenantIds, false);
|
||||
$definitionsByTenant = $this->buildDefinitionsByTenant($tenantIds, false);
|
||||
$definitions = [];
|
||||
foreach ($definitionsByTenant as $tenantDefinitionList) {
|
||||
foreach ($tenantDefinitionList as $definition) {
|
||||
@@ -404,9 +409,9 @@ class UserCustomFieldValueService
|
||||
return ['prepared' => $prepared, 'errors' => $errors];
|
||||
}
|
||||
|
||||
public static function extractAddressBookFilterSpec(array $query, int $currentUserId): array
|
||||
public function extractAddressBookFilterSpec(array $query, int $currentUserId): array
|
||||
{
|
||||
$tenantIds = (new UserScopeGateway())->getUserTenantIds($currentUserId);
|
||||
$tenantIds = $this->userScopeGateway()->getUserTenantIds($currentUserId);
|
||||
$definitions = TenantCustomFieldDefinitionRepository::listFilterableByTenantIds($tenantIds);
|
||||
if (!$definitions) {
|
||||
return ['definitions' => [], 'filters' => [], 'query' => []];
|
||||
@@ -519,6 +524,11 @@ class UserCustomFieldValueService
|
||||
];
|
||||
}
|
||||
|
||||
private function userScopeGateway(): UserScopeGateway
|
||||
{
|
||||
return $this->userScopeGateway;
|
||||
}
|
||||
|
||||
private static function normalizeTenantIds(array $tenantIds): array
|
||||
{
|
||||
$tenantIds = array_values(array_unique(array_map('intval', $tenantIds)));
|
||||
|
||||
Reference in New Issue
Block a user