<?php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use App\Model\LangParamInterface;
use App\Model\LangParamRelationInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Query\Parameter;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="sub_product")
*/
class SubProduct implements TranslatableInterface, BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use TranslatableTrait;
use SoftDeletableTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Obsługa tłumaczeń
* @param $method
* @param $arguments
* @return mixed
*/
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
public function getName()
{
return $this->translate()->getName();
}
public function getPrice()
{
return $this->translate()->getPrice();
}
public function getRebate()
{
return $this->translate()->getRebate();
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", cascade={"all"}, inversedBy="subProducts")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
*/
protected $product;
/**
* @Doctrine\ORM\Mapping\Column(name="active", type="boolean", options={"default"=0}, nullable=true)
*/
protected $active;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CartProduct", mappedBy="subProduct")
* @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
*/
protected $carts;
/**
* @ORM\OneToMany(targetEntity="App\Entity\OrderProduct", mappedBy="subProduct")
* @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
*/
protected $orders;
/**
*
* note This is not a mapped field of entity metadata, just a simple property.
*
* @var File $imageFile
*/
protected $imageFile;
/**
* @ORM\Column(type="string", length=255, name="image_name", nullable=true)
* @var string $imageName
*/
protected $imageName;
/**
* @var \DateTime
*
* @ORM\Column(name="sold_time", type="datetime", nullable=true)
*/
private $soldTime;
/**
* @var \DateTime
*
* @ORM\Column(name="add_to_cart_time", type="datetime", nullable=true)
*/
private $addToCartTime;
public function __construct()
{
$this->carts = new ArrayCollection();
$this->orders = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function getSoldTime(): ?\DateTimeInterface
{
return $this->soldTime;
}
public function setSoldTime(?\DateTimeInterface $soldTime): self
{
$this->soldTime = $soldTime;
return $this;
}
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
try {
$fileName = md5(uniqid()).'.'.$image->guessExtension();
// Move the file to the directory where brochures are stored
$brochuresDir = getcwd().'/images/product/';
$image->move($brochuresDir, $fileName);
// Update the 'brochure' property to store the PDF file name
// instead of its contents
$this->setImageName($fileName);
$this->updatedAt = new \DateTime('now');
} catch (\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException $e) {
}
}
return $this;
}
/**
* @return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* @return Collection|CartProduct[]
*/
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart(CartProduct $cart): self
{
if (!$this->carts->contains($cart)) {
$this->carts[] = $cart;
$cart->setSubProduct($this);
}
return $this;
}
public function removeCart(CartProduct $cart): self
{
if ($this->carts->removeElement($cart)) {
// set the owning side to null (unless already changed)
if ($cart->getSubProduct() === $this) {
$cart->setSubProduct(null);
}
}
return $this;
}
/**
* @return Collection|OrderProduct[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(OrderProduct $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setSubProduct($this);
}
return $this;
}
public function removeOrder(OrderProduct $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getSubProduct() === $this) {
$order->setSubProduct(null);
}
}
return $this;
}
/**
* @return \DateTime
*/
public function getAddToCartTime()
{
return $this->addToCartTime;
}
/**
* @param \DateTime $addToCartTime
*/
public function setAddToCartTime(\DateTime $addToCartTime)
{
$this->addToCartTime = $addToCartTime;
}
}