58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\Actions;
|
|
use App\Entity\Organizations;
|
|
use App\Entity\User;
|
|
use App\Entity\UsersOrganizations;
|
|
use App\Service\ActionService;
|
|
use \App\Service\UserOrganizationAppService;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
/**
|
|
* Service pour la gestion des organisations d'utilisateurs.
|
|
* Fournit des méthodes pour récupérer, modifier et désactiver les rôles et applications d'un utilisateur dans une organisation.
|
|
*/
|
|
readonly class UserOrganizationService
|
|
{
|
|
|
|
public function __construct(
|
|
private userOrganizationAppService $userOrganizationAppService, private EntityManagerInterface $entityManager, private ActionService $actionService,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Deactive all user organization links.
|
|
*
|
|
* @param User $user
|
|
* @param User $actingUser
|
|
* @return void
|
|
*/
|
|
public function deactivateAllUserOrganizationLinks(User $actingUser, User $user = null, Organizations $organizations = null): void{
|
|
if($user !== null) {
|
|
$uos = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'isActive' => true]);
|
|
}elseif($organizations !== null){
|
|
$uos = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['organization' => $organizations, 'isActive' => true]);
|
|
}
|
|
foreach ($uos as $uo) {
|
|
$this->userOrganizationAppService->deactivateAllUserOrganizationsAppLinks($uo);
|
|
$uo->setIsActive(false);
|
|
$this->entityManager->persist($uo);
|
|
$this->actionService->createAction("Deactivate UO link", $actingUser, $uo->getOrganization(), $uo->getOrganization()->getName() );
|
|
}
|
|
}
|
|
|
|
public function getByIdOrFail(int $id): UsersOrganizations
|
|
{
|
|
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->find($id);
|
|
if (!$uo) {
|
|
throw new NotFoundHttpException("UserOrganization not found");
|
|
}
|
|
return $uo;
|
|
}
|
|
|
|
|
|
}
|