From ca95ec48aaddbb6247bf8156ef48119b8880837f Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Sat, 31 Aug 2024 22:02:28 +0330 Subject: [PATCH] add options for remove business --- .../src/Controller/BusinessController.php | 37 +++++++++++++++++++ hesabixCore/src/Entity/Business.php | 15 ++++++++ 2 files changed, 52 insertions(+) diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index ca39c25..cc8df01 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -17,6 +17,7 @@ use App\Entity\Hook; use App\Entity\Year; use App\Service\Access; use App\Service\Explore; +use App\Service\Extractor; use App\Service\Jdate; use App\Service\Log; use App\Service\Provider; @@ -33,6 +34,41 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser; class BusinessController extends AbstractController { + #[Route('/api/business/delete', name: 'api_business_delete')] + public function api_business_delete(Extractor $extractor, Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): Response + { + $acc = $access->hasRole('owner'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $archiveUser = $entityManager->getRepository(User::class)->findOneBy([ + 'email'=>'archive@hesabix.ir' + ]); + if(! $archiveUser){ + $archiveUser = new User(); + $archiveUser->setEmail('archive@hesabix.ir'); + $archiveUser->setFullName('کاربر آرشیو و بایگانی'); + $archiveUser->setPassword(0); + $archiveUser->setDateRegister(time()); + $archiveUser->setActive(false); + $entityManager->persist($archiveUser); + $entityManager->flush(); + } + $acc['bid']->setOwner($archiveUser); + $acc['bid']->setArchiveEmail($this->getUser()->getEmail()); + $entityManager->persist($acc['bid']); + $entityManager->flush(); + + //remove permissions + $permissions = $entityManager->getRepository(Permission::class)->findBy([ + 'bid'=>$acc['bid'] + ]); + foreach($permissions as $perm){ + $entityManager->remove($perm); + $entityManager->flush(); + } + return $this->json($extractor->operationSuccess()); + } #[Route('/api/business/list', name: 'api_bussiness_list')] public function api_bussiness_list(#[CurrentUser] ?User $user, EntityManagerInterface $entityManager, Provider $provider): Response { @@ -271,6 +307,7 @@ class BusinessController extends AbstractController return $this->json(['result' => 1]); } + #[Route('/api/business/add/user', name: 'api_business_add_user')] public function api_business_add_user(Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): Response { diff --git a/hesabixCore/src/Entity/Business.php b/hesabixCore/src/Entity/Business.php index e50e9bf..0e11c9f 100644 --- a/hesabixCore/src/Entity/Business.php +++ b/hesabixCore/src/Entity/Business.php @@ -234,6 +234,9 @@ class Business #[ORM\OneToMany(mappedBy: 'bid', targetEntity: PrintOptions::class, orphanRemoval: true)] private Collection $printOptions; + #[ORM\Column(length: 255, nullable: true)] + private ?string $archiveEmail = null; + public function __construct() { $this->logs = new ArrayCollection(); @@ -1690,4 +1693,16 @@ class Business return $this; } + + public function getArchiveEmail(): ?string + { + return $this->archiveEmail; + } + + public function setArchiveEmail(?string $archiveEmail): static + { + $this->archiveEmail = $archiveEmail; + + return $this; + } }