src/Entity/Products.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\CreatedAtTrait;
  4. use App\Entity\Trait\SlugTrait;
  5. use App\Repository\ProductsRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassProductsRepository::class)]
  12. class Products
  13. {
  14.     use CreatedAtTrait;
  15.     use SlugTrait;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(length255)]
  21.     #[Assert\NotBlank(message'Le nom du produit ne peut pas étre vide')]
  22.     #[Assert\Length(
  23.         min3,
  24.         max50,
  25.         minMessage'Le titre doit faire au moins {{ limit }} caractères',
  26.         maxMessage'Le titre doit faire au plus {{ limit }} caractères'
  27.     )]
  28.     private ?string $name// private ?string $name = null;
  29.     #[ORM\Column(typeTypes::TEXT)]
  30.     private ?string $description null;
  31.     #[ORM\Column]
  32.     #[Assert\Positive(message'Le prix ne peut pas ètre négatif ou nulle')]
  33.     private int $price// private ?int $price = null;
  34.     #[ORM\Column]
  35.     #[Assert\PositiveOrZero(message'Le stock ne peut pas ètre négatif')]
  36.     private ?int $stock null// private ?int $stock = null;
  37.     #[ORM\Column(length255)]
  38.     #[Assert\NotBlank(message'Le SLUG est le NOM du produit en un seul mot séparé de tirets')]
  39.     #[Assert\Length(
  40.         min3,
  41.         max50,
  42.         minMessage'Le slug doit faire au moins {{ limit }} caractères',
  43.         maxMessage'Le slug doit faire au plus {{ limit }} caractères'
  44.     )]
  45.     private ?string $slug// private ?string $name = null;
  46.     #[ORM\ManyToOne(inversedBy'products')]
  47.     #[ORM\JoinColumn(nullablefalse)]
  48.     private ?Categories $categories null;
  49.            /****** 
  50.     #[ORM\OneToMany(mappedBy: 'products', targetEntity: Images::class, orphanRemoval: true, cascade: ['persist'])]
  51.     private Collection $images;
  52.             *****/
  53.     #[ORM\OneToMany(mappedBy'products'targetEntityOrdersDetails::class)]
  54.     private Collection $ordersDetails;
  55.     #[ORM\Column(length255)]
  56.     private ?string $imageFileName null;
  57.     #[ORM\Column(typeTypes::ARRAY, nullabletrue)]
  58.     private ?array $imageFileOthers = [];
  59.     #[ORM\ManyToOne]
  60.     private ?Users $users null;
  61.     #[ORM\Column(length255)]
  62.     #[Assert\NotBlank(message'La ville ou Localité est obligatoire')]
  63.     private ?string $city null;
  64.     #[ORM\Column(length255)]
  65.     #[Assert\NotBlank(message'Le pays est obligatoire')]
  66.     private ?string $country null;
  67.     #[ORM\Column(nullabletrue)]
  68.     private ?bool $bannerAutorisation null;
  69.     #[ORM\Column(nullabletrue)]
  70.     private ?bool $homeAutorisation null;
  71.     #[ORM\Column(nullabletrue)]
  72.     private ?bool $publicityAutorisation null;  
  73.     // #[ORM\ManyToOne]
  74.     // private ?Users $users = null; ///**************************** 
  75.     // #[ORM\ManyToOne]
  76.     // private ?Users $usersId = null;
  77.     public function __construct()
  78.     {
  79.         // $this->images = new ArrayCollection(); // supprimé
  80.         $this->ordersDetails = new ArrayCollection();
  81.         $this->created_at = new \DateTimeImmutable();
  82.         /// $this->createdAt = new \DateTimeImmutable(); /////////////////
  83.     }
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getName(): ?string
  89.     {
  90.         return $this->name;
  91.     }
  92.     public function setName(string $name): static
  93.     {
  94.         $this->name $name;
  95.         return $this;
  96.     }
  97.     public function getDescription(): ?string
  98.     {
  99.         return $this->description;
  100.     }
  101.     public function setDescription(string $description): static
  102.     {
  103.         $this->description $description;
  104.         return $this;
  105.     }
  106.     public function getPrice(): ?int
  107.     {
  108.         return $this->price;
  109.     }
  110.     public function setPrice(int $price): static
  111.     {
  112.         $this->price $price;
  113.         return $this;
  114.     }
  115.     public function getStock(): ?int
  116.     {
  117.         return $this->stock;
  118.     }
  119.     public function setStock(int $stock): static
  120.     {
  121.         $this->stock $stock;
  122.         return $this;
  123.     }
  124.     public function getCategories(): ?Categories
  125.     {
  126.         return $this->categories;
  127.     }
  128.     public function setCategories(?Categories $categories): static
  129.     {
  130.         $this->categories $categories;
  131.         return $this;
  132.     }
  133.                 /***** 
  134.     /**
  135.      * @return Collection<int, Images>
  136.      */                                     /****
  137.     public function getImages(): Collection
  138.     {
  139.         return $this->images;
  140.     }
  141.     public function addImage(Images $image): static
  142.     {
  143.         if (!$this->images->contains($image)) {
  144.             $this->images->add($image);
  145.             $image->setProducts($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeImage(Images $image): static
  150.     {
  151.         if ($this->images->removeElement($image)) {
  152.             // set the owning side to null (unless already changed)
  153.             if ($image->getProducts() === $this) {
  154.                 $image->setProducts(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159.                     
  160.     /**
  161.      * @return Collection<int, OrdersDetails>
  162.      */
  163.                     
  164.     public function getOrdersDetails(): Collection
  165.     {
  166.         return $this->ordersDetails;
  167.     }
  168.     public function addOrdersDetail(OrdersDetails $ordersDetail): static
  169.     {
  170.         if (!$this->ordersDetails->contains($ordersDetail)) {
  171.             $this->ordersDetails->add($ordersDetail);
  172.             $ordersDetail->setProducts($this);
  173.         }
  174.         return $this;
  175.     }
  176.     public function removeOrdersDetail(OrdersDetails $ordersDetail): static
  177.     {
  178.         if ($this->ordersDetails->removeElement($ordersDetail)) {
  179.             // set the owning side to null (unless already changed)
  180.             if ($ordersDetail->getProducts() === $this) {
  181.                 $ordersDetail->setProducts(null);
  182.             }
  183.         }
  184.         return $this;
  185.     }
  186.     public function getImageFileName(): ?string
  187.     {
  188.         return $this->imageFileName;
  189.     }
  190.     public function setImageFileName(string $imageFileName): static
  191.     {
  192.         $this->imageFileName $imageFileName;
  193.         return $this;
  194.     }
  195.                        
  196.     public function getImageFileOthers(): ?array
  197.     {
  198.         return $this->imageFileOthers;
  199.     }
  200.     public function setImageFileOthers(array $imageFileOthers): static
  201.     {
  202.         $this->imageFileOthers $imageFileOthers;
  203.         return $this;
  204.     }
  205.     public function getUsers(): ?Users
  206.     {
  207.         return $this->users;
  208.     }
  209.     public function setUsers(?Users $users): static
  210.     {
  211.         $this->users $users;
  212.         return $this;
  213.     }
  214.     public function getCity(): ?string
  215.     {
  216.         return $this->city;
  217.     }
  218.     public function setCity(string $city): static
  219.     {
  220.         $this->city $city;
  221.         return $this;
  222.     }
  223.     public function getCountry(): ?string
  224.     {
  225.         return $this->country;
  226.     }
  227.     public function setCountry(string $country): static
  228.     {
  229.         $this->country $country;
  230.         return $this;
  231.     }
  232.     public function isBannerAutorisation(): ?bool
  233.     {
  234.         return $this->bannerAutorisation;
  235.     }
  236.     public function setBannerAutorisation(?bool $bannerAutorisation): static
  237.     {
  238.         $this->bannerAutorisation $bannerAutorisation;
  239.         return $this;
  240.     }
  241.     public function isHomeAutorisation(): ?bool
  242.     {
  243.         return $this->homeAutorisation;
  244.     }
  245.     public function setHomeAutorisation(?bool $homeAutorisation): static
  246.     {
  247.         $this->homeAutorisation $homeAutorisation;
  248.         return $this;
  249.     }
  250.     public function isPublicityAutorisation(): ?bool
  251.     {
  252.         return $this->publicityAutorisation;
  253.     }
  254.     public function setPublicityAutorisation(?bool $publicityAutorisation): static
  255.     {
  256.         $this->publicityAutorisation $publicityAutorisation;
  257.         return $this;
  258.     }
  259. }