<?php
namespace App\Entity;
use App\Repository\ArticleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: ArticleRepository::class)]
/**
* @ORM\Entity(repositoryClass=ArticleRepository::class)
* @Vich\Uploadable
*/
class Article
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $description;
#[ORM\Column(type: 'integer')]
private $quantity;
#[ORM\Column(type: 'integer')]
private $warnining;
#[ORM\ManyToOne(targetEntity: Category::class, inversedBy: 'articles')]
private $category;
#[ORM\ManyToOne(targetEntity: Shop::class, inversedBy: 'articles')]
private $shop;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $image;
/**
* @Vich\UploadableField(mapping="products_image", fileNameProperty="image")
* @var File
*/
private $imageFile;
#[ORM\Column(type: 'datetime')]
private $updatedAt;
#[ORM\OneToMany(mappedBy: 'article', targetEntity: Evolution::class)]
private $evolutions;
public function __construct()
{
$this->evolutions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getWarnining(): ?int
{
return $this->warnining;
}
public function setWarnining(int $warnining): self
{
$this->warnining = $warnining;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): self
{
$this->shop = $shop;
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;
}
/**
* @return Collection<int, Evolution>
*/
public function getEvolutions(): Collection
{
return $this->evolutions;
}
public function addEvolution(Evolution $evolution): self
{
if (!$this->evolutions->contains($evolution)) {
$this->evolutions[] = $evolution;
$evolution->setArticle($this);
}
return $this;
}
public function removeEvolution(Evolution $evolution): self
{
if ($this->evolutions->removeElement($evolution)) {
// set the owning side to null (unless already changed)
if ($evolution->getArticle() === $this) {
$evolution->setArticle(null);
}
}
return $this;
}
}