<?php
namespace App\Entity;
use App\Entity\Trait\CreatedAtTrait;
use App\Entity\Trait\SlugTrait;
use App\Repository\ProductsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ProductsRepository::class)]
class Products
{
use CreatedAtTrait;
use SlugTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: 'Le nom du produit ne peut pas étre vide')]
#[Assert\Length(
min: 3,
max: 50,
minMessage: 'Le titre doit faire au moins {{ limit }} caractères',
maxMessage: 'Le titre doit faire au plus {{ limit }} caractères'
)]
private ?string $name; // private ?string $name = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $description = null;
#[ORM\Column]
#[Assert\Positive(message: 'Le prix ne peut pas ètre négatif ou nulle')]
private int $price; // private ?int $price = null;
#[ORM\Column]
#[Assert\PositiveOrZero(message: 'Le stock ne peut pas ètre négatif')]
private ?int $stock = null; // private ?int $stock = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: 'Le SLUG est le NOM du produit en un seul mot séparé de tirets')]
#[Assert\Length(
min: 3,
max: 50,
minMessage: 'Le slug doit faire au moins {{ limit }} caractères',
maxMessage: 'Le slug doit faire au plus {{ limit }} caractères'
)]
private ?string $slug; // private ?string $name = null;
#[ORM\ManyToOne(inversedBy: 'products')]
#[ORM\JoinColumn(nullable: false)]
private ?Categories $categories = null;
/******
#[ORM\OneToMany(mappedBy: 'products', targetEntity: Images::class, orphanRemoval: true, cascade: ['persist'])]
private Collection $images;
*****/
#[ORM\OneToMany(mappedBy: 'products', targetEntity: OrdersDetails::class)]
private Collection $ordersDetails;
#[ORM\Column(length: 255)]
private ?string $imageFileName = null;
#[ORM\Column(type: Types::ARRAY, nullable: true)]
private ?array $imageFileOthers = [];
#[ORM\ManyToOne]
private ?Users $users = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: 'La ville ou Localité est obligatoire')]
private ?string $city = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: 'Le pays est obligatoire')]
private ?string $country = null;
#[ORM\Column(nullable: true)]
private ?bool $bannerAutorisation = null;
#[ORM\Column(nullable: true)]
private ?bool $homeAutorisation = null;
#[ORM\Column(nullable: true)]
private ?bool $publicityAutorisation = null;
// #[ORM\ManyToOne]
// private ?Users $users = null; ///****************************
// #[ORM\ManyToOne]
// private ?Users $usersId = null;
public function __construct()
{
// $this->images = new ArrayCollection(); // supprimé
$this->ordersDetails = new ArrayCollection();
$this->created_at = new \DateTimeImmutable();
/// $this->createdAt = new \DateTimeImmutable(); /////////////////
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): static
{
$this->description = $description;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(int $price): static
{
$this->price = $price;
return $this;
}
public function getStock(): ?int
{
return $this->stock;
}
public function setStock(int $stock): static
{
$this->stock = $stock;
return $this;
}
public function getCategories(): ?Categories
{
return $this->categories;
}
public function setCategories(?Categories $categories): static
{
$this->categories = $categories;
return $this;
}
/*****
/**
* @return Collection<int, Images>
*/ /****
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Images $image): static
{
if (!$this->images->contains($image)) {
$this->images->add($image);
$image->setProducts($this);
}
return $this;
}
public function removeImage(Images $image): static
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getProducts() === $this) {
$image->setProducts(null);
}
}
return $this;
}
/**
* @return Collection<int, OrdersDetails>
*/
public function getOrdersDetails(): Collection
{
return $this->ordersDetails;
}
public function addOrdersDetail(OrdersDetails $ordersDetail): static
{
if (!$this->ordersDetails->contains($ordersDetail)) {
$this->ordersDetails->add($ordersDetail);
$ordersDetail->setProducts($this);
}
return $this;
}
public function removeOrdersDetail(OrdersDetails $ordersDetail): static
{
if ($this->ordersDetails->removeElement($ordersDetail)) {
// set the owning side to null (unless already changed)
if ($ordersDetail->getProducts() === $this) {
$ordersDetail->setProducts(null);
}
}
return $this;
}
public function getImageFileName(): ?string
{
return $this->imageFileName;
}
public function setImageFileName(string $imageFileName): static
{
$this->imageFileName = $imageFileName;
return $this;
}
public function getImageFileOthers(): ?array
{
return $this->imageFileOthers;
}
public function setImageFileOthers(array $imageFileOthers): static
{
$this->imageFileOthers = $imageFileOthers;
return $this;
}
public function getUsers(): ?Users
{
return $this->users;
}
public function setUsers(?Users $users): static
{
$this->users = $users;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): static
{
$this->city = $city;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): static
{
$this->country = $country;
return $this;
}
public function isBannerAutorisation(): ?bool
{
return $this->bannerAutorisation;
}
public function setBannerAutorisation(?bool $bannerAutorisation): static
{
$this->bannerAutorisation = $bannerAutorisation;
return $this;
}
public function isHomeAutorisation(): ?bool
{
return $this->homeAutorisation;
}
public function setHomeAutorisation(?bool $homeAutorisation): static
{
$this->homeAutorisation = $homeAutorisation;
return $this;
}
public function isPublicityAutorisation(): ?bool
{
return $this->publicityAutorisation;
}
public function setPublicityAutorisation(?bool $publicityAutorisation): static
{
$this->publicityAutorisation = $publicityAutorisation;
return $this;
}
}