diff --git a/hesabixCore/src/Controller/MostdesController.php b/hesabixCore/src/Controller/MostdesController.php new file mode 100644 index 0000000..183d2dd --- /dev/null +++ b/hesabixCore/src/Controller/MostdesController.php @@ -0,0 +1,77 @@ +hasRole('join'); + if (!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + $items = $entityManager->getRepository(MostDes::class)->findBy([ + 'bid' => $acc['bid'], + 'submitter' => $this->getUser(), + 'type' => $params['type'] + ]); + $result = []; + foreach ($items as $item) { + $result[] = [ + 'id'=>$item->getId(), + 'des'=>$item->getDes() + ]; + } + return $this->json($result); + } + + #[Route('/api/mostdes/add', name: 'api_mostdes_add')] + public function api_mostdes_add(Request $request, Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse + { + $acc = $access->hasRole('join'); + if (!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + $des = new MostDes(); + $des->setBid($acc['bid']); + $des->setSubmitter($this->getUser()); + $des->setType($params['type']); + $des->setDes($params['des']); + $entityManager->persist($des); + $entityManager->flush(); + return $this->json(['result' => 1]); + } + #[Route('/api/mostdes/remove/{id}', name: 'api_mostdes_remove')] + public function api_mostdes_remove(string $id, Request $request, Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse + { + $acc = $access->hasRole('join'); + if (!$acc) + throw $this->createAccessDeniedException(); + $item = $entityManager->getRepository(MostDes::class)->findOneBy([ + 'bid' => $acc['bid'], + 'submitter' => $this->getUser(), + 'id' => $id + ]); + $entityManager->remove($item); + $entityManager->flush(); + return $this->json(['result' => 1]); + } +} diff --git a/hesabixCore/src/Entity/Business.php b/hesabixCore/src/Entity/Business.php index 7f7f570..cfadcea 100644 --- a/hesabixCore/src/Entity/Business.php +++ b/hesabixCore/src/Entity/Business.php @@ -208,6 +208,9 @@ class Business #[ORM\OneToMany(mappedBy: 'bid', targetEntity: PersonCard::class, orphanRemoval: true)] private Collection $personCards; + #[ORM\OneToMany(mappedBy: 'bid', targetEntity: MostDes::class, orphanRemoval: true)] + private Collection $mostDes; + public function __construct() { $this->logs = new ArrayCollection(); @@ -235,6 +238,7 @@ class Business $this->hooks = new ArrayCollection(); $this->cheques = new ArrayCollection(); $this->personCards = new ArrayCollection(); + $this->mostDes = new ArrayCollection(); } public function getId(): ?int @@ -1423,4 +1427,34 @@ class Business return $this; } + + /** + * @return Collection + */ + public function getMostDes(): Collection + { + return $this->mostDes; + } + + public function addMostDe(MostDes $mostDe): static + { + if (!$this->mostDes->contains($mostDe)) { + $this->mostDes->add($mostDe); + $mostDe->setBid($this); + } + + return $this; + } + + public function removeMostDe(MostDes $mostDe): static + { + if ($this->mostDes->removeElement($mostDe)) { + // set the owning side to null (unless already changed) + if ($mostDe->getBid() === $this) { + $mostDe->setBid(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/MostDes.php b/hesabixCore/src/Entity/MostDes.php new file mode 100644 index 0000000..dfc00cf --- /dev/null +++ b/hesabixCore/src/Entity/MostDes.php @@ -0,0 +1,82 @@ +id; + } + + public function getBid(): ?Business + { + return $this->bid; + } + + public function setBid(?Business $bid): static + { + $this->bid = $bid; + + return $this; + } + + public function getSubmitter(): ?User + { + return $this->submitter; + } + + public function setSubmitter(?User $submitter): static + { + $this->submitter = $submitter; + + return $this; + } + + public function getDes(): ?string + { + return $this->des; + } + + public function setDes(string $des): static + { + $this->des = $des; + + return $this; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(string $type): static + { + $this->type = $type; + + return $this; + } +} diff --git a/hesabixCore/src/Entity/User.php b/hesabixCore/src/Entity/User.php index 9e924bb..f67b346 100644 --- a/hesabixCore/src/Entity/User.php +++ b/hesabixCore/src/Entity/User.php @@ -104,6 +104,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\OneToMany(mappedBy: 'submitter', targetEntity: Cheque::class, orphanRemoval: true)] private Collection $cheques; + #[ORM\OneToMany(mappedBy: 'submitter', targetEntity: MostDes::class, orphanRemoval: true)] + private Collection $mostDes; + public function __construct() { $this->userTokens = new ArrayCollection(); @@ -125,6 +128,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface $this->archiveOrders = new ArrayCollection(); $this->hooks = new ArrayCollection(); $this->cheques = new ArrayCollection(); + $this->mostDes = new ArrayCollection(); } public function getId(): ?int @@ -838,4 +842,34 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + /** + * @return Collection + */ + public function getMostDes(): Collection + { + return $this->mostDes; + } + + public function addMostDe(MostDes $mostDe): static + { + if (!$this->mostDes->contains($mostDe)) { + $this->mostDes->add($mostDe); + $mostDe->setSubmitter($this); + } + + return $this; + } + + public function removeMostDe(MostDes $mostDe): static + { + if ($this->mostDes->removeElement($mostDe)) { + // set the owning side to null (unless already changed) + if ($mostDe->getSubmitter() === $this) { + $mostDe->setSubmitter(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Repository/MostDesRepository.php b/hesabixCore/src/Repository/MostDesRepository.php new file mode 100644 index 0000000..f15ebab --- /dev/null +++ b/hesabixCore/src/Repository/MostDesRepository.php @@ -0,0 +1,48 @@ + + * + * @method MostDes|null find($id, $lockMode = null, $lockVersion = null) + * @method MostDes|null findOneBy(array $criteria, array $orderBy = null) + * @method MostDes[] findAll() + * @method MostDes[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class MostDesRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, MostDes::class); + } + +// /** +// * @return MostDes[] Returns an array of MostDes objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('m') +// ->andWhere('m.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('m.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?MostDes +// { +// return $this->createQueryBuilder('m') +// ->andWhere('m.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}