<?php
namespace App\Entity\Application;
use App\Entity\User;
use App\Entity\Web\TopCategory;
use App\Repository\Application\OfferRepository;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Behaviors\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
*
* @ORM\Table(name="app_offer")
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @ORM\Entity(repositoryClass=OfferRepository::class)
* @Vich\Uploadable()
*/
class Offer implements TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Store::class, inversedBy="offers")
* @ORM\JoinColumn(nullable=false)
*/
private $store;
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="offers")
* @ORM\JoinColumn(nullable=true)
*/
private $category;
/**
* @ORM\ManyToOne(targetEntity=TopCategory::class, inversedBy="offers")
* @ORM\JoinColumn(nullable=true)
*/
private $topCategory;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $fromOutletPrice;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $fromNormalPrice;
/**
* @ORM\Column(type="boolean")
*/
private $isPublic = false;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("dateFrom")
* @ORM\Column(type="datetime")
*/
private $dateFrom;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("dateTo")
* @ORM\Column(type="datetime")
*/
private $dateTo;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $publicDate;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=true)
*/
private $createUser;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $editUser;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("logo")
*/
private $shopLogo;
/**
* @Vich\UploadableField(mapping="offer", fileNameProperty="image")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Serializer\VirtualProperty()
* @Serializer\Groups({"api"})
* @Serializer\Inline()
*/
public function getVirtualTranslation()
{
return $this->translate();
}
/**
* @Serializer\VirtualProperty()
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("shop")
*/
public function getVirtualShopID()
{
return $this->getStore()->getId();
}
public function __construct() {
$this->setDateFrom(new \DateTime());
$this->setDateTo(new \DateTime());
$this->setPublicDate((new \DateTime())->setTime(0,0,0));
}
public function checkCollections($locales){
foreach ( $locales as $locale ) {
if($this->getTranslations()->get($locale) === null){
$this->translate($locale)->setName(' ');
}
}
$this->mergeNewTranslations();
}
public function getId(): ?int
{
return $this->id;
}
public function getStore(): ?Store
{
return $this->store;
}
public function setStore(?Store $store): self
{
$this->store = $store;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getTopCategory(): ?TopCategory
{
return $this->topCategory;
}
public function setTopCategory(?TopCategory $category): self
{
$this->topCategory = $category;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
/**
* Get DateFrom
*
* @return mixed
*/
public function getDateFrom()
{
return $this->dateFrom;
}
/**
* Set DateFrom
*
* @param mixed $dateFrom
*/
public function setDateFrom( $dateFrom )
{
$this->dateFrom = $dateFrom;
}
/**
* Get DateTo
*
* @return mixed
*/
public function getDateTo()
{
return $this->dateTo;
}
/**
* Set DateTo
*
* @param mixed $dateTo
*/
public function setDateTo( $dateTo )
{
$this->dateTo = $dateTo;
}
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 ShopLogo
*
* @return mixed
*/
public function getShopLogo()
{
return $this->shopLogo;
}
/**
* Set ShopLogo
*
* @param mixed $shopLogo
*/
public function setShopLogo( $shopLogo )
{
$this->shopLogo = $shopLogo;
}
/**
* Get ImageFile
*
* @return null|File
*/
public function getImageFile(): ?File
{
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 mixed
*/
public function getImage()
{
return $this->image;
}
/**
* @param mixed $image
*/
public function setImage($image): void
{
$this->image = $image;
}
/**
* @return mixed
*/
public function getIsPublic()
{
return $this->isPublic;
}
/**
* @param mixed $isPublic
*/
public function setIsPublic($isPublic): void
{
$this->isPublic = $isPublic;
}
/**
* @return mixed
*/
public function getPublicDate()
{
return $this->publicDate;
}
/**
* @param mixed $publicDate
*/
public function setPublicDate($publicDate): void
{
$this->publicDate = $publicDate;
}
/**
* @return mixed
*/
public function getFromOutletPrice()
{
return $this->fromOutletPrice;
}
/**
* @param mixed $fromOutletPrice
*/
public function setFromOutletPrice($fromOutletPrice): void
{
$this->fromOutletPrice = $fromOutletPrice;
}
/**
* @return mixed
*/
public function getFromNormalPrice()
{
return $this->fromNormalPrice;
}
/**
* @param mixed $fromNormalPrice
*/
public function setFromNormalPrice($fromNormalPrice): void
{
$this->fromNormalPrice = $fromNormalPrice;
}
}