<?php
namespace App\Entity\Application;
use App\Repository\Application\BonusRepository;
use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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\Table(name="app_bonus",
* uniqueConstraints={@ORM\UniqueConstraint(name="hash", columns={"hash"})}
* )
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @ORM\Entity(repositoryClass=BonusRepository::class)
* @Vich\Uploadable()
*/
class Bonus implements TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("price")
* @ORM\Column(type="integer")
*/
private $price;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("hash")
* @ORM\Column(type="string", nullable=true, length=100)
*/
private $hash;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("dateFrom")
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateFrom;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("dateTo")
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateTo;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("count")
* @ORM\Column(type="integer", nullable=true)
*/
private $count = 0;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("used")
* @ORM\Column(type="integer", nullable=true)
*/
private $used = 0;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @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;
/**
* @Vich\UploadableField(mapping="store_qr", fileNameProperty="qr")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $qrFile;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $qr;
/**
* @ORM\OneToMany(targetEntity=Points::class, mappedBy="bonus")
*/
private $pointsHistory;
/**
* @Vich\UploadableField(mapping="bonus_image", fileNameProperty="image")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $imageFile;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("image")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
public function __construct()
{
$this->pointsHistory = new ArrayCollection();
}
/**
* @Serializer\VirtualProperty()
* @Serializer\Groups({"api","pointsHistory"})
* @Serializer\Inline()
*/
public function getVirtualName()
{
return $this->translate();
}
public function checkCollections($locales): void
{
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 getPrice(): ?int
{
return $this->price;
}
public function setPrice(int $price): self
{
$this->price = $price;
return $this;
}
public function getDateFrom()
{
return $this->dateFrom;
}
public function setDateFrom( $dateFrom): self
{
$this->dateFrom = $dateFrom;
return $this;
}
public function getDateTo()
{
return $this->dateTo;
}
public function setDateTo( $dateTo): self
{
$this->dateTo = $dateTo;
return $this;
}
public function getCount(): ?int
{
return $this->count;
}
public function setCount(?int $count): self
{
$this->count = $count;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
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;
}
/**
* Get Qr
*
* @return mixed
*/
public function getQr()
{
return $this->qr;
}
/**
* Set Qr
*
* @param mixed $qr
*/
public function setQr( $qr )
{
$this->qr = $qr;
}
/**
* Get QrFile
*
* @return null|File
*/
public function getQrFile(): ?File
{
return $this->qrFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $qrFile
*/
public function setQrFile(?File $qrFile = null): void
{
$this->qrFile = $qrFile;
if (null !== $qrFile) {
$this->editts = new \DateTime();
}
}
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 Hash
*
* @return mixed
*/
public function getHash()
{
return $this->hash;
}
/**
* Set Hash
*
* @param mixed $hash
*/
public function setHash( $hash )
{
$this->hash = $hash;
}
/**
* @return Collection|Points[]
*/
public function getPointsHistory(): Collection
{
return $this->pointsHistory;
}
public function addPointsHistory(Points $pointsHistory): self
{
if (!$this->pointsHistory->contains($pointsHistory)) {
$this->pointsHistory[] = $pointsHistory;
$pointsHistory->setBonus($this);
}
return $this;
}
public function removePointsHistory(Points $pointsHistory): self
{
if ($this->pointsHistory->removeElement($pointsHistory)) {
// set the owning side to null (unless already changed)
if ($pointsHistory->getBonus() === $this) {
$pointsHistory->setBonus(null);
}
}
return $this;
}
/**
* Get Used
*
* @return mixed
*/
public function getUsed()
{
return $this->used;
}
/**
* Set Used
*
* @param mixed $used
*/
public function setUsed( $used )
{
$this->used = $used;
}
/**
* 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();
}
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
}