src/Entity/Brand.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BrandRepository;
  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(repositoryClassBrandRepository::class)]
  9. #[UniqueEntity(fields: ['brand_name'], message'Il existe déjà une marque avec ce nom.')]
  10. class Brand
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255uniquetrue)]
  17.     private ?string $brand_name null;
  18.     #[ORM\OneToMany(mappedBy'model_brand'targetEntityModel::class)]
  19.     private Collection $models;
  20.     #[ORM\ManyToOne(inversedBy'brands')]
  21.     #[ORM\JoinColumn(nullablefalse)]
  22.     private ?BrandLogo $brand_logo null;
  23.     public function __construct()
  24.     {
  25.         $this->models = new ArrayCollection();
  26.     }
  27.     public function getId(): ?int
  28.     {
  29.         return $this->id;
  30.     }
  31.     public function getBrandName(): ?string
  32.     {
  33.         return $this->brand_name;
  34.     }
  35.     public function setBrandName(string $brand_name): self
  36.     {
  37.         $this->brand_name $brand_name;
  38.         return $this;
  39.     }
  40.     /**
  41.      * @return Collection<int, Model>
  42.      */
  43.     public function getModels(): Collection
  44.     {
  45.         return $this->models;
  46.     }
  47.     public function addModel(Model $model): self
  48.     {
  49.         if (!$this->models->contains($model)) {
  50.             $this->models->add($model);
  51.             $model->setModelBrand($this);
  52.         }
  53.         return $this;
  54.     }
  55.     public function removeModel(Model $model): self
  56.     {
  57.         if ($this->models->removeElement($model)) {
  58.             // set the owning side to null (unless already changed)
  59.             if ($model->getModelBrand() === $this) {
  60.                 $model->setModelBrand(null);
  61.             }
  62.         }
  63.         return $this;
  64.     }
  65.     public function getBrandLogo(): ?BrandLogo
  66.     {
  67.         return $this->brand_logo;
  68.     }
  69.     public function setBrandLogo(?BrandLogo $brand_logo): self
  70.     {
  71.         $this->brand_logo $brand_logo;
  72.         return $this;
  73.     }
  74.     public function getBrandLogoImage(): ?string
  75.     {
  76.         return $this->brand_logo->getBrandLogoImage();
  77.     }
  78.     public function __toString(): string
  79.     {
  80.         return $this->brand_name;
  81.     }
  82. }