src/Entity/Condition.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ConditionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. #[ORM\Entity(repositoryClassConditionRepository::class)]
  9. #[ORM\Table(name'`condition`')]
  10. #[UniqueEntity(fields: ['condition_title'], message'Il existe déjà un état avec ce nom.')]
  11. class Condition
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length255uniquetrue)]
  18.     private ?string $condition_title null;
  19.     #[ORM\OneToMany(mappedBy'product_condition'targetEntityProduct::class)]
  20.     private Collection $products;
  21.     public function __construct()
  22.     {
  23.         $this->products = new ArrayCollection();
  24.     }
  25.     public function getId(): ?int
  26.     {
  27.         return $this->id;
  28.     }
  29.     public function getConditionTitle(): ?string
  30.     {
  31.         return $this->condition_title;
  32.     }
  33.     public function setConditionTitle(string $condition_title): self
  34.     {
  35.         $this->condition_title $condition_title;
  36.         return $this;
  37.     }
  38.     /**
  39.      * @return Collection<int, Product>
  40.      */
  41.     public function getProducts(): Collection
  42.     {
  43.         return $this->products;
  44.     }
  45.     public function addProduct(Product $product): self
  46.     {
  47.         if (!$this->products->contains($product)) {
  48.             $this->products->add($product);
  49.             $product->setProductCondition($this);
  50.         }
  51.         return $this;
  52.     }
  53.     public function removeProduct(Product $product): self
  54.     {
  55.         if ($this->products->removeElement($product)) {
  56.             // set the owning side to null (unless already changed)
  57.             if ($product->getProductCondition() === $this) {
  58.                 $product->setProductCondition(null);
  59.             }
  60.         }
  61.         return $this;
  62.     }
  63.     public function __toString(): string
  64.     {
  65.         return $this->condition_title;
  66.     }
  67. }