major update
This commit is contained in:
@@ -7,13 +7,19 @@ use MintyPHP\Service\CustomField\UserCustomFieldValueService;
|
||||
|
||||
class AddressBookCustomFieldGateway
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UserCustomFieldValueService $userCustomFieldValueService
|
||||
) {
|
||||
}
|
||||
|
||||
public function extractFilterSpec(array $query, int $currentUserId): array
|
||||
{
|
||||
return UserCustomFieldValueService::extractAddressBookFilterSpec($query, $currentUserId);
|
||||
return $this->userCustomFieldValueService->extractAddressBookFilterSpec($query, $currentUserId);
|
||||
}
|
||||
|
||||
public function listOptionsByDefinitionIds(array $definitionIds, bool $activeOnly = true): array
|
||||
{
|
||||
return TenantCustomFieldOptionRepository::listByDefinitionIds($definitionIds, $activeOnly);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ use MintyPHP\Service\Tenant\TenantService;
|
||||
class AddressBookDirectoryGateway
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ?TenantService $tenantService = null,
|
||||
private readonly ?DepartmentService $departmentService = null,
|
||||
private readonly ?RoleService $roleService = null,
|
||||
private readonly ?DirectoryScopeGateway $scopeGateway = null
|
||||
private readonly TenantService $tenantService,
|
||||
private readonly DepartmentService $departmentService,
|
||||
private readonly RoleService $roleService,
|
||||
private readonly DirectoryScopeGateway $scopeGateway
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -54,21 +54,21 @@ class AddressBookDirectoryGateway
|
||||
|
||||
private function tenantService(): TenantService
|
||||
{
|
||||
return $this->tenantService ?? new TenantService();
|
||||
return $this->tenantService;
|
||||
}
|
||||
|
||||
private function departmentService(): DepartmentService
|
||||
{
|
||||
return $this->departmentService ?? new DepartmentService();
|
||||
return $this->departmentService;
|
||||
}
|
||||
|
||||
private function roleService(): RoleService
|
||||
{
|
||||
return $this->roleService ?? new RoleService();
|
||||
return $this->roleService;
|
||||
}
|
||||
|
||||
private function scopeGateway(): DirectoryScopeGateway
|
||||
{
|
||||
return $this->scopeGateway ?? new DirectoryScopeGateway();
|
||||
return $this->scopeGateway;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,28 +104,27 @@ class AddressBookService
|
||||
unset($definition);
|
||||
|
||||
$tenantDepartmentMap = [];
|
||||
if ($tenantIds) {
|
||||
$departmentMapByTenantId = [];
|
||||
foreach ($departments as $department) {
|
||||
$departmentId = (int) ($department['id'] ?? 0);
|
||||
$departmentTenantId = (int) ($department['tenant_id'] ?? 0);
|
||||
if ($departmentId <= 0 || $departmentTenantId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$departmentMapByTenantId[$departmentTenantId] ??= [];
|
||||
$departmentMapByTenantId[$departmentTenantId][] = $departmentId;
|
||||
$departmentMapByTenantId = [];
|
||||
foreach ($departments as $department) {
|
||||
$departmentId = (int) ($department['id'] ?? 0);
|
||||
$departmentTenantId = (int) ($department['tenant_id'] ?? 0);
|
||||
if ($departmentId <= 0 || $departmentTenantId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$departmentMapByTenantId[$departmentTenantId] ??= [];
|
||||
$departmentMapByTenantId[$departmentTenantId][] = $departmentId;
|
||||
}
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
$tenantId = (int) ($tenant['id'] ?? 0);
|
||||
$tenantUuid = (string) ($tenant['uuid'] ?? '');
|
||||
if ($tenantId > 0 && $tenantUuid !== '') {
|
||||
$tenantDepartmentMap[$tenantUuid] = array_map(
|
||||
'strval',
|
||||
$departmentMapByTenantId[$tenantId] ?? []
|
||||
);
|
||||
}
|
||||
foreach ($tenants as $tenant) {
|
||||
$tenantId = (int) ($tenant['id'] ?? 0);
|
||||
$tenantUuid = (string) ($tenant['uuid'] ?? '');
|
||||
if ($tenantId <= 0 || $tenantUuid === '') {
|
||||
continue;
|
||||
}
|
||||
$tenantDepartmentMap[$tenantUuid] = array_map(
|
||||
'strval',
|
||||
$departmentMapByTenantId[$tenantId] ?? []
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace MintyPHP\Service\AddressBook;
|
||||
|
||||
use MintyPHP\Service\CustomField\CustomFieldServicesFactory;
|
||||
use MintyPHP\Service\Directory\DirectoryServicesFactory;
|
||||
use MintyPHP\Service\User\UserServicesFactory;
|
||||
|
||||
@@ -11,8 +12,12 @@ class AddressBookServicesFactory
|
||||
private ?AddressBookCustomFieldGateway $addressBookCustomFieldGateway = null;
|
||||
private ?AddressBookAvatarGateway $addressBookAvatarGateway = null;
|
||||
private ?AddressBookService $addressBookService = null;
|
||||
private ?UserServicesFactory $userServicesFactory = null;
|
||||
private ?DirectoryServicesFactory $directoryServicesFactory = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly UserServicesFactory $userServicesFactory,
|
||||
private readonly DirectoryServicesFactory $directoryServicesFactory,
|
||||
private readonly CustomFieldServicesFactory $customFieldServicesFactory
|
||||
) {}
|
||||
|
||||
public function createAddressBookService(): AddressBookService
|
||||
{
|
||||
@@ -20,7 +25,7 @@ class AddressBookServicesFactory
|
||||
return $this->addressBookService;
|
||||
}
|
||||
|
||||
$userFactory = $this->userServicesFactory();
|
||||
$userFactory = $this->userServicesFactory;
|
||||
return $this->addressBookService = new AddressBookService(
|
||||
$userFactory->createUserAccountService(),
|
||||
$userFactory->createUserAssignmentService(),
|
||||
@@ -36,7 +41,7 @@ class AddressBookServicesFactory
|
||||
return $this->addressBookDirectoryGateway;
|
||||
}
|
||||
|
||||
$directoryFactory = $this->directoryServicesFactory();
|
||||
$directoryFactory = $this->directoryServicesFactory;
|
||||
return $this->addressBookDirectoryGateway = new AddressBookDirectoryGateway(
|
||||
$directoryFactory->createTenantService(),
|
||||
$directoryFactory->createDepartmentService(),
|
||||
@@ -47,23 +52,15 @@ class AddressBookServicesFactory
|
||||
|
||||
public function createAddressBookCustomFieldGateway(): AddressBookCustomFieldGateway
|
||||
{
|
||||
return $this->addressBookCustomFieldGateway ??= new AddressBookCustomFieldGateway();
|
||||
return $this->addressBookCustomFieldGateway ??= new AddressBookCustomFieldGateway(
|
||||
$this->customFieldServicesFactory->createUserCustomFieldValueService()
|
||||
);
|
||||
}
|
||||
|
||||
public function createAddressBookAvatarGateway(): AddressBookAvatarGateway
|
||||
{
|
||||
return $this->addressBookAvatarGateway ??= new AddressBookAvatarGateway(
|
||||
$this->userServicesFactory()->createUserAvatarService()
|
||||
$this->userServicesFactory->createUserAvatarService()
|
||||
);
|
||||
}
|
||||
|
||||
private function userServicesFactory(): UserServicesFactory
|
||||
{
|
||||
return $this->userServicesFactory ??= new UserServicesFactory();
|
||||
}
|
||||
|
||||
private function directoryServicesFactory(): DirectoryServicesFactory
|
||||
{
|
||||
return $this->directoryServicesFactory ??= new DirectoryServicesFactory();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user