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