add most des
This commit is contained in:
parent
a84bc451b8
commit
c73e2ca760
77
hesabixCore/src/Controller/MostdesController.php
Normal file
77
hesabixCore/src/Controller/MostdesController.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\Log;
|
||||
use App\Service\Jdate;
|
||||
use App\Entity\MostDes;
|
||||
use App\Service\Access;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class MostdesController extends AbstractController
|
||||
{
|
||||
#[Route('/api/mostdes/list', name: 'api_mostdes_list')]
|
||||
public function api_mostdes_list(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);
|
||||
}
|
||||
$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]);
|
||||
}
|
||||
}
|
|
@ -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<int, MostDes>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
82
hesabixCore/src/Entity/MostDes.php
Normal file
82
hesabixCore/src/Entity/MostDes.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\MostDesRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: MostDesRepository::class)]
|
||||
class MostDes
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'mostDes')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Business $bid = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'mostDes')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $submitter = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $des = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $type = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
|
@ -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<int, MostDes>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
48
hesabixCore/src/Repository/MostDesRepository.php
Normal file
48
hesabixCore/src/Repository/MostDesRepository.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\MostDes;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<MostDes>
|
||||
*
|
||||
* @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()
|
||||
// ;
|
||||
// }
|
||||
}
|
Loading…
Reference in a new issue