<?php
namespace App\Entity;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
#[ORM\Table(name: "products")]
class Product
{
//Виды сортировок грида товаров
const SORT_PRODUCTS_DEFAULT = 0;
const SORT_PRODUCTS_PRICE_DOWN = 1;
const SORT_PRODUCTS_PRICE_UP = 2;
const SORT_PRODUCTS_VIEWS = 3;
const SORT_PRODUCTS_BOUGHT = 4;
// Статусы товара
const STATUS_PRODUCTS_ACTUAL = 1;
const STATUS_PRODUCTS_ON_VERIFICATION = 2;
const STATUS_PRODUCTS_NOT_ACTUAL = 3;
const STATUS_PRODUCTS_DECLINED = 4;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(length: 255)]
private ?string $description = null;
#[ORM\Column(name: "stock_depth")]
private ?int $stockDepth = null;
#[ORM\Column(name: "likes")]
private ?int $likes = null;
#[ORM\Column(name: "views")]
private ?int $views = null;
#[ORM\Column(name: "bought")]
private ?int $bought = null;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: ImagePath::class)]
private Collection $images;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?GroupProducts $groupsProduct = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?MaterialProducts $materialProduct = null;
#[ORM\Column]
private float $price = 0;
#[ORM\Column(type: Types::TEXT)]
private string $tags = '';
#[ORM\Column]
private float $priceForSeller = 0;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductsSizes::class, orphanRemoval: true)]
private Collection $productsSizes;
#[ORM\ManyToOne(inversedBy: 'products')]
#[ORM\JoinColumn(nullable: false)]
private ?User $seller = null;
#[ORM\Column]
private int $status = self::STATUS_PRODUCTS_ACTUAL;
public function __construct()
{
$this->images = new ArrayCollection();
$this->productsSizes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getStockDepth(): ?int
{
return $this->stockDepth;
}
public function setStockDepth(int $stockDepth): self
{
$this->stockDepth = $stockDepth;
return $this;
}
/**
* @return int|null
*/
public function getLikes(): ?int
{
return $this->likes;
}
/**
* @param int|null $likes
*/
public function setLikes(?int $likes): void
{
$this->likes = $likes;
}
/**
* @return int|null
*/
public function getViews(): ?int
{
return $this->views;
}
/**
* @param int|null $views
*/
public function setViews(?int $views): void
{
$this->views = $views;
}
/**
* @return int|null
*/
public function getBought(): ?int
{
return $this->bought;
}
/**
* @param int|null $bought
*/
public function setBought(?int $bought): void
{
$this->bought = $bought;
}
/**
* @return int|null
*/
public function getGroupId(): ?int
{
return $this->groupId;
}
/**
* @param int|null $groupId
*/
public function setGroupId(?int $groupId): void
{
$this->groupId = $groupId;
}
/**
* @return int|null
*/
public function getMaterialId(): ?int
{
return $this->materialId;
}
/**
* @param int|null $materialId
*/
public function setMaterialId(?int $materialId): void
{
$this->materialId = $materialId;
}
/**
* @return Collection<int, ImagePath>
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(ImagePath $image): self
{
if (!$this->images->contains($image)) {
$this->images->add($image);
$image->setProduct($this);
}
return $this;
}
public function removeImage(ImagePath $image): self
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getProduct() === $this) {
$image->setProduct(null);
}
}
return $this;
}
public function getGroupsProduct(): ?GroupProducts
{
return $this->groupsProduct;
}
public function setGroupsProduct(?GroupProducts $groupsProduct): self
{
$this->groupsProduct = $groupsProduct;
return $this;
}
public function getMaterialProduct(): ?MaterialProducts
{
return $this->materialProduct;
}
public function setMaterialProduct(?MaterialProducts $materialProduct): self
{
$this->materialProduct = $materialProduct;
return $this;
}
public function getPrice(): float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getTags(): string
{
return $this->tags;
}
public function setTags(string $tags): self
{
$this->tags = $tags;
return $this;
}
public function getPriceForSeller(): float
{
return $this->priceForSeller;
}
public function setPriceForSeller(float $priceForSeller): self
{
$this->priceForSeller = $priceForSeller;
return $this;
}
/**
* @return Collection<int, ProductsSizes>
*/
public function getProductsSizes(): Collection
{
return $this->productsSizes;
}
public function addProductsSize(ProductsSizes $productsSize): self
{
if (!$this->productsSizes->contains($productsSize)) {
$this->productsSizes->add($productsSize);
$productsSize->setProduct($this);
}
return $this;
}
public function removeProductsSize(ProductsSizes $productsSize): self
{
if ($this->productsSizes->removeElement($productsSize)) {
// set the owning side to null (unless already changed)
if ($productsSize->getProduct() === $this) {
$productsSize->setProduct(null);
}
}
return $this;
}
public function getSeller(): ?User
{
return $this->seller;
}
public function setSeller(?User $seller): self
{
$this->seller = $seller;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): static
{
$this->status = $status;
return $this;
}
public function isActual(): bool
{
return $this->status === self::STATUS_PRODUCTS_ACTUAL;
}
}