src/Entity/Languages.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\LanguagesRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassLanguagesRepository::class)]
  10. #[ApiResource(
  11.     normalizationContext: ['groups' => ['language:read']],
  12.     denormalizationContext: ['groups' => ['language:write']],
  13.     order: ['id' => 'DESC'],
  14. )]
  15. class Languages
  16. {
  17.     #[Groups(['language:read''language:write''product:read''product:write''cat:read''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invoice:read''user_like:read''order_product:read''attributes_items:read''attributes:read',  'cat:read','product_storage_balance:read'])]
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[Groups(['language:read''language:write''product:read''product:write''cat:read''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invoice:read''user_like:read''order_product:read''attributes_items:read''attributes:read',  'cat:read','product_storage_balance:read'])]
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $name null;
  25.     
  26.     #[Groups(['language:read''language:write''product:read''product:write''cat:read''order:read''order_product:read''pre_order_product:read''pre_order:read''load_invoice:read''user_like:read''order_product:read''attributes_items:read''attributes:read',  'cat:read','product_storage_balance:read'])]    
  27.     #[ORM\Column(length10nullabletrue)]
  28.     private ?string $key null;
  29.     
  30.     #[Groups(['language:read''language:write''product:write''cat:read''order:read''order_product:read''pre_order_product:read''pre_order:read',  'user_like:read''order_product:read''attributes_items:read''attributes:read',  'cat:read','product_storage_balance:read'])]
  31.     #[ORM\OneToMany(mappedBy'language'targetEntityProducts::class)]
  32.     private Collection $products;
  33.     public function __construct()
  34.     {
  35.         $this->products = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getName(): ?string
  42.     {
  43.         return $this->name;
  44.     }
  45.     public function setName(?string $name): self
  46.     {
  47.         $this->name $name;
  48.         return $this;
  49.     }
  50.     public function getKey(): ?string
  51.     {
  52.         return $this->key;
  53.     }
  54.     public function setKey(?string $key): self
  55.     {
  56.         $this->key $key;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return Collection<int, Products>
  61.      */
  62.     public function getProducts(): Collection
  63.     {
  64.         return $this->products;
  65.     }
  66.     public function addProduct(Products $product): self
  67.     {
  68.         if (!$this->products->contains($product)) {
  69.             $this->products->add($product);
  70.             $product->setLanguage($this);
  71.         }
  72.         return $this;
  73.     }
  74.     public function removeProduct(Products $product): self
  75.     {
  76.         if ($this->products->removeElement($product)) {
  77.             // set the owning side to null (unless already changed)
  78.             if ($product->getLanguage() === $this) {
  79.                 $product->setLanguage(null);
  80.             }
  81.         }
  82.         return $this;
  83.     }
  84. }