src/Entity/Recommendation.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. /**
  6.  * @ORM\Entity(repositoryClass="App\Repository\RecommendationRepository")
  7.  */
  8. class Recommendation
  9. {
  10.     /**
  11.      * @ORM\Id()
  12.      * @ORM\GeneratedValue()
  13.      * @ORM\Column(type="integer")
  14.      */
  15.     private $id;
  16.     /**
  17.      * @ORM\Column(type="string", length=150)
  18.      * @Assert\NotBlank()
  19.      * @Assert\Length(max=150)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @var string
  24.      *
  25.      * @ORM\Column(type="string", length=550)
  26.      * @Assert\NotBlank()
  27.      * @Assert\Length(max=550)
  28.      */
  29.     private $description;
  30.     /**
  31.      * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="recommendations")
  32.      * @ORM\JoinColumn(nullable=true)
  33.      */
  34.     private $category;
  35.     public function __toString(): string
  36.     {
  37.         return $this->getName();
  38.     }
  39.     public function getName(): ?string
  40.     {
  41.         return $this->name;
  42.     }
  43.     public function setName(string $name): self
  44.     {
  45.         $this->name $name;
  46.         return $this;
  47.     }
  48.     public function getDescription(): string
  49.     {
  50.         return $this->description;
  51.     }
  52.     public function setDescription(string $description): self
  53.     {
  54.         $this->description $description;
  55.         return $this;
  56.     }
  57.     public function setCategory(?Category $category): self
  58.     {
  59.         $this->category $category;
  60.         return $this;
  61.     }
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function addCategory(string $category): void
  67.     {
  68.         $this->category[] = $category;
  69.     }
  70.     public function removeCategory(string $category): void
  71.     {
  72.         if (false !== $key array_search($category$this->category ?? [], true)) {
  73.             unset($this->category[$key]);
  74.         }
  75.     }
  76.     /**
  77.      * @return string[]|null
  78.      */
  79.     public function getCategory()
  80.     {
  81.         return $this->category;
  82.     }
  83. }