src/Entity/Location.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\LocationRepository;
  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 Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassLocationRepository::class)]
  11. #[ApiResource(
  12.     normalizationContext: ['groups' => ['location:read']],
  13.     denormalizationContext: ['groups' => ['location:update']],
  14. )]
  15. class Location
  16. {
  17.     #[Groups(['location:read''location:update''user:read''read''account:read''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invoice:read''load_invocie:read''product_storage_balance:read''product:read''storage:read'])]
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[Groups(['location:read''location:update''user:read''read''account:read''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invoice:read''load_invocie:read''product_storage_balance:read''product:read''storage:read'])]
  23.     #[ORM\Column(length255)]
  24.     private ?string $name null;
  25.     #[Groups(['location:read''location:update''user:read''read''account:read''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invoice:read''load_invocie:read''product_storage_balance:read''product:read''storage:read'])]
  26.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  27.     private ?string $description null;
  28.     #[Groups(['location:read''location:update''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invocie:read''product_storage_balance:read'])]
  29.     #[ORM\OneToMany(mappedBy'location'targetEntityUser::class)]
  30.     private Collection $users;
  31.     #[Groups(['location:read''location:update''user:read''read''account:read''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invocie:read''product_storage_balance:read'])]
  32.     #[ORM\ManyToMany(targetEntityStorage::class, mappedBy'location')]
  33.     private Collection $storages;
  34.     public function __construct()
  35.     {
  36.         $this->users = new ArrayCollection();
  37.         $this->storages = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): self
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     public function getDescription(): ?string
  53.     {
  54.         return $this->description;
  55.     }
  56.     public function setDescription(?string $description): self
  57.     {
  58.         $this->description $description;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, User>
  63.      */
  64.     public function getUsers(): Collection
  65.     {
  66.         return $this->users;
  67.     }
  68.     public function addUser(User $user): self
  69.     {
  70.         if (!$this->users->contains($user)) {
  71.             $this->users->add($user);
  72.             $user->setLocation($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeUser(User $user): self
  77.     {
  78.         if ($this->users->removeElement($user)) {
  79.             // set the owning side to null (unless already changed)
  80.             if ($user->getLocation() === $this) {
  81.                 $user->setLocation(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, Storage>
  88.      */
  89.     public function getStorages(): Collection
  90.     {
  91.         return $this->storages;
  92.     }
  93.     public function addStorage(Storage $storage): self
  94.     {
  95.         if (!$this->storages->contains($storage)) {
  96.             $this->storages->add($storage);
  97.             $storage->addLocation($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeStorage(Storage $storage): self
  102.     {
  103.         if ($this->storages->removeElement($storage)) {
  104.             $storage->removeLocation($this);
  105.         }
  106.         return $this;
  107.     }
  108. }