<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\LocationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: LocationRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['location:read']],
denormalizationContext: ['groups' => ['location:update']],
)]
class Location
{
#[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'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[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'])]
#[ORM\Column(length: 255)]
private ?string $name = null;
#[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'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['location:read', 'location:update', 'order:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read', 'load_invoice:read', 'load_invocie:read', 'product_storage_balance:read', 'product:read'])]
#[ORM\OneToMany(mappedBy: 'location', targetEntity: User::class)]
private Collection $users;
#[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'])]
#[ORM\ManyToMany(targetEntity: Storage::class, mappedBy: 'location')]
private Collection $storages;
public function __construct()
{
$this->users = new ArrayCollection();
$this->storages = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setLocation($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getLocation() === $this) {
$user->setLocation(null);
}
}
return $this;
}
/**
* @return Collection<int, Storage>
*/
public function getStorages(): Collection
{
return $this->storages;
}
public function addStorage(Storage $storage): self
{
if (!$this->storages->contains($storage)) {
$this->storages->add($storage);
$storage->addLocation($this);
}
return $this;
}
public function removeStorage(Storage $storage): self
{
if ($this->storages->removeElement($storage)) {
$storage->removeLocation($this);
}
return $this;
}
}