<?php
namespace App\Entity;
use App\Repository\ArticleRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Doctrine\Common\Collections\ArrayCollection;
#[ORM\Entity(repositoryClass: ArticleRepository::class)]
#[Vich\Uploadable]
class Article
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $titre = null;
#[ORM\Column(length:11)]
private ?int $prix = null;
#[ORM\Column(length:11)]
private ?int $quantite = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $description = null;
#[ORM\OneToMany(mappedBy: 'article', targetEntity: CommandArticle::class, cascade: ['persist', 'remove'])]
private $commandes;
#[ORM\Column(type:'string', length:255)]
private $image;
#[Vich\UploadableField(mapping:'post_thumbnails', fileNameProperty:'image')]
private $imageFile;
#[ORM\Column(type:'string', length:255)]
private $extrait;
#[Vich\UploadableField(mapping:'post_thumbnails', fileNameProperty:'extrait')]
private $extraitFile;
public function __construct()
{
$this->commandes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getPrix(): ?int
{
return $this->prix;
}
public function setPrix(int $prix): self
{
$this->prix = $prix;
return $this;
}
public function setQuantite(int $quantite): self
{
$this->quantite = $quantite;
return $this;
}
public function getQuantite(): ?int
{
return $this->quantite;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
// if ($image) {
// if 'updatedAt' is not defined in your entity, use another property
// $this->updatedAt = new \DateTime('now');
// }
}
public function getImageFile()
{
return $this->imageFile;
}
public function setImage($image)
{
$this->image = $image;
}
public function getImage()
{
return $this->image;
}
public function setExtraitFile(File $extrait = null)
{
$this->imageFile = $extrait;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
// if ($image) {
// if 'updatedAt' is not defined in your entity, use another property
// $this->updatedAt = new \DateTime('now');
// }
}
public function getExtraitFile()
{
return $this->extraitFile;
}
public function setExtrait($extrait)
{
$this->extrait = $extrait;
}
public function getExtrait()
{
return $this->extrait;
}
public function __toString()
{
return $this->titre;
}
/**
* @return Collection<int, CommandArticle>
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(CommandArticle $commande): self
{
if (!$this->commandes->contains($commande)) {
$this->commandes->add($commande);
$commande->setArticle($this);
}
return $this;
}
public function removeCommande(CommandArticle $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getArticle() === $this) {
$commande->setArticle(null);
}
}
return $this;
}
}