src/Entity/MarketCategory.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use App\Entity\Traits\CreatedAtTrait;
  7. use App\Entity\Traits\UpdatedAtTrait;
  8. use App\Repository\MarketCategoryRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. #[ORM\HasLifecycleCallbacks]
  14. #[ORM\Entity(repositoryClassMarketCategoryRepository::class)]
  15. #[ApiResource(
  16.     operations: [
  17.         new Get(),
  18.         new GetCollection(),
  19.     ],
  20.     normalizationContext: ['groups' => 'MarketCategory:read'],
  21.     paginationEnabledfalse
  22. )]
  23. class MarketCategory
  24. {
  25.     use CreatedAtTrait;
  26.     use UpdatedAtTrait;
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column]
  30.     #[Groups(['read''MarketCategory:read'])]
  31.     private ?int $id null;
  32.     #[ORM\Column(length255)]
  33.     #[Groups(['read''MarketCategory:read'])]
  34.     private ?string $name null;
  35.     #[ORM\ManyToMany(targetEntityMarketApp::class, inversedBy'marketCategories')]
  36.     #[Groups(['MarketCategory:read'])]
  37.     private Collection $apps;
  38.     public function __construct()
  39.     {
  40.         $this->apps = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function __toString(): string
  47.     {
  48.         return $this->getName();
  49.     }
  50.     public function getName(): ?string
  51.     {
  52.         return $this->name;
  53.     }
  54.     public function setName(string $name): self
  55.     {
  56.         $this->name $name;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return Collection<int, MarketApp>
  61.      */
  62.     public function getApps(): Collection
  63.     {
  64.         return $this->apps;
  65.     }
  66.     public function addApp(MarketApp $app): self
  67.     {
  68.         if (!$this->apps->contains($app)) {
  69.             $this->apps->add($app);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeApp(MarketApp $app): self
  74.     {
  75.         $this->apps->removeElement($app);
  76.         return $this;
  77.     }
  78. }