src/Entity/AppPersonalAccount.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\AppPersonalAccountRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\MaxDepth;
  13. use ApiPlatform\Core\Annotation\ApiProperty;
  14. use App\Filter\CurrentUserFilter;
  15. use ApiPlatform\Metadata\Get;
  16. use ApiPlatform\Metadata\GetCollection;
  17. use ApiPlatform\Metadata\Post;
  18. use ApiPlatform\Metadata\Put;
  19. use ApiPlatform\Metadata\Delete;
  20. #[ORM\Entity(repositoryClassAppPersonalAccountRepository::class)]
  21. #[ApiResource(
  22.     normalizationContext: ['groups' => ['personalAcc:read']],
  23.     denormalizationContext: ['groups' => ['personalAcc:write']],
  24.     order: ['id' => 'DESC'],
  25.     // security: "is_granted('ROLE_USER')",
  26. )]
  27. #[Put(security"object.owner == user")]
  28. #[Get(security"object.owner == user or is_granted('ROLE_ADMIN')")]
  29. #[GetCollection]
  30. #[Delete(security"object.owner == user")]
  31. #[Post(security"is_granted('ROLE_ADMIN')")]
  32. #[ApiFilter(SearchFilter::class, properties: [
  33.     // 'name' => 'ipartial', 
  34.     'owner.id' => 'exact'
  35.     'owner.phone' => 'ipartial'
  36.     'number' => 'exact'
  37.     'parent.id' => 'exact'
  38.     'main' => 'exact'
  39.     // 'manager.id' => 'exact', 
  40.     // 'manager.firstName' => 'ipartial',
  41.     // 'phone' => 'exact',
  42. ])]
  43. #[ApiFilter(CurrentUserFilter::class)]
  44. class AppPersonalAccount
  45. {
  46.     #[ORM\Id]
  47.     #[ORM\GeneratedValue]
  48.     #[ORM\Column]
  49.     #[Groups(['personalAcc:read''personalAcc:write''user:read''service_history:read'])]
  50.     private ?int $id null;
  51.     #[ORM\ManyToOne(inversedBy'appPersonalAccounts')]
  52.     #[ORM\JoinColumn    (nullablefalse)]
  53.     #[Groups(['personalAcc:read'])]
  54.     public ?User $owner null;
  55.     #[ORM\Column(length100)]
  56.     #[Groups(['personalAcc:read''user:read''service_history:read'])]
  57.     private ?string $number null;
  58.     #[ORM\Column(length255nullabletrue)]
  59.     #[Groups(['personalAcc:read''personalAcc:write''user:read''service_history:read'])]
  60.     private ?string $name null;
  61.     #[ORM\Column(nullabletrue)]
  62.     #[Groups(['personalAcc:read''user:read'])]
  63.     private ?int $numberOfScale null;
  64.     #[ORM\Column(nullabletrue)]
  65.     #[Groups(['personalAcc:read''user:read''service_history:read'])]
  66.     private ?bool $active null;
  67.     #[ORM\OneToMany(mappedBy'personal'targetEntityAppCounterReading::class, cascade:['persist''remove'])]
  68.     #[Groups(['personalAcc:read''user:read'])]
  69.     private Collection $appCounterReadings;
  70.     #[ORM\Column(length255nullabletrue)]
  71.     #[Groups(['personalAcc:read''user:read'])]
  72.     private ?string $fullAddress null;
  73.     #[ORM\Column(length100nullabletrue)]
  74.     #[Groups(['personalAcc:read''user:read'])]
  75.     private ?string $city null;
  76.     #[ORM\Column(length100nullabletrue)]
  77.     #[Groups(['personalAcc:read''user:read'])]
  78.     private ?string $street null;
  79.     #[ORM\Column(length100nullabletrue)]
  80.     #[Groups(['personalAcc:read''user:read'])]
  81.     private ?string $building null;
  82.     #[ORM\Column(length100nullabletrue)]
  83.     #[Groups(['personalAcc:read''user:read'])]
  84.     private ?string $room null;
  85.     #[ORM\Column(length255nullabletrue)]
  86.     #[Groups(['personalAcc:read''user:read'])]
  87.     private ?string $mainFullAddress null;
  88.     #[Groups(['personalAcc:read'])]
  89.     #[ORM\ManyToOne(inversedBy'appPersonalAccounts')]
  90.     private ?Accounts $accounts null;
  91.     #[ORM\OneToMany(mappedBy'personalAccount'targetEntityServiceOrderHistory::class, cascade:['persist''remove'])]
  92.     private Collection $serviceOrderHistories;
  93.     #[Groups(['personalAcc:read''user:read'])]
  94.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'appPersonalAccounts')]
  95.     private ?self $parent null;
  96.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class, cascade:['remove'])]
  97.     private Collection $appPersonalAccounts;
  98.     #[Groups(['personalAcc:read''user:read'])]
  99.     #[ORM\Column(length100nullabletrue)]
  100.     private ?string $type null;
  101.     #[Groups(['personalAcc:read''user:read'])]
  102.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  103.     private ?\DateTimeInterface $dateEntered null;
  104.     #[Groups(['personalAcc:read''user:read'])]
  105.     #[ORM\Column(nullabletrue)]
  106.     private ?bool $isMain null;
  107.     #[Groups(['personalAcc:read''user:read'])]
  108.     #[ORM\Column(length255nullabletrue)]
  109.     private ?string $eic null;
  110.     #[Groups(['personalAcc:read''user:read'])]
  111.     #[ORM\Column(length255nullabletrue)]
  112.     private ?string $counter null;
  113.     #[Groups(['personalAcc:read''personalAcc:write''user:read'])]
  114.     #[ORM\Column(nullabletrue)]
  115.     private ?bool $isShow null;
  116.     #[ORM\ManyToOne(inversedBy'appPersonalAccounts')]
  117.     private ?Company $company null;
  118.     #[ORM\Column(nullabletrue)]
  119.     private ?array $lastHistoryCounter null;
  120.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  121.     private ?\DateTimeInterface $lastHistoryCounterDate null;
  122.     public function __construct()
  123.     {
  124.         $this->appCounterReadings = new ArrayCollection();
  125.         $this->serviceOrderHistories = new ArrayCollection();
  126.         $this->appPersonalAccounts = new ArrayCollection();
  127.     }
  128.     public function getId(): ?int
  129.     {
  130.         return $this->id;
  131.     }
  132.     public function getOwner(): ?User
  133.     {
  134.         return $this->owner;
  135.     }
  136.     public function setOwner(?User $owner): static
  137.     {
  138.         $this->owner $owner;
  139.         return $this;
  140.     }
  141.     public function getNumber(): ?string
  142.     {
  143.         return $this->number;
  144.     }
  145.     public function setNumber(string $number): static
  146.     {
  147.         $this->number $number;
  148.         return $this;
  149.     }
  150.     public function getName(): ?string
  151.     {
  152.         return $this->name;
  153.     }
  154.     public function setName(?string $name): static
  155.     {
  156.         $this->name $name;
  157.         return $this;
  158.     }
  159.     public function getNumberOfScale(): ?int
  160.     {
  161.         return $this->numberOfScale;
  162.     }
  163.     public function setNumberOfScale(?int $numberOfScale): static
  164.     {
  165.         $this->numberOfScale $numberOfScale;
  166.         return $this;
  167.     }
  168.     public function isActive(): ?bool
  169.     {
  170.         return $this->active;
  171.     }
  172.     public function setActive(?bool $active): static
  173.     {
  174.         $this->active $active;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return Collection<int, AppCounterReading>
  179.      */
  180.     public function getAppCounterReadings(): Collection
  181.     {
  182.         return $this->appCounterReadings;
  183.     }
  184.     public function addAppCounterReading(AppCounterReading $appCounterReading): static
  185.     {
  186.         if (!$this->appCounterReadings->contains($appCounterReading)) {
  187.             $this->appCounterReadings->add($appCounterReading);
  188.             $appCounterReading->setPersonal($this);
  189.         }
  190.         return $this;
  191.     }
  192.     public function removeAppCounterReading(AppCounterReading $appCounterReading): static
  193.     {
  194.         if ($this->appCounterReadings->removeElement($appCounterReading)) {
  195.             // set the owning side to null (unless already changed)
  196.             if ($appCounterReading->getPersonal() === $this) {
  197.                 $appCounterReading->setPersonal(null);
  198.             }
  199.         }
  200.         return $this;
  201.     }
  202.     public function getFullAddress(): ?string
  203.     {
  204.         return $this->fullAddress;
  205.     }
  206.     public function setFullAddress(?string $fullAddress): static
  207.     {
  208.         $this->fullAddress $fullAddress;
  209.         return $this;
  210.     }
  211.     public function getCity(): ?string
  212.     {
  213.         return $this->city;
  214.     }
  215.     public function setCity(?string $city): static
  216.     {
  217.         $this->city $city;
  218.         return $this;
  219.     }
  220.     public function getStreet(): ?string
  221.     {
  222.         return $this->street;
  223.     }
  224.     public function setStreet(?string $street): static
  225.     {
  226.         $this->street $street;
  227.         return $this;
  228.     }
  229.     public function getBuilding(): ?string
  230.     {
  231.         return $this->building;
  232.     }
  233.     public function setBuilding(?string $building): static
  234.     {
  235.         $this->building $building;
  236.         return $this;
  237.     }
  238.     public function getRoom(): ?string
  239.     {
  240.         return $this->room;
  241.     }
  242.     public function setRoom(?string $room): static
  243.     {
  244.         $this->room $room;
  245.         return $this;
  246.     }
  247.     public function getMainFullAddress(): ?string
  248.     {
  249.         return $this->mainFullAddress;
  250.     }
  251.     public function setMainFullAddress(string $mainFullAddress): static
  252.     {
  253.         $this->mainFullAddress $mainFullAddress;
  254.         return $this;
  255.     }
  256.     public function getAccounts(): ?Accounts
  257.     {
  258.         return $this->accounts;
  259.     }
  260.     public function setAccounts(?Accounts $accounts): static
  261.     {
  262.         $this->accounts $accounts;
  263.         return $this;
  264.     }
  265.     /**
  266.      * @return Collection<int, ServiceOrderHistory>
  267.      */
  268.     public function getServiceOrderHistories(): Collection
  269.     {
  270.         return $this->serviceOrderHistories;
  271.     }
  272.     public function addServiceOrderHistory(ServiceOrderHistory $serviceOrderHistory): static
  273.     {
  274.         if (!$this->serviceOrderHistories->contains($serviceOrderHistory)) {
  275.             $this->serviceOrderHistories->add($serviceOrderHistory);
  276.             $serviceOrderHistory->setPersonalAccount($this);
  277.         }
  278.         return $this;
  279.     }
  280.     public function removeServiceOrderHistory(ServiceOrderHistory $serviceOrderHistory): static
  281.     {
  282.         if ($this->serviceOrderHistories->removeElement($serviceOrderHistory)) {
  283.             // set the owning side to null (unless already changed)
  284.             if ($serviceOrderHistory->getPersonalAccount() === $this) {
  285.                 $serviceOrderHistory->setPersonalAccount(null);
  286.             }
  287.         }
  288.         return $this;
  289.     }
  290.     public function getParent(): ?self
  291.     {
  292.         return $this->parent;
  293.     }
  294.     public function setParent(?self $parent): static
  295.     {
  296.         $this->parent $parent;
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return Collection<int, self>
  301.      */
  302.     public function getAppPersonalAccounts(): Collection
  303.     {
  304.         return $this->appPersonalAccounts;
  305.     }
  306.     public function addAppPersonalAccount(self $appPersonalAccount): static
  307.     {
  308.         if (!$this->appPersonalAccounts->contains($appPersonalAccount)) {
  309.             $this->appPersonalAccounts->add($appPersonalAccount);
  310.             $appPersonalAccount->setParent($this);
  311.         }
  312.         return $this;
  313.     }
  314.     public function removeAppPersonalAccount(self $appPersonalAccount): static
  315.     {
  316.         if ($this->appPersonalAccounts->removeElement($appPersonalAccount)) {
  317.             // set the owning side to null (unless already changed)
  318.             if ($appPersonalAccount->getParent() === $this) {
  319.                 $appPersonalAccount->setParent(null);
  320.             }
  321.         }
  322.         return $this;
  323.     }
  324.     public function getType(): ?string
  325.     {
  326.         return $this->type;
  327.     }
  328.     public function setType(?string $type): static
  329.     {
  330.         $this->type $type;
  331.         return $this;
  332.     }
  333.     public function getDateEntered(): ?\DateTimeInterface
  334.     {
  335.         return $this->dateEntered;
  336.     }
  337.     public function setDateEntered(?\DateTimeInterface $dateEntered): static
  338.     {
  339.         $this->dateEntered $dateEntered;
  340.         return $this;
  341.     }
  342.     public function isIsMain(): ?bool
  343.     {
  344.         return $this->isMain;
  345.     }
  346.     public function setIsMain(?bool $isMain): static
  347.     {
  348.         $this->isMain $isMain;
  349.         return $this;
  350.     }
  351.     public function getEic(): ?string
  352.     {
  353.         return $this->eic;
  354.     }
  355.     public function setEic(?string $eic): static
  356.     {
  357.         $this->eic $eic;
  358.         return $this;
  359.     }
  360.     public function getCounter(): ?string
  361.     {
  362.         return $this->counter;
  363.     }
  364.     public function setCounter(?string $counter): static
  365.     {
  366.         $this->counter $counter;
  367.         return $this;
  368.     }
  369.     public function isIsShow(): ?bool
  370.     {
  371.         return $this->isShow;
  372.     }
  373.     public function setIsShow(?bool $isShow): static
  374.     {
  375.         $this->isShow $isShow;
  376.         return $this;
  377.     }
  378.     public function getCompany(): ?Company
  379.     {
  380.         return $this->company;
  381.     }
  382.     public function setCompany(?Company $company): static
  383.     {
  384.         $this->company $company;
  385.         return $this;
  386.     }
  387.     public function getLastHistoryCounter(): ?array
  388.     {
  389.         return $this->lastHistoryCounter;
  390.     }
  391.     public function setLastHistoryCounter(?array $lastHistoryCounter): static
  392.     {
  393.         $this->lastHistoryCounter $lastHistoryCounter;
  394.         return $this;
  395.     }
  396.     public function getLastHistoryCounterDate(): ?\DateTimeInterface
  397.     {
  398.         return $this->lastHistoryCounterDate;
  399.     }
  400.     public function setLastHistoryCounterDate(?\DateTimeInterface $lastHistoryCounterDate): static
  401.     {
  402.         $this->lastHistoryCounterDate $lastHistoryCounterDate;
  403.         return $this;
  404.     }
  405. }