<?php
namespace App\Entity;
use App\Fce\F_PP;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Behaviors\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @Vich\Uploadable()
*/
class Product implements TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Vich\UploadableField(mapping="product_image", fileNameProperty="image")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=199, nullable=true)
*/
private $image;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("code")
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $code;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $hash;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="boolean")
*/
private $onlyForAdults = false;
/**
* @Serializer\Groups({"api"})
* @Serializer\Inline()
* @ORM\ManyToOne(targetEntity="App\Entity\Brand", inversedBy="products")
* @ORM\JoinColumn(nullable=false)
*/
private $brand;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Dealer", inversedBy="products")
* @ORM\JoinColumn(nullable=false)
*/
private $dealer;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $createUser;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editts;
/**
* @ORM\Column(type="boolean")
*/
private $translated = false;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $editUser;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductImage", mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"orderBy" = "ASC"})
*/
private $productImages;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Variant", mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"orderBy" = "ASC"})
*/
private $variants;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Pricelist", mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true, indexBy="currency")
*/
private $pricelists;
/**
* @ORM\OneToMany(targetEntity="App\Entity\OrderItem", mappedBy="product")
*/
private $orderItems;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="products")
*/
private $category;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("image")
*/
private $productImage;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("url")
*/
private $url;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("category")
*/
private $appCategory;
/**
* @Serializer\VirtualProperty()
* @Serializer\Groups({"api"})
* @Serializer\Inline()
*/
public function getVirtualTranslation()
{
return $this->translate();
}
public function __construct()
{
$this->productImages = new ArrayCollection();
$this->variants = new ArrayCollection();
$this->pricelists = new ArrayCollection();
$this->orderItems = new ArrayCollection();
}
public function checkPricelists($currencies){
$diff = array_diff($currencies,array_keys($this->getPricelists()->toArray()));
if(count($diff)>0){
foreach ($diff as $curr){
$price = new Pricelist($curr);
$this->addPricelist($price);
}
}
}
public function getId(): ?int
{
return $this->id;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getBrand(): ?Brand
{
return $this->brand;
}
public function setBrand(?Brand $brand): self
{
$this->brand = $brand;
return $this;
}
public function getDealer(): ?Dealer
{
return $this->dealer;
}
public function setDealer(?Dealer $dealer): self
{
$this->dealer = $dealer;
return $this;
}
public function getCreatets(): ?\DateTimeInterface
{
return $this->createts;
}
public function setCreatets(\DateTimeInterface $createts): self
{
$this->createts = $createts;
return $this;
}
public function getCreateUser(): ?User
{
return $this->createUser;
}
public function setCreateUser(?User $createUser): self
{
$this->createUser = $createUser;
return $this;
}
public function getEditts(): ?\DateTimeInterface
{
return $this->editts;
}
public function setEditts(?\DateTimeInterface $editts): self
{
$this->editts = $editts;
return $this;
}
public function getEditUser(): ?User
{
return $this->editUser;
}
public function setEditUser(?User $editUser): self
{
$this->editUser = $editUser;
return $this;
}
public function __call($method, $arguments)
{
$ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
if(empty($ret)) {
$ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
}
return $ret;
}
/**
* Get ImageFile
*
* @return null|File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->editts = new \DateTime();
}
}
/**
* @return Collection|ProductImage[]
*/
public function getProductImages(): Collection
{
return $this->productImages;
}
public function addProductImage(ProductImage $productImage): self
{
if (!$this->productImages->contains($productImage)) {
$this->productImages[] = $productImage;
$productImage->setProduct($this);
}
return $this;
}
public function removeProductImage(ProductImage $productImage): self
{
if ($this->productImages->contains($productImage)) {
$this->productImages->removeElement($productImage);
// set the owning side to null (unless already changed)
if ($productImage->getProduct() === $this) {
$productImage->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|Variant[]
*/
public function getVariants(): Collection
{
return $this->variants;
}
public function addVariant(Variant $variant): self
{
if (!$this->variants->contains($variant)) {
$this->variants[] = $variant;
$variant->setProduct($this);
}
return $this;
}
public function removeVariant(Variant $variant): self
{
if ($this->variants->contains($variant)) {
$this->variants->removeElement($variant);
// set the owning side to null (unless already changed)
if ($variant->getProduct() === $this) {
$variant->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|Pricelist[]
*/
public function getPricelists(): Collection
{
return $this->pricelists;
}
public function addPricelist(Pricelist $pricelist): self
{
if (!$this->pricelists->contains($pricelist)) {
$this->pricelists[$pricelist->getCurrency()] = $pricelist;
$pricelist->setProduct($this);
}
return $this;
}
public function removePricelist(Pricelist $pricelist): self
{
if ($this->pricelists->contains($pricelist)) {
$this->pricelists->removeElement($pricelist);
// set the owning side to null (unless already changed)
if ($pricelist->getProduct() === $this) {
$pricelist->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|OrderItem[]
*/
public function getOrderItems(): Collection
{
return $this->orderItems;
}
public function addOrderItem(OrderItem $orderItem): self
{
if (!$this->orderItems->contains($orderItem)) {
$this->orderItems[] = $orderItem;
$orderItem->setProduct($this);
}
return $this;
}
public function removeOrderItem(OrderItem $orderItem): self
{
if ($this->orderItems->contains($orderItem)) {
$this->orderItems->removeElement($orderItem);
// set the owning side to null (unless already changed)
if ($orderItem->getProduct() === $this) {
$orderItem->setProduct(null);
}
}
return $this;
}
/**
* Get Category
*
* @return mixed
*/
public function getCategory()
{
return $this->category;
}
/**
* Set Category
*
* @param mixed $category
*/
public function setCategory( $category )
{
$this->category = $category;
}
/**
* Get Code
*
* @return mixed
*/
public function getCode()
{
return $this->code;
}
/**
* Set Code
*
* @param mixed $code
*/
public function setCode( $code )
{
$this->code = $code;
}
/**
* Get Hash
*
* @return mixed
*/
public function getHash()
{
return $this->hash;
}
/**
* Set Hash
*
* @param mixed $hash
*/
public function setHash( $hash )
{
$this->hash = $hash;
}
/**
* @Serializer\VirtualProperty()
* @Serializer\Groups({"api"})
* @Serializer\Inline()
*/
public function getPrice( $curr = null )
{
if($curr === null){$curr = \Locale::getDefault() === 'cs'?'CZK':'EUR';}
return $this->getPricelists()[$curr];
}
/**
* Get Translated
*
* @return mixed
*/
public function getTranslated()
{
return $this->translated;
}
/**
* Set Translated
*
* @param mixed $translated
*/
public function setTranslated( $translated )
{
$this->translated = $translated;
}
/**
* Get OnlyForAdults
*
* @return mixed
*/
public function getOnlyForAdults()
{
return $this->onlyForAdults;
}
/**
* Set OnlyForAdults
*
* @param mixed $onlyForAdults
*/
public function setOnlyForAdults( $onlyForAdults )
{
$this->onlyForAdults = $onlyForAdults;
}
/**
* Get ProductImage
*
* @return mixed
*/
public function getProductImage()
{
return $this->productImage;
}
/**
* Set ProductImage
*
* @param mixed $productImage
*/
public function setProductImage( $productImage )
{
$this->productImage = $productImage;
}
/**
* Get Url
*
* @return mixed
*/
public function getUrl()
{
return $this->url;
}
/**
* Set Url
*
* @param mixed $url
*/
public function setUrl( $url )
{
$this->url = $url;
}
/**
* Get AppCategory
*
* @return mixed
*/
public function getAppCategory()
{
return $this->appCategory;
}
/**
* Set AppCategory
*
* @param mixed $appCategory
*/
public function setAppCategory( $appCategory )
{
$this->appCategory = $appCategory;
}
}