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.     #[Groups(['personalAcc:read''personalAcc:write''user:read'])]
  123.     #[ORM\Column(length50nullabletrueoptions: ['default' => 'active'])]
  124.     private ?string $notificationStatus null;
  125.     public function __construct()
  126.     {
  127.         $this->appCounterReadings = new ArrayCollection();
  128.         $this->serviceOrderHistories = new ArrayCollection();
  129.         $this->appPersonalAccounts = new ArrayCollection();
  130.     }
  131.     public function getId(): ?int
  132.     {
  133.         return $this->id;
  134.     }
  135.     public function getOwner(): ?User
  136.     {
  137.         return $this->owner;
  138.     }
  139.     public function setOwner(?User $owner): static
  140.     {
  141.         $this->owner $owner;
  142.         return $this;
  143.     }
  144.     public function getNumber(): ?string
  145.     {
  146.         return $this->number;
  147.     }
  148.     public function setNumber(string $number): static
  149.     {
  150.         $this->number $number;
  151.         return $this;
  152.     }
  153.     public function getName(): ?string
  154.     {
  155.         return $this->name;
  156.     }
  157.     public function setName(?string $name): static
  158.     {
  159.         $this->name $name;
  160.         return $this;
  161.     }
  162.     public function getNumberOfScale(): ?int
  163.     {
  164.         return $this->numberOfScale;
  165.     }
  166.     public function setNumberOfScale(?int $numberOfScale): static
  167.     {
  168.         $this->numberOfScale $numberOfScale;
  169.         return $this;
  170.     }
  171.     public function isActive(): ?bool
  172.     {
  173.         return $this->active;
  174.     }
  175.     public function setActive(?bool $active): static
  176.     {
  177.         $this->active $active;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return Collection<int, AppCounterReading>
  182.      */
  183.     public function getAppCounterReadings(): Collection
  184.     {
  185.         return $this->appCounterReadings;
  186.     }
  187.     public function addAppCounterReading(AppCounterReading $appCounterReading): static
  188.     {
  189.         if (!$this->appCounterReadings->contains($appCounterReading)) {
  190.             $this->appCounterReadings->add($appCounterReading);
  191.             $appCounterReading->setPersonal($this);
  192.         }
  193.         return $this;
  194.     }
  195.     public function removeAppCounterReading(AppCounterReading $appCounterReading): static
  196.     {
  197.         if ($this->appCounterReadings->removeElement($appCounterReading)) {
  198.             // set the owning side to null (unless already changed)
  199.             if ($appCounterReading->getPersonal() === $this) {
  200.                 $appCounterReading->setPersonal(null);
  201.             }
  202.         }
  203.         return $this;
  204.     }
  205.     public function getFullAddress(): ?string
  206.     {
  207.         return $this->fullAddress;
  208.     }
  209.     public function setFullAddress(?string $fullAddress): static
  210.     {
  211.         $this->fullAddress $fullAddress;
  212.         return $this;
  213.     }
  214.     public function getCity(): ?string
  215.     {
  216.         return $this->city;
  217.     }
  218.     public function setCity(?string $city): static
  219.     {
  220.         $this->city $city;
  221.         return $this;
  222.     }
  223.     public function getStreet(): ?string
  224.     {
  225.         return $this->street;
  226.     }
  227.     public function setStreet(?string $street): static
  228.     {
  229.         $this->street $street;
  230.         return $this;
  231.     }
  232.     public function getBuilding(): ?string
  233.     {
  234.         return $this->building;
  235.     }
  236.     public function setBuilding(?string $building): static
  237.     {
  238.         $this->building $building;
  239.         return $this;
  240.     }
  241.     public function getRoom(): ?string
  242.     {
  243.         return $this->room;
  244.     }
  245.     public function setRoom(?string $room): static
  246.     {
  247.         $this->room $room;
  248.         return $this;
  249.     }
  250.     public function getMainFullAddress(): ?string
  251.     {
  252.         return $this->mainFullAddress;
  253.     }
  254.     public function setMainFullAddress(string $mainFullAddress): static
  255.     {
  256.         $this->mainFullAddress $mainFullAddress;
  257.         return $this;
  258.     }
  259.     public function getAccounts(): ?Accounts
  260.     {
  261.         return $this->accounts;
  262.     }
  263.     public function setAccounts(?Accounts $accounts): static
  264.     {
  265.         $this->accounts $accounts;
  266.         return $this;
  267.     }
  268.     /**
  269.      * @return Collection<int, ServiceOrderHistory>
  270.      */
  271.     public function getServiceOrderHistories(): Collection
  272.     {
  273.         return $this->serviceOrderHistories;
  274.     }
  275.     public function addServiceOrderHistory(ServiceOrderHistory $serviceOrderHistory): static
  276.     {
  277.         if (!$this->serviceOrderHistories->contains($serviceOrderHistory)) {
  278.             $this->serviceOrderHistories->add($serviceOrderHistory);
  279.             $serviceOrderHistory->setPersonalAccount($this);
  280.         }
  281.         return $this;
  282.     }
  283.     public function removeServiceOrderHistory(ServiceOrderHistory $serviceOrderHistory): static
  284.     {
  285.         if ($this->serviceOrderHistories->removeElement($serviceOrderHistory)) {
  286.             // set the owning side to null (unless already changed)
  287.             if ($serviceOrderHistory->getPersonalAccount() === $this) {
  288.                 $serviceOrderHistory->setPersonalAccount(null);
  289.             }
  290.         }
  291.         return $this;
  292.     }
  293.     public function getParent(): ?self
  294.     {
  295.         return $this->parent;
  296.     }
  297.     public function setParent(?self $parent): static
  298.     {
  299.         $this->parent $parent;
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return Collection<int, self>
  304.      */
  305.     public function getAppPersonalAccounts(): Collection
  306.     {
  307.         return $this->appPersonalAccounts;
  308.     }
  309.     public function addAppPersonalAccount(self $appPersonalAccount): static
  310.     {
  311.         if (!$this->appPersonalAccounts->contains($appPersonalAccount)) {
  312.             $this->appPersonalAccounts->add($appPersonalAccount);
  313.             $appPersonalAccount->setParent($this);
  314.         }
  315.         return $this;
  316.     }
  317.     public function removeAppPersonalAccount(self $appPersonalAccount): static
  318.     {
  319.         if ($this->appPersonalAccounts->removeElement($appPersonalAccount)) {
  320.             // set the owning side to null (unless already changed)
  321.             if ($appPersonalAccount->getParent() === $this) {
  322.                 $appPersonalAccount->setParent(null);
  323.             }
  324.         }
  325.         return $this;
  326.     }
  327.     public function getType(): ?string
  328.     {
  329.         return $this->type;
  330.     }
  331.     public function setType(?string $type): static
  332.     {
  333.         $this->type $type;
  334.         return $this;
  335.     }
  336.     public function getDateEntered(): ?\DateTimeInterface
  337.     {
  338.         return $this->dateEntered;
  339.     }
  340.     public function setDateEntered(?\DateTimeInterface $dateEntered): static
  341.     {
  342.         $this->dateEntered $dateEntered;
  343.         return $this;
  344.     }
  345.     public function isIsMain(): ?bool
  346.     {
  347.         return $this->isMain;
  348.     }
  349.     public function setIsMain(?bool $isMain): static
  350.     {
  351.         $this->isMain $isMain;
  352.         return $this;
  353.     }
  354.     public function getEic(): ?string
  355.     {
  356.         return $this->eic;
  357.     }
  358.     public function setEic(?string $eic): static
  359.     {
  360.         $this->eic $eic;
  361.         return $this;
  362.     }
  363.     public function getCounter(): ?string
  364.     {
  365.         return $this->counter;
  366.     }
  367.     public function setCounter(?string $counter): static
  368.     {
  369.         $this->counter $counter;
  370.         return $this;
  371.     }
  372.     public function isIsShow(): ?bool
  373.     {
  374.         return $this->isShow;
  375.     }
  376.     public function setIsShow(?bool $isShow): static
  377.     {
  378.         $this->isShow $isShow;
  379.         return $this;
  380.     }
  381.     public function getCompany(): ?Company
  382.     {
  383.         return $this->company;
  384.     }
  385.     public function setCompany(?Company $company): static
  386.     {
  387.         $this->company $company;
  388.         return $this;
  389.     }
  390.     public function getLastHistoryCounter(): ?array
  391.     {
  392.         return $this->lastHistoryCounter;
  393.     }
  394.     public function setLastHistoryCounter(?array $lastHistoryCounter): static
  395.     {
  396.         $this->lastHistoryCounter $lastHistoryCounter;
  397.         return $this;
  398.     }
  399.     public function getLastHistoryCounterDate(): ?\DateTimeInterface
  400.     {
  401.         return $this->lastHistoryCounterDate;
  402.     }
  403.     public function setLastHistoryCounterDate(?\DateTimeInterface $lastHistoryCounterDate): static
  404.     {
  405.         $this->lastHistoryCounterDate $lastHistoryCounterDate;
  406.         return $this;
  407.     }
  408.     public function getNotificationStatus(): ?string
  409.     {
  410.         return $this->notificationStatus;
  411.     }
  412.     public function setNotificationStatus(?string $notificationStatus): static
  413.     {
  414.         $this->notificationStatus $notificationStatus;
  415.         return $this;
  416.     }
  417. }